@@ -29,6 +29,8 @@ type visibilityStruct struct {
29
29
Telemetry bool `json:"telemetry"` // True if the message should be sent to telemetry (defaults to false)
30
30
}
31
31
32
+ var fullVisibility * visibilityStruct = & visibilityStruct {true , true , true }
33
+
32
34
type locationStruct struct {
33
35
File string `json:"file,omitempty"`
34
36
StartLine int `json:"startLine,omitempty"`
@@ -37,20 +39,22 @@ type locationStruct struct {
37
39
EndColumn int `json:"endColumn,omitempty"`
38
40
}
39
41
42
+ var noLocation * locationStruct = nil
43
+
40
44
type diagnostic struct {
41
- Timestamp string `json:"timestamp"`
42
- Source sourceStruct `json:"source"`
43
- MarkdownMessage string `json:"markdownMessage"`
44
- Severity string `json:"severity"`
45
- Internal bool `json:"internal"`
46
- Visibility visibilityStruct `json:"visibility"`
47
- Location * locationStruct `json:"location,omitempty"` // Use a pointer so that it is omitted if nil
45
+ Timestamp string `json:"timestamp"`
46
+ Source sourceStruct `json:"source"`
47
+ MarkdownMessage string `json:"markdownMessage"`
48
+ Severity string `json:"severity"`
49
+ Internal bool `json:"internal"`
50
+ Visibility * visibilityStruct `json:"visibility,omitempty"` // Use a pointer so that it is omitted if nil
51
+ Location * locationStruct `json:"location,omitempty"` // Use a pointer so that it is omitted if nil
48
52
}
49
53
50
54
var diagnosticsEmitted , diagnosticsLimit uint = 0 , 100
51
55
var noDiagnosticDirPrinted bool = false
52
56
53
- func emitDiagnostic (sourceid , sourcename , markdownMessage string , severity diagnosticSeverity , internal , visibilitySP , visibilityCST , visibilityT bool , file string , startLine , startColumn , endLine , endColumn int ) {
57
+ func emitDiagnostic (sourceid , sourcename , markdownMessage string , severity diagnosticSeverity , internal bool , visibility * visibilityStruct , location * locationStruct ) {
54
58
if diagnosticsEmitted < diagnosticsLimit {
55
59
diagnosticsEmitted += 1
56
60
@@ -63,43 +67,39 @@ func emitDiagnostic(sourceid, sourcename, markdownMessage string, severity diagn
63
67
return
64
68
}
65
69
66
- var optLoc * locationStruct
67
- if file == "" && startLine == 0 && startColumn == 0 && endLine == 0 && endColumn == 0 {
68
- optLoc = nil
69
- } else {
70
- optLoc = & locationStruct {file , startLine , startColumn , endLine , endColumn }
71
- }
72
-
73
70
timestamp := time .Now ().UTC ().Format ("2006-01-02T15:04:05.000" ) + "Z"
74
71
75
- d := diagnostic {
76
- timestamp ,
77
- sourceStruct {sourceid , sourcename , "go" },
78
- markdownMessage ,
79
- string (severity ),
80
- internal ,
81
- visibilityStruct {visibilitySP , visibilityCST , visibilityT },
82
- optLoc ,
83
- }
72
+ var d diagnostic
84
73
85
- if diagnosticsEmitted == diagnosticsLimit {
74
+ if diagnosticsEmitted < diagnosticsLimit {
86
75
d = diagnostic {
87
76
timestamp ,
88
- sourceStruct {"go/autobuilder/diagnostic-limit-hit" , "Some diagnostics were dropped" , "go" },
89
- fmt .Sprintf ("The number of diagnostics exceeded the limit (%d); the remainder were dropped." , diagnosticsLimit ),
77
+ sourceStruct {sourceid , sourcename , "go" },
78
+ markdownMessage ,
79
+ string (severity ),
80
+ internal ,
81
+ visibility ,
82
+ location ,
83
+ }
84
+ } else {
85
+ d = diagnostic {
86
+ timestamp ,
87
+ sourceStruct {"go/autobuilder/diagnostic-limit-reached" , "Diagnostics limit exceeded" , "go" },
88
+ fmt .Sprintf ("CodeQL has produced more than the maximum number of diagnostics. Only the first %d have been reported." , diagnosticsLimit ),
90
89
string (severityWarning ),
91
90
false ,
92
- visibilityStruct { true , true , true } ,
93
- nil ,
91
+ visibility ,
92
+ location ,
94
93
}
95
94
}
96
95
97
96
content , err := json .Marshal (d )
98
97
if err != nil {
99
98
log .Println (err )
99
+ return
100
100
}
101
101
102
- targetFile , err := os .CreateTemp (diagnosticDir , "go-extractor.*.jsonl " )
102
+ targetFile , err := os .CreateTemp (diagnosticDir , "go-extractor.*.json " )
103
103
if err != nil {
104
104
log .Println ("Failed to create temporary file for diagnostic: " )
105
105
log .Println (err )
@@ -124,8 +124,8 @@ func EmitPackageDifferentOSArchitecture(pkgPath string) {
124
124
"Package " + pkgPath + " is intended for a different OS or architecture" ,
125
125
"Make sure the `GOOS` and `GOARCH` [environment variables are correctly set](https://docs.github.com/en/actions/learn-github-actions/variables#defining-environment-variables-for-a-single-workflow). Alternatively, [change your OS and architecture](https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#using-a-github-hosted-runner)." ,
126
126
severityWarning , false ,
127
- true , true , true ,
128
- "" , 0 , 0 , 0 , 0 ,
127
+ fullVisibility ,
128
+ noLocation ,
129
129
)
130
130
}
131
131
@@ -156,8 +156,8 @@ func EmitCannotFindPackages(pkgPaths []string) {
156
156
fmt .Sprintf ("%d package%s could not be found" , numPkgPaths , ending ),
157
157
"The following packages could not be found. Check that the paths are correct and make sure any private packages can be accessed. If any of the packages are present in the repository then you may need a [custom build command](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-the-codeql-workflow-for-compiled-languages).\n \n " + secondLine ,
158
158
severityError , false ,
159
- true , true , true ,
160
- "" , 0 , 0 , 0 , 0 ,
159
+ fullVisibility ,
160
+ noLocation ,
161
161
)
162
162
}
163
163
@@ -167,8 +167,8 @@ func EmitNewerGoVersionNeeded() {
167
167
"Newer Go version needed" ,
168
168
"The detected version of Go is lower than the version specified in `go.mod`. [Install a newer version](https://github.com/actions/setup-go#basic)." ,
169
169
severityError , false ,
170
- true , true , true ,
171
- "" , 0 , 0 , 0 , 0 ,
170
+ fullVisibility ,
171
+ noLocation ,
172
172
)
173
173
}
174
174
@@ -178,7 +178,7 @@ func EmitGoFilesFoundButNotProcessed() {
178
178
"Go files were found but not processed" ,
179
179
"[Specify a custom build command](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-the-codeql-workflow-for-compiled-languages) that includes one or more `go build` commands to build the `.go` files to be analyzed." ,
180
180
severityError , false ,
181
- true , true , true ,
182
- "" , 0 , 0 , 0 , 0 ,
181
+ fullVisibility ,
182
+ noLocation ,
183
183
)
184
184
}
0 commit comments