-
Notifications
You must be signed in to change notification settings - Fork 105
Support setting build status when MR is from another project #100
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
6da0804 to
e3837c8
Compare
|
A must-have feature, @baymac @markyjackson-taulia @Casz @justinharringa could you have a look at this, please? |
| try { | ||
| GitLabApi gitLabApi = GitLabHelper.apiBuilder(source.getServerName()); | ||
| LOGGER.log(Level.FINE, String.format("Notifiying commit: %s", hash)); | ||
| gitLabApi.getCommitsApi().addCommitStatus( |
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.
The block could be rewritten in this way:
Integer projectId = (revision instanceof MergeRequestSCMRevision) ? getSourceProjectId(build.getParent(), gitLabApi, source.getProjectPath()) : source.getProjectPath()
gitLabApi.getCommitsApi().addCommitStatus(
projectId,
hash,
state,
status);
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.
Thanks for the tip. That didn't quite work, it produced the below error.
[ERROR] /build/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabPipelineStatusNotifier.java:[306,178] incompatible types: bad type in conditional expression
I did expand upon your suggested change and managed to get it working. PR updated.
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.
Nevermind, reverted. Had some linting errors and I can't really be bothered spending any more time on this.
| // it is our nonce, so remove it | ||
| resolving.remove(job); | ||
| } | ||
| gitLabApi.getCommitsApi().addCommitStatus( |
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.
The block could be rewritten in this way:
Integer projectId = (revision instanceof MergeRequestSCMRevision) ? getSourceProjectId(build.getParent(), gitLabApi, source.getProjectPath()) : source.getProjectPath()
gitLabApi.getCommitsApi().addCommitStatus(
projectId,
hash,
state,
status);
9a328ae to
e3837c8
Compare
Hi, (sorry if it's not the right place for my message) |
Is it a fork in the same organization? It is in my case |
Yes, it is in the same organization. |
|
@MarkEWaite @markyjackson-taulia can you have a look at this? |
|
@baymac @markyjackson-taulia @Casz @justinharringa bump. Can we get a simple review on a 60 line change, and possibly an approval? Do I need to do something else to expedite this process? Ridiculous. |
LinuxSuRen
left a comment
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

Currently if you have a fork in another project and try to do an MR into the main project, the API will return a 404 because it is looking for the commit in the wrong project. See jenkinsci/gitlab-plugin#549 for similar problem discussion.
The change here is that now it will use the Gitlab API to find the source project ID instead of assuming it is the same. Also fixes a bug where the ref isn't sent as part of the status check, which caused status checks to not update for the correct MR when there is an MR and a branch with the same head sha.
This has fixed it for me.
Not a java dev, but hopefully this isn't too bad.