Skip to content

Fix Default Branch Issue on GitOps Comment Event in Github #1918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

zakisk
Copy link
Contributor

@zakisk zakisk commented Feb 6, 2025

Issue: when a user uses GitOps comment on pushed commit in Github, Head and Base branch is set as main in hardcoded string and considered default branch here but default could differ by repos like it could be master or trunk as well.

Fix: use Event.Repository.DefaultBranch field for Head and Base branch value in this case.

Changes

Submitter Checklist

  • 📝 Ensure your commit message is clear and informative. Refer to the How to write a git commit message guide. Include the commit message in the PR body rather than linking to an external site (e.g., Jira ticket).

  • ♽ Run make test lint before submitting a PR to avoid unnecessary CI processing. Consider installing pre-commit and running pre-commit install in the repository root for an efficient workflow.

  • ✨ We use linters to maintain clean and consistent code. Run make lint before submitting a PR. Some linters offer a --fix mode, executable with make fix-linters (ensure markdownlint and golangci-lint are installed).

  • 📖 Document any user-facing features or changes in behavior.

  • 🧪 While 100% coverage isn't required, we encourage unit tests for code changes where possible.

  • 🎁 If feasible, add an end-to-end test. See README for details.

  • 🔎 Address any CI test flakiness before merging, or provide a valid reason to bypass it (e.g., token rate limitations).

  • If adding a provider feature, fill in the following details:

Git Provider Supported
GitHub App ✅️
GitHub Webhook ❌️
Gitea ❌️
GitLab ❌️
Bitbucket Cloud ❌️
Bitbucket Server ❌️

(update the documentation accordingly)

Issue: when a user uses GitOps comment on pushed commit in
Github, Head and Base branch is set as `main` in hardcoded string
and considered default branch here but default could differ by repos
like it could be `master` or `trunk` as well.

Fix: use Event.Repository.DefaultBranch field for Head and Base
branch value in this case.

Signed-off-by: Zaki Shaikh <[email protected]>
@chmouel
Copy link
Member

chmouel commented Feb 6, 2025

heu good catch, which commit implemented that?

@@ -48,7 +48,7 @@ var sampleRepo = &github.Repository{
Login: github.Ptr("owner"),
},
Name: github.Ptr("reponame"),
DefaultBranch: github.Ptr("defaultbranch"),
DefaultBranch: github.Ptr("main"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think there is no test for that right ? ie it doesn't check if the user has set something else than main on their repo and that we are actuallyusing it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes seems same to mee, that it wasn't used that's why this bug is ignored

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a test then please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chmouel there are already tests for commit comment and branch matches, but the issue was DefaultBranch value of repo wasn't used in test due to hardcoded "main".

@zakisk
Copy link
Contributor Author

zakisk commented Feb 6, 2025

heu good catch, which commit implemented that?

bd4ad2f

@chmouel
Copy link
Member

chmouel commented Feb 10, 2025

/lgtm

Copy link

@pipelines-as-code pipelines-as-code bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Pull Request Approved

Approval Status:

  • Required Approvals: 1
  • Current Approvals: 1

👥 Approved By:

Reviewer Permission Status
@chmouel admin

📝 Next Steps

  • All required checks must pass
  • Branch protection rules apply
  • Get a maintainer to use the /merge command to merge the PR

Thank you for your contributions! 🎉

@chmouel
Copy link
Member

chmouel commented Feb 11, 2025

/rebase

@chmouel
Copy link
Member

chmouel commented Feb 11, 2025

/merge

@pipelines-as-code pipelines-as-code bot merged commit 04127aa into openshift-pipelines:main Feb 11, 2025
3 of 5 checks passed
Copy link

✅ PR Successfully Merged

  • Merge method: rebase
  • Merged by: @chmouel
  • Total approvals: 1/1

Approvals Summary:

Reviewer Permission Status
@chmouel admin

@zakisk zakisk deleted the fix-default-branch-issue-on-commit-comment branch March 11, 2025 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants