Skip to content

Fix GitLab MR Not Updated Issue on Forked Repository #1892

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

Merged
merged 1 commit into from
Jan 22, 2025

Conversation

zakisk
Copy link
Contributor

@zakisk zakisk commented Jan 22, 2025

In this issue MR status was being created by PAC controller but wasn't updated in reconciler (watcher) and 404 Not Found was noticed in logs:

{"level":"error","ts":"2025-01-22T09:49:03.343Z","logger":"pac-watcher","caller":"events/emit.go:46","msg":"cannot set status with the GitLab token because of: 404 Not Found",...}

this was happening due to wrong Event.SourceProjectID. In implementation of SetClinet func of GitLab provider, if provider.SourceProjectID is empty (0) then it project is fetched from GitLab API (I think this is intended for incoming webhook and workable when sourceProject and targetProject are same raising MR in same repo), but when MR is from a "Forked" respository they are different. and as ParsePayload is only called in controller (really intended for that), when SetClient is called in pac-watcher code provider.SourceProjectID is empty here. But before SetClient is called in reconciler, detectProvider is called there, and detectProvider in its definition calls buildEventFromPipelineRun which sets Event.SourceProjectID and Event.TargetProjectID.

Solution

I am assigning event.SourceProjectID from runevent.TargetProjectID. and it works

Demo

Screencast.from.2025-01-22.18-12-28.mp4

https://issues.redhat.com/browse/SRVKP-6100

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)

Comment on lines 141 to 144
// in a scenario where source repo is a forked and created an MR on upstream
// runevent.SourceProjectID wouldn't be 0 when SetClient is called from pac-watcher code
// because in controller SourceProjectID is set in annotation of PR and runevent.SourceProjectID
// is set before SetClient is called so its worth taking ID from runevent.SourceProjectID.
Copy link
Member

Choose a reason for hiding this comment

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

In a scenario where the source repository is forked and a merge request (MR) is created on the upstream repository, runevent.SourceProjectID will not be 0 when SetClient is called from the pac-watcher code. This is because, in the controller, SourceProjectID is set in the annotation of the pull request, and runevent.SourceProjectID is set before SetClient is called. Therefore, we need to take the ID from runevent.SourceProjectID.

Copy link
Member

Choose a reason for hiding this comment

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

rephrased with proper english ^

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good!

fixed GitLan issue where MR status was created initially but wasn't
being updated on finish and was throwing error `404 not found` due to
wrong SourceProjectID assignment in SetClient.

https://issues.redhat.com/browse/SRVKP-6100

Signed-off-by: Zaki Shaikh <[email protected]>
@chmouel chmouel merged commit 1aecd8a into openshift-pipelines:main Jan 22, 2025
5 checks passed
@zakisk zakisk deleted the SRVKP-6100 branch January 22, 2025 16:19
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