|
8 | 8 | "io"
|
9 | 9 | "net/http"
|
10 | 10 | "net/url"
|
| 11 | + "strings" |
11 | 12 | )
|
12 | 13 |
|
13 | 14 | var (
|
@@ -96,17 +97,28 @@ func (d *DeepCodeLLMBindingImpl) explainRequestBody(options *ExplainOptions) ([]
|
96 | 97 | } else {
|
97 | 98 | requestBody, marshalErr = json.Marshal(explainFixRequest{
|
98 | 99 | RuleId: options.RuleKey,
|
99 |
| - Diffs: encodeDiffs(options.Diffs), |
| 100 | + Diffs: prepareDiffs(options.Diffs), |
100 | 101 | ExplanationLength: SHORT,
|
101 | 102 | })
|
102 | 103 | logger.Debug().Msg("payload for FixExplanation")
|
103 | 104 | }
|
104 | 105 | return requestBody, marshalErr
|
105 | 106 | }
|
106 | 107 |
|
107 |
| -func encodeDiffs(diffs []string) []string { |
108 |
| - var encodedDiffs []string |
| 108 | +func prepareDiffs(diffs []string) []string { |
| 109 | + cleanedDiffs := make([]string, 0, len(diffs)) |
109 | 110 | for _, diff := range diffs {
|
| 111 | + diffLines := strings.Split(diff, "\n") |
| 112 | + cleanedLines := "" |
| 113 | + for i, line := range diffLines { |
| 114 | + if !strings.HasPrefix(line, "---") && !strings.HasPrefix(line, "+++") && i > 1 { |
| 115 | + cleanedLines += line + "\n" |
| 116 | + } |
| 117 | + } |
| 118 | + cleanedDiffs = append(cleanedDiffs, cleanedLines) |
| 119 | + } |
| 120 | + var encodedDiffs []string |
| 121 | + for _, diff := range cleanedDiffs { |
110 | 122 | encodedDiffs = append(encodedDiffs, base64.StdEncoding.EncodeToString([]byte(diff)))
|
111 | 123 | }
|
112 | 124 | return encodedDiffs
|
|
0 commit comments