-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcode_scanning_list_analyses.go
More file actions
81 lines (69 loc) · 2.21 KB
/
code_scanning_list_analyses.go
File metadata and controls
81 lines (69 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package cmd
import (
"encoding/json"
"fmt"
"text/tabwriter"
gh "github.com/advanced-security/codeql-development-mcp-server/client/internal/github"
"github.com/spf13/cobra"
)
var listAnalysesCmd = &cobra.Command{
Use: "list-analyses",
Short: "List Code Scanning analyses for a repository",
RunE: runListAnalyses,
}
var listAnalysesFlags struct {
repo string
ref string
toolName string
sarifID string
sort string
direction string
perPage int
}
func init() {
codeScanningCmd.AddCommand(listAnalysesCmd)
f := listAnalysesCmd.Flags()
f.StringVar(&listAnalysesFlags.repo, "repo", "", "Repository in owner/repo format (required)")
f.StringVar(&listAnalysesFlags.ref, "ref", "", "Git ref to filter by")
f.StringVar(&listAnalysesFlags.toolName, "tool-name", "", "Tool name to filter by (e.g. CodeQL)")
f.StringVar(&listAnalysesFlags.sarifID, "sarif-id", "", "SARIF ID to filter by")
f.StringVar(&listAnalysesFlags.sort, "sort", "", "Sort by (created)")
f.StringVar(&listAnalysesFlags.direction, "direction", "", "Sort direction (asc, desc)")
f.IntVar(&listAnalysesFlags.perPage, "per-page", 30, "Results per page (max 100)")
_ = listAnalysesCmd.MarkFlagRequired("repo")
}
func runListAnalyses(cmd *cobra.Command, _ []string) error {
owner, repo, err := parseRepo(listAnalysesFlags.repo)
if err != nil {
return err
}
client, err := gh.NewClient()
if err != nil {
return err
}
analyses, err := client.ListAnalyses(gh.ListAnalysesOptions{
Owner: owner,
Repo: repo,
Ref: listAnalysesFlags.ref,
ToolName: listAnalysesFlags.toolName,
SarifID: listAnalysesFlags.sarifID,
Sort: listAnalysesFlags.sort,
Direction: listAnalysesFlags.direction,
PerPage: listAnalysesFlags.perPage,
})
if err != nil {
return err
}
if OutputFormat() == "json" {
enc := json.NewEncoder(cmd.OutOrStdout())
enc.SetIndent("", " ")
return enc.Encode(analyses)
}
w := tabwriter.NewWriter(cmd.OutOrStdout(), 0, 4, 2, ' ', 0)
fmt.Fprintln(w, "ID\tTOOL\tREF\tCATEGORY\tRESULTS\tRULES\tCREATED")
for _, a := range analyses {
fmt.Fprintf(w, "%d\t%s\t%s\t%s\t%d\t%d\t%s\n",
a.ID, a.Tool.Name, a.Ref, a.Category, a.ResultsCount, a.RulesCount, a.CreatedAt)
}
return w.Flush()
}