From 77570b4273ba93985ff6d4df9de598227fc19455 Mon Sep 17 00:00:00 2001 From: Andrew Thorp Date: Mon, 11 May 2026 13:54:13 -0400 Subject: [PATCH 1/4] include commit link and author tag in pull request --- .github/workflows/generate-konflux.yaml | 2 ++ internal/konflux/git.go | 31 +++++++++++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/.github/workflows/generate-konflux.yaml b/.github/workflows/generate-konflux.yaml index d7334f5c..7c23f23c 100644 --- a/.github/workflows/generate-konflux.yaml +++ b/.github/workflows/generate-konflux.yaml @@ -66,6 +66,8 @@ jobs: env: GH_TOKEN: ${{ secrets.OPENSHIFT_PIPELINES_ROBOT }} GITHUB_TOKEN: ${{ secrets.OPENSHIFT_PIPELINES_ROBOT }} + + # TODO: This should be removed since the previous step sends the pull requests now - name: Commit new changes if: github.event_name != 'pull_request' run: | diff --git a/internal/konflux/git.go b/internal/konflux/git.go index 61a63be8..7584aaab 100644 --- a/internal/konflux/git.go +++ b/internal/konflux/git.go @@ -68,11 +68,18 @@ func metadataTrailer() string { message := "" if workflow := os.Getenv("GITHUB_WORKFLOW"); workflow != "" { - message += fmt.Sprintf("\nGenerated by workflow [%s](%s/%s/actions/runs/%s)", + shortSha := os.Getenv("GITHUB_SHA") + if len(shortSha) > 8 { + shortSha = shortSha[:8] + } + message += fmt.Sprintf("\nGenerated by workflow [%s](%s/%s/actions/runs/%s) on branch %s ([%s](%s))", workflow, os.Getenv("GITHUB_SERVER_URL"), os.Getenv("GITHUB_REPOSITORY"), os.Getenv("GITHUB_RUN_ID"), + os.Getenv("GITHUB_REF_NAME"), + shortSha, + os.Getenv("GITHUB_SHA"), ) } @@ -82,7 +89,7 @@ func metadataTrailer() string { } if actor != "" { - message += fmt.Sprintf("\nTriggered by %s", actor) + message += fmt.Sprintf("\nTriggered by @%s", actor) } if message != "" { @@ -123,18 +130,32 @@ func commitAndPullRequest(ctx context.Context, repo Repository, dir string) erro return fmt.Errorf("failed to check if a pr exists: %s, %s", err, out) } prNumber := strings.TrimSpace(string(out)) + prBody := "This PR was automatically generated by the konflux command from openshift-pipelines/hack repository" + metadataTrailer() if prNumber == "" { log.Printf("No PR found for %s, Creating ", head) - if out, err := run(ctx, dir, "gh", "pr", "create", + out, err := run(ctx, dir, "gh", "pr", "create", "--base", base, "--head", head, "--label=hack", "--label=automated", "--title", fmt.Sprintf("[bot:%s] update konflux configuration", head), - "--body", "This PR was automatically generated by the konflux command from openshift-pipelines/hack repository"+metadataTrailer()); err != nil { + "--body", prBody) + if err != nil { return fmt.Errorf("failed to create the pr: %s, %s", err, out) } + // Printing directly allows + fmt.Printf("::notice::Created Pull Request for %s: %s\n", repo.Name, out) } else { - log.Printf("[%s] PR already exists", prNumber) + // We update the PR body since it links to a specific workflow + out, err := run(ctx, dir, "gh", "pr", "edit", "--body", prBody) + if err != nil { + return fmt.Errorf("failed to update the pr: %s, %s", err, out) + } + url, err := run(ctx, dir, "gh", "pr", "view", prNumber, "--json", "url", "--jq", "'.url'") + if err != nil { + return fmt.Errorf("failed to get the pr URL: %s, %s", err, out) + } + // Printing directly allows + fmt.Printf("::notice::Updated Pull Request for %s: %s\n", repo.Name, url) } return nil } From 45a219a00639a04c70bc1c59de02eae821fce2c6 Mon Sep 17 00:00:00 2001 From: Andrew Thorp Date: Mon, 11 May 2026 14:43:33 -0400 Subject: [PATCH 2/4] drop pr view and pr edit due to permissions issues --- internal/konflux/git.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/internal/konflux/git.go b/internal/konflux/git.go index 7584aaab..f15aa9b4 100644 --- a/internal/konflux/git.go +++ b/internal/konflux/git.go @@ -125,11 +125,11 @@ func commitAndPullRequest(ctx context.Context, repo Repository, dir string) erro cmd := fmt.Sprintf("gh pr list --base %s --head %s --json number --jq '.[0].number'", base, head) out, err := run(ctx, dir, "bash", "-c", cmd) - if err != nil { return fmt.Errorf("failed to check if a pr exists: %s, %s", err, out) } prNumber := strings.TrimSpace(string(out)) + prBody := "This PR was automatically generated by the konflux command from openshift-pipelines/hack repository" + metadataTrailer() if prNumber == "" { log.Printf("No PR found for %s, Creating ", head) @@ -145,17 +145,17 @@ func commitAndPullRequest(ctx context.Context, repo Repository, dir string) erro // Printing directly allows fmt.Printf("::notice::Created Pull Request for %s: %s\n", repo.Name, out) } else { - // We update the PR body since it links to a specific workflow - out, err := run(ctx, dir, "gh", "pr", "edit", "--body", prBody) - if err != nil { - return fmt.Errorf("failed to update the pr: %s, %s", err, out) - } - url, err := run(ctx, dir, "gh", "pr", "view", prNumber, "--json", "url", "--jq", "'.url'") + log.Printf("[%s] PR already exists", prNumber) + + cmd := fmt.Sprintf("gh pr list --base %s --head %s --json url --jq '.[0].url'", base, head) + out, err := run(ctx, dir, "bash", "-c", cmd) if err != nil { - return fmt.Errorf("failed to get the pr URL: %s, %s", err, out) + return fmt.Errorf("failed to check existing PR's URL exists: %s, %s", err, out) } + prUrl := strings.TrimSpace(string(out)) + // Printing directly allows - fmt.Printf("::notice::Updated Pull Request for %s: %s\n", repo.Name, url) + fmt.Printf("::notice::Updated Pull Request for %s: %s\n", repo.Name, prUrl) } return nil } From e2ff32b3d8503b744fa284ca9fdadefbd2b9d83b Mon Sep 17 00:00:00 2001 From: Andrew Thorp Date: Mon, 11 May 2026 14:54:45 -0400 Subject: [PATCH 3/4] fix commit sha link --- internal/konflux/git.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/internal/konflux/git.go b/internal/konflux/git.go index f15aa9b4..a682d942 100644 --- a/internal/konflux/git.go +++ b/internal/konflux/git.go @@ -68,18 +68,21 @@ func metadataTrailer() string { message := "" if workflow := os.Getenv("GITHUB_WORKFLOW"); workflow != "" { - shortSha := os.Getenv("GITHUB_SHA") + sha := os.Getenv("GITHUB_SHA") + shortSha := sha if len(shortSha) > 8 { - shortSha = shortSha[:8] + shortSha = sha[:8] } - message += fmt.Sprintf("\nGenerated by workflow [%s](%s/%s/actions/runs/%s) on branch %s ([%s](%s))", + message += fmt.Sprintf("\nGenerated by workflow [%s](%s/%s/actions/runs/%s) on branch %s ([%s](%s/%s/commit/%s))", workflow, os.Getenv("GITHUB_SERVER_URL"), os.Getenv("GITHUB_REPOSITORY"), os.Getenv("GITHUB_RUN_ID"), os.Getenv("GITHUB_REF_NAME"), shortSha, - os.Getenv("GITHUB_SHA"), + os.Getenv("GITHUB_SERVER_URL"), + os.Getenv("GITHUB_REPOSITORY"), + sha, ) } From c466647919c74caf43c71340af6a69a19cdb5f7d Mon Sep 17 00:00:00 2001 From: Andrew Thorp Date: Mon, 11 May 2026 15:14:00 -0400 Subject: [PATCH 4/4] fix incomplete comment --- internal/konflux/git.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/konflux/git.go b/internal/konflux/git.go index a682d942..c4df4940 100644 --- a/internal/konflux/git.go +++ b/internal/konflux/git.go @@ -145,7 +145,7 @@ func commitAndPullRequest(ctx context.Context, repo Repository, dir string) erro if err != nil { return fmt.Errorf("failed to create the pr: %s, %s", err, out) } - // Printing directly allows + // Printing directly since the log prefix blocks the notice from registering with the workflow fmt.Printf("::notice::Created Pull Request for %s: %s\n", repo.Name, out) } else { log.Printf("[%s] PR already exists", prNumber) @@ -157,7 +157,7 @@ func commitAndPullRequest(ctx context.Context, repo Repository, dir string) erro } prUrl := strings.TrimSpace(string(out)) - // Printing directly allows + // Printing directly since the log prefix blocks the notice from registering with the workflow fmt.Printf("::notice::Updated Pull Request for %s: %s\n", repo.Name, prUrl) } return nil