Skip to content

Commit 07098bf

Browse files
committed
Minor refactor in diagnostics.go
1 parent 2edccec commit 07098bf

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

go/extractor/diagnostics/diagnostics.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@ func emitDiagnostic(sourceid, sourcename, markdownMessage string, severity diagn
6969
} else {
7070
optLoc = &locationStruct{file, startLine, startColumn, endLine, endColumn}
7171
}
72+
73+
timestamp := time.Now().UTC().Format("2006-01-02T15:04:05.000") + "Z"
74+
7275
d := diagnostic{
73-
time.Now().UTC().Format("2006-01-02T15:04:05.000") + "Z",
76+
timestamp,
7477
sourceStruct{sourceid, sourcename, "go"},
7578
markdownMessage,
7679
string(severity),
@@ -81,7 +84,7 @@ func emitDiagnostic(sourceid, sourcename, markdownMessage string, severity diagn
8184

8285
if diagnosticsEmitted == diagnosticsLimit {
8386
d = diagnostic{
84-
time.Now().UTC().Format("2006-01-02T15:04:05.000") + "Z",
87+
timestamp,
8588
sourceStruct{"go/autobuilder/diagnostic-limit-hit", "Some diagnostics were dropped", "go"},
8689
fmt.Sprintf("The number of diagnostics exceeded the limit (%d); the remainder were dropped.", diagnosticsLimit),
8790
string(severityWarning),
@@ -116,7 +119,8 @@ func emitDiagnostic(sourceid, sourcename, markdownMessage string, severity diagn
116119
}
117120

118121
func EmitPackageDifferentOSArchitecture(pkgPath string) {
119-
emitDiagnostic("go/autobuilder/package-different-os-architecture",
122+
emitDiagnostic(
123+
"go/autobuilder/package-different-os-architecture",
120124
"Package "+pkgPath+" is intended for a different OS or architecture",
121125
"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).",
122126
severityWarning, false,
@@ -158,7 +162,8 @@ func EmitCannotFindPackages(pkgPaths []string) {
158162
}
159163

160164
func EmitNewerGoVersionNeeded() {
161-
emitDiagnostic("go/autobuilder/newer-go-version-needed",
165+
emitDiagnostic(
166+
"go/autobuilder/newer-go-version-needed",
162167
"Newer Go version needed",
163168
"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).",
164169
severityError, false,
@@ -168,7 +173,8 @@ func EmitNewerGoVersionNeeded() {
168173
}
169174

170175
func EmitGoFilesFoundButNotProcessed() {
171-
emitDiagnostic("go/autobuilder/go-files-found-but-not-processed",
176+
emitDiagnostic(
177+
"go/autobuilder/go-files-found-but-not-processed",
172178
"Go files were found but not processed",
173179
"[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.",
174180
severityError, false,

0 commit comments

Comments
 (0)