Skip to content

Conversation

@callum-p
Copy link
Contributor

@callum-p callum-p commented Oct 26, 2020

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.

@aksenov007
Copy link

aksenov007 commented Nov 13, 2020

A must-have feature, @baymac @markyjackson-taulia @Casz @justinharringa could you have a look at this, please?

image

try {
GitLabApi gitLabApi = GitLabHelper.apiBuilder(source.getServerName());
LOGGER.log(Level.FINE, String.format("Notifiying commit: %s", hash));
gitLabApi.getCommitsApi().addCommitStatus(

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);

Copy link
Contributor Author

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.

Copy link
Contributor Author

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(

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);

@amit-gueta
Copy link

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.

Hi,
Currently it doesn't even trigger an MR if my repo is a fork, how did you configure it to work with fork repos?
I'm getting in the log - "Ignoring merge requests as project is a mirror..."

(sorry if it's not the right place for my message)

@callum-p
Copy link
Contributor Author

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.

Hi,
Currently it doesn't even trigger an MR if my repo is a fork, how did you configure it to work with fork repos?
I'm getting in the log - "Ignoring merge requests as project is a mirror..."

(sorry if it's not the right place for my message)

Is it a fork in the same organization? It is in my case

@amit-gueta
Copy link

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.

Hi,
Currently it doesn't even trigger an MR if my repo is a fork, how did you configure it to work with fork repos?
I'm getting in the log - "Ignoring merge requests as project is a mirror..."
(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.
but I didn't use "Gitlab group" in jenkins, I used "Multibranch".. maybe because of this?

@callum-p
Copy link
Contributor Author

@MarkEWaite @markyjackson-taulia can you have a look at this?

@callum-p
Copy link
Contributor Author

callum-p commented Jun 10, 2021

@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.

Copy link
Member

@LinuxSuRen LinuxSuRen left a comment

Choose a reason for hiding this comment

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

LGTM

@LinuxSuRen LinuxSuRen merged commit cbe0d50 into jenkinsci:master Aug 30, 2021
@callum-p callum-p deleted the support-forks branch August 30, 2021 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants