Repository: googleapis/api-linter
Pull request #1003 (2022-08-20 00:10:16)

fix: Render URIs in github actions links
Include linter rule URI in findings for GitHub Action format.

noahdietz: Need to rebase/update this branch since I just merged the other one with the Location span handling logic.
GregFurmanek: Any chance your initial description would highlight what is this CL supposed to do/fix/accomplish? It helps to understand intent behind the change.
achew22: @noahdietz rebased
noahdietz: > Any chance your initial description would highlight what is this CL supposed to do/fix/accomplish? It helps to understand intent behind the change.

Good idea, I added a description :)

Patch:
diff --git a/cmd/api-linter/github_actions.go b/cmd/api-linter/github_actions.go
index da667f9..c9f1e6a 100644
--- a/cmd/api-linter/github_actions.go
+++ b/cmd/api-linter/github_actions.go
@@ -57,6 +57,10 @@ func formatGitHubActionOutput(responses []lint.Response) []byte {
 			runeThatLooksLikeTwoColonsButIsActuallyTwoArmenianFullStops := "։։"
 			title := strings.ReplaceAll(string(problem.RuleID), "::", runeThatLooksLikeTwoColonsButIsActuallyTwoArmenianFullStops)
 			message := strings.ReplaceAll(problem.Message, "\n", "\\n")
+			uri := problem.GetRuleURI()
+			if uri != "" {
+				message += "\\n\\n" + uri
+			}
 			fmt.Fprintf(&buf, " title=%s::%s\n", title, message)
 		}
 	}
diff --git a/lint/problem.go b/lint/problem.go
index 2ad4234..9491bc8 100644
--- a/lint/problem.go
+++ b/lint/problem.go
@@ -95,11 +95,16 @@ func (p Problem) marshal() interface{} {
 		p.Suggestion,
 		fileLocationFromPBLocation(loc),
 		p.RuleID,
-		getRuleURL(string(p.RuleID), ruleURLMappings),
+		p.GetRuleURI(),
 		p.category,
 	}
 }
 
+// GetRuleURI returns a URI to learn more about the problem.
+func (p Problem) GetRuleURI() string {
+	return getRuleURL(string(p.RuleID), ruleURLMappings)
+}
+
 // position describes a one-based position in a source code file.
 // They are one-indexed, as a human counts lines or columns.
 type position struct {


Test patch:
diff --git a/cmd/api-linter/github_actions_test.go b/cmd/api-linter/github_actions_test.go
index 3134ab6..3039ef6 100644
--- a/cmd/api-linter/github_actions_test.go
+++ b/cmd/api-linter/github_actions_test.go
@@ -98,8 +98,8 @@ func TestFormatGitHubActionOutput(t *testing.T) {
 					},
 				},
 			},
-			want: `::error file=example.proto endColumn=4 endLine=3 col=2 line=1 title=core։։naming_formats։։field_names::
-::error file=example.proto endColumn=8 endLine=7 col=6 line=5 title=core։։naming_formats։։field_names::multi\nline\ncomment
+			want: `::error file=example.proto endColumn=4 endLine=3 col=2 line=1 title=core։։naming_formats։։field_names::\n\nhttps://linter.aip.dev/naming_formats/field_names
+::error file=example.proto endColumn=8 endLine=7 col=6 line=5 title=core։։naming_formats։։field_names::multi\nline\ncomment\n\nhttps://linter.aip.dev/naming_formats/field_names
 `,
 		},
 		{
@@ -133,13 +133,13 @@ func TestFormatGitHubActionOutput(t *testing.T) {
 					},
 				},
 			},
-			want: `::error file=example.proto title=core։։naming_formats։։field_names::
-::error file=example.proto title=core։։naming_formats։։field_names::
-::error file=example2.proto title=core։։0131։։request_message։։name::
-::error file=example2.proto title=core։։0132։։response_message։։name::
-::error file=example3.proto title=core։։naming_formats։։field_names::
-::error file=example4.proto title=core։։naming_formats։։field_names::
-::error file=example4.proto title=core։։0132։։response_message։։name::
+			want: `::error file=example.proto title=core։։naming_formats։։field_names::\n\nhttps://linter.aip.dev/naming_formats/field_names
+::error file=example.proto title=core։։naming_formats։։field_names::\n\nhttps://linter.aip.dev/naming_formats/field_names
+::error file=example2.proto title=core։։0131։։request_message։։name::\n\nhttps://linter.aip.dev/131/request_message/name
+::error file=example2.proto title=core։։0132։։response_message։։name::\n\nhttps://linter.aip.dev/132/response_message/name
+::error file=example3.proto title=core։։naming_formats։։field_names::\n\nhttps://linter.aip.dev/naming_formats/field_names
+::error file=example4.proto title=core։։naming_formats։։field_names::\n\nhttps://linter.aip.dev/naming_formats/field_names
+::error file=example4.proto title=core։։0132։։response_message։։name::\n\nhttps://linter.aip.dev/132/response_message/name
 `,
 		},
 	}