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..c4df4940 100644 --- a/internal/konflux/git.go +++ b/internal/konflux/git.go @@ -68,11 +68,21 @@ func metadataTrailer() string { message := "" if workflow := os.Getenv("GITHUB_WORKFLOW"); workflow != "" { - message += fmt.Sprintf("\nGenerated by workflow [%s](%s/%s/actions/runs/%s)", + sha := os.Getenv("GITHUB_SHA") + shortSha := sha + if len(shortSha) > 8 { + shortSha = sha[:8] + } + 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_SERVER_URL"), + os.Getenv("GITHUB_REPOSITORY"), + sha, ) } @@ -82,7 +92,7 @@ func metadataTrailer() string { } if actor != "" { - message += fmt.Sprintf("\nTriggered by %s", actor) + message += fmt.Sprintf("\nTriggered by @%s", actor) } if message != "" { @@ -118,23 +128,37 @@ 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) - 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 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) + + 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 check existing PR's URL exists: %s, %s", err, out) + } + prUrl := strings.TrimSpace(string(out)) + + // 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 }