@@ -6,16 +6,13 @@ import (
66 "codacy/cli-v2/plugins"
77 "encoding/json"
88 "fmt"
9- "net/http"
109 "os"
1110 "os/exec"
1211 "path/filepath"
1312 "strconv"
1413 "strings"
15- "time"
1614)
1715
18- const CodacyApiBase = "https://app.codacy.com"
1916const codacyToolName = "dartanalyzer"
2017const patternPrefix = "dartanalyzer_"
2118
@@ -138,114 +135,3 @@ func RunDartAnalyzer(workDirectory string, toolInfo *plugins.ToolInfo, files []s
138135 }
139136
140137}
141-
142- func convertDartAnalyzerOutputToSarif (output string ) (string , error ) {
143- // Create base SARIF structure
144- sarif := map [string ]interface {}{
145- "$schema" : "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json" ,
146- "runs" : []map [string ]interface {}{
147- {
148- "results" : []map [string ]interface {}{},
149- },
150- },
151- }
152-
153- // Split output into lines
154- lines := strings .Split (output , "\n " )
155-
156- // Process each line
157- for _ , line := range lines {
158- if line == "" {
159- continue
160- }
161-
162- // Split line into fields
163- fields := strings .Split (line , "|" )
164- if len (fields ) < 8 {
165- continue
166- }
167-
168- // Extract fields
169- file := fields [3 ]
170- lineNum , _ := strconv .Atoi (fields [4 ])
171- message := fields [7 ]
172-
173- // Create result object
174- result := map [string ]interface {}{
175- "message" : map [string ]string {
176- "text" : message ,
177- },
178- "locations" : []map [string ]interface {}{
179- {
180- "physicalLocation" : map [string ]interface {}{
181- "artifactLocation" : map [string ]interface {}{
182- "uri" : file ,
183- },
184- "region" : map [string ]interface {}{
185- "startLine" : lineNum ,
186- },
187- },
188- },
189- },
190- }
191-
192- // Add result to SARIF output
193- sarif ["runs" ].([]map [string ]interface {})[0 ]["results" ] = append (
194- sarif ["runs" ].([]map [string ]interface {})[0 ]["results" ].([]map [string ]interface {}),
195- result ,
196- )
197- }
198-
199- // Convert to JSON
200- sarifJson , err := json .MarshalIndent (sarif , "" , " " )
201- if err != nil {
202- return "" , fmt .Errorf ("error marshaling SARIF: %v" , err )
203- }
204-
205- return string (sarifJson ), nil
206- }
207-
208- func getToolFromCodacy (apiToken string , provider string , owner string , repository string ) (* Tool , error ) {
209- url := fmt .Sprintf ("%s/api/v3/analysis/organizations/%s/%s/repositories/%s/tools" ,
210- CodacyApiBase ,
211- provider ,
212- owner ,
213- repository )
214-
215- client := & http.Client {
216- Timeout : 10 * time .Second ,
217- }
218-
219- req , err := http .NewRequest ("GET" , url , nil )
220- if err != nil {
221- return nil , fmt .Errorf ("error creating request: %v" , err )
222- }
223-
224- req .Header .Set ("Accept" , "application/json" )
225- req .Header .Set ("api-token" , apiToken )
226-
227- resp , err := client .Do (req )
228- if err != nil {
229- return nil , fmt .Errorf ("error making request: %v" , err )
230- }
231- defer resp .Body .Close ()
232-
233- if resp .StatusCode >= 400 {
234- return nil , fmt .Errorf ("failed to get tools from Codacy API: %v" , resp .Status )
235- }
236-
237- var response struct {
238- Data []Tool `json:"data"`
239- }
240-
241- if err := json .NewDecoder (resp .Body ).Decode (& response ); err != nil {
242- return nil , fmt .Errorf ("error decoding response: %v" , err )
243- }
244-
245- for _ , tool := range response .Data {
246- if tool .Name == codacyToolName {
247- return & tool , nil
248- }
249- }
250- return nil , fmt .Errorf ("tool %s not found" , codacyToolName )
251- }
0 commit comments