-
Notifications
You must be signed in to change notification settings - Fork 113
fix(gitlab): use TargetProjectID for merge request comments #2194
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
base: main
Are you sure you want to change the base?
Conversation
Thanks @infernus01! Do you mind adding an end to end test for this? |
@infernus01 can you please confirm that it works with exact same setup where you were debugging this? |
🚀 Mirrored PR Created for E2E Testing |
/ok-to-test |
this is a critical fix, thanks, we really need a E2E test (but that may be complicated due of some initial setup to do)a or a demo demonstrating before/after on how it fixes.. |
Signed-off-by: Shubham Bhardwaj <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
Thanks @infernus01! Two nitpick suggestions but functionally this looks good
Signed-off-by: Shubham Bhardwaj <[email protected]>
/ok-to-test |
/ok-to-test @infernus01 i have sent you an invite to join openshift-pipelines org and you should be able to trigger e2e test |
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request correctly fixes an issue where GitLab API calls for merge request comments were using SourceProjectID
instead of TargetProjectID
, which is crucial for forked repositories. The change is simple and effective. The accompanying unit tests are updated accordingly, and a new end-to-end test has been added to validate the fix in a forked repository scenario.
My review includes one suggestion to improve the robustness of the new E2E test by replacing a fixed time.Sleep
with a polling mechanism to check for the fork's readiness, which will help prevent flaky test runs.
// Wait sometime for fork to be fully ready | ||
time.Sleep(3 * time.Second) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a fixed time.Sleep
to wait for the fork to be ready can lead to flaky tests. The GitLab API provides a way to check the status of a fork operation. It's better to poll the project's import_status
until it becomes finished
. This will make the test more robust.
// Wait for fork to be ready by polling its import status
const maxForkRetries = 24
const forkRetryInterval = 5 * time.Second
var p *clientGitlab.Project
for i := 0; i < maxForkRetries; i++ {
p, _, err = glprovider.Client().Projects.GetProject(forkProject.ID, nil)
assert.NilError(t, err)
if p.ImportStatus == "finished" {
runcnx.Clients.Log.Info("Fork project is ready.")
break
}
if i == maxForkRetries-1 {
t.Fatalf("Fork of project did not finish in time, status: %s", p.ImportStatus)
}
runcnx.Clients.Log.Infof("Waiting for fork to be ready, current status: %s... (%d/%d)", p.ImportStatus, i+1, maxForkRetries)
time.Sleep(forkRetryInterval)
}
Cool, thanks |
failing in CI due to GitLab fork permissions (CI token can't create forks I guess) and I think the test infrastructure has different limitations in different environments. |
the gitlab token for e2e is using my account, we need to change this... Maybe we should try to create multiple existent repo and not creating/deleting, Or create a new pac user and have a elevated token in there that can do anything we want... all of those needs some pre setup and work... were you able to test your e2e manually? |
📝 Description of the Change
When PaC reports validation errors on GitLab merge requests from repository forks, it was incorrectly using
SourceProjectID
in API calls. Since merge requests are objects on theTargetProject
, this resulted in 404 errors and no comments were added.Fixed
CreateComment
method to useevent.TargetProjectID
instead ofv.sourceProjectID
for all merge request operations.JIRA Ref: https://issues.redhat.com/browse/SRVKP-8246
🔗 Linked GitHub Issue
Fixes #
👨🏻 Linked Jira
🚀 Type of Change
fix:
)feat:
)feat!:
,fix!:
)docs:
)chore:
)refactor:
)enhance:
)🧪 Testing Strategy
✅ Submitter Checklist
fix:
,feat:
) matches the "Type of Change" I selected above.make test
andmake lint
locally to check for and fix anyissues. For an efficient workflow, I have considered installing
pre-commit and running
pre-commit install
toautomate these checks.