Skip to content
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

Respect GitLab's delete source branch checkbox #1220

Merged
merged 1 commit into from
Feb 3, 2022

Conversation

UnsolvedCypher
Copy link
Contributor

Currently, acceptGitLabMR passes false to GitLab's API for should_remove_source_branch unless otherwise specified. This change makes it specify null instead, which means that unless it is specified, it will respect the checkbox in the GitLab UI for removing the source branch after merge.

@UnsolvedCypher UnsolvedCypher requested a review from a team as a code owner January 13, 2022 20:03
@basil
Copy link
Member

basil commented Jan 20, 2022

Incremental build 1.5.28-rc1334.943db_b_50c532 is available for testing. The incremental build is available from: https://repo.jenkins-ci.org/incrementals/org/jenkins-ci/plugins/gitlab-plugin/1.5.28-rc1334.943db_b_50c532/

@UnsolvedCypher Can you please test the incremental build and confirm the issue is resolved? For instructions on how to install a custom build, see: https://www.jenkins.io/doc/book/managing/plugins/#advanced-installation

@UnsolvedCypher
Copy link
Contributor Author

Hello @basil, thank you for the instructions. I have set this up locally and confirmed that this change does in fact work and causes GitLab's "Should remove source branch" checkbox to be respected.

In the process, I found that in the plugin even without my change completely ignores the removeSourceBranch parameter to acceptGitLabMR(). Before my change, it would always pass "false" to GitLab regardless of the parameter, and now with my change, it always passes "null" (which means that it defers to GitLab's checkbox).

I can open a separate issue for that, but as this PR does at least improve the situation, I think it is ready to be merged.

@basil
Copy link
Member

basil commented Jan 24, 2022

Can you please look into fixing acceptGitLabMR so that the removeSourceBranch parameter is properly propagated to the GitLab API? I fear our understanding of the problem is incomplete, and I want to get a better understanding of what is going on before releasing this.

@UnsolvedCypher
Copy link
Contributor Author

I'd be happy to look into it but I will need some help understanding the architecture. I don't really understand how the parameters from acceptGitLabMR get translated as there isn't any function in the code called acceptGitLabMR. It looks like there is some magical stuff happening through annotations. Could you give me some pointers on where to look or what to search for?

@basil
Copy link
Member

basil commented Jan 25, 2022

Sure, the relevant source file is AcceptGitLabMergeRequestStep which implements the Pipeline: Step API (see also this page). This is annotated with @DataBoundSetter:

    @DataBoundSetter
    public void setRemoveSourceBranch(boolean removeSourceBranch) {
        this.removeSourceBranch = removeSourceBranch;
    }

It seems like one problem is that this uses the mechanism for optional parameters (@DataBoundSetter) as well as the mechanism for mandatory parameters (@DataBoundConstructor) described in the docs. I can't quite tell what's truly mandatory and what's optional from reading the code, but if all parameters are optional then we should remove the @DataBoundConstructor annotation and replace it with @Deprecated. If some parameters are indeed mandatory, then we should have a @DataBoundConstructor with just those mandatory parameters. There should be no overlap between the parameters covered by @DataBoundConstructor and the parameters covered by @DataBoundSetter. Hope this helps get you started.

@UnsolvedCypher
Copy link
Contributor Author

Thank you, that is very helpful. I have determined that the request getting sent to GitLab is correct, but for some reason is still not working properly. There have been a number of bugs filed and fixed in the past few years about GitLab's should_remove_source_branch API parameter. I suspect I may be hitting one, and the version of Dockerized GitLab that this repo uses is quite old.

I've opened #1232, so if you are alright with it, I will open a PR to upgrade the docker-compose to a more modern version and see if that fixes this problem.

@basil
Copy link
Member

basil commented Jan 30, 2022

I've opened #1232, so if you are alright with it, I will open a PR to upgrade the docker-compose to a more modern version and see if that fixes this problem.

Sure, go ahead!

@UnsolvedCypher
Copy link
Contributor Author

UnsolvedCypher commented Feb 3, 2022

Hi @basil, I believe this is ready to be merged. I have made some further changes (part of the plugin was still using primitive boolean rather than Boolean), and the updated GitLab in the Dockers seemed to do the trick.

I have ensured (by building an hpi locally and installing it on a Dockerized Jenkins) that:

  1. Passing false to should_remove_source_branch always preserves the branch
  2. Passing true to should_remove_source_branch always deletes the branch
  3. Not passing anything to should_remove_source_branch defers to GitLab's checkbox

Please let me know if there are any other changes you would like to this PR!

Copy link
Member

@basil basil left a comment

Choose a reason for hiding this comment

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

Very nice! Thanks again for the PR.

@basil basil merged commit 8f05bef into jenkinsci:master Feb 3, 2022
@basil basil added the rfe label Feb 3, 2022
@UnsolvedCypher
Copy link
Contributor Author

Wonderful, thank you for the quick merge! Would it be possible to get a release sometime soon? This fix would be very helpful to have at work.

@basil
Copy link
Member

basil commented Feb 3, 2022

Released in 1.5.28.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants