Skip to content

Commit 9ae81ab

Browse files
jelly-afkmx-psi
andauthored
add commit and pr in autogenerated issue body (#1226)
Co-authored-by: Pablo Baeyens <[email protected]>
1 parent 9f4715e commit 9ae81ab

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: enhancement
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. crosslink)
5+
component: issuegenerator
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: Include commit and pr in issues generated by issuegenerator
9+
10+
# One or more tracking issues related to the change
11+
issues: [1180]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext:

issuegenerator/main.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ const (
3636
githubOwnerAndRepository = "GITHUB_REPOSITORY"
3737
githubWorkflow = "GITHUB_ACTION"
3838
githubAPITokenKey = "GITHUB_TOKEN" // #nosec G101
39+
githubSHAKey = "GITHUB_SHA"
40+
githubRefKey = "GITHUB_REF"
3941

4042
githubOwner = "githubOwner"
4143
githubRepository = "githubRepository"
@@ -51,6 +53,8 @@ const (
5153
Auto-generated report for ${jobName} job build.
5254
5355
Link to failed build: ${linkToBuild}
56+
Commit: ${commit}
57+
PR: ${pr}
5458
5559
### Component(s)
5660
${component}
@@ -62,6 +66,8 @@ this issue is open, will be added as comments with more information to this issu
6266
`
6367
issueCommentTemplate = `
6468
Link to latest failed build: ${linkToBuild}
69+
Commit: ${commit}
70+
PR: ${pr}
6571
6672
${failedTests}
6773
`
@@ -239,6 +245,8 @@ func (rg *reportGenerator) getRequiredEnv() {
239245
env[githubServerURL] = os.Getenv(githubServerURL)
240246
env[githubRunID] = os.Getenv(githubRunID)
241247
env[githubAPITokenKey] = os.Getenv(githubAPITokenKey)
248+
env[githubSHAKey] = os.Getenv(githubSHAKey)
249+
env[githubRefKey] = os.Getenv(githubRefKey)
242250

243251
for k, v := range env {
244252
if v == "" {
@@ -264,6 +272,16 @@ func (rg *reportGenerator) templateHelper(param string) string {
264272
case "component":
265273
trimmedModule := trimModule(rg.envVariables[githubOwner], rg.envVariables[githubRepository], currentReport.module)
266274
return getComponent(trimmedModule)
275+
case "commit":
276+
return rg.envVariables[githubSHAKey]
277+
case "pr":
278+
ref := rg.envVariables[githubRefKey]
279+
parts := strings.Split(ref, "/")
280+
if len(parts) == 4 && parts[1] == "pull" {
281+
return "#" + parts[2]
282+
}
283+
rg.logger.Warn("Could not parse PR from GITHUB_REF", zap.String("GITHUB_REF", ref))
284+
return "N/A"
267285
default:
268286
return ""
269287
}

issuegenerator/main_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ func TestTemplateExpansion(t *testing.T) {
224224
githubOwner: "test-org",
225225
githubRepository: "test-repo",
226226
githubRunID: "555555",
227+
githubSHAKey: "abcde12345",
228+
githubRefKey: "refs/pull/1234/merge",
227229
}
228230

229231
// Sort the reports by module name to ensure deterministic order
@@ -245,6 +247,8 @@ func TestTemplateExpansion(t *testing.T) {
245247
Auto-generated report for ` + "`test-ci`" + ` job build.
246248
247249
Link to failed build: https://github.com/test-org/test-repo/actions/runs/555555
250+
Commit: abcde12345
251+
PR: #1234
248252
249253
### Component(s)
250254
` + "package1" + `
@@ -267,6 +271,8 @@ this issue is open, will be added as comments with more information to this issu
267271
template: issueCommentTemplate,
268272
expected: `
269273
Link to latest failed build: https://github.com/test-org/test-repo/actions/runs/555555
274+
Commit: abcde12345
275+
PR: #1234
270276
271277
#### Test Failures
272278
- ` + "`TestFailure`" + `

0 commit comments

Comments
 (0)