-
Notifications
You must be signed in to change notification settings - Fork 136
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
Fixes squash merge request for Single Job Mode #369
base: master
Are you sure you want to change the base?
Fixes squash merge request for Single Job Mode #369
Conversation
7e25cd2
to
00785b2
Compare
e8950d3
to
0e4e82c
Compare
@snim2 can you help review these changes. Thanks |
I'll have a look for you later today. |
@snim2 thanks, we have tested the main scenario in our test project and it is working. We are checking remaining scenarios. Also I needed to add test case for the same, but would require some help to understand how it has been setup. |
pylintrc
Outdated
@@ -30,7 +30,7 @@ max-line-length=110 | |||
[DESIGN] | |||
max-args=10 | |||
max-attributes=15 | |||
max-public-methods=35 | |||
max-public-methods=40 |
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.
This is possibly something that the project owners will want to look at, but IMO it's fine in this repo
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.
Although this seems to be reverted in the next commit?
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.
Yes so there were 2 approaches in which this could have done. Earlier I was merging the project config with the MR config and then taking a decision.
But then I thought that there is only one case we need to address which is when at project level we have sqaush_option: always
, so we are not taking any decision on behalf of the user or gitlab, instead we are respecting user's configuration and only sending squash: true
when the project level configuration is set to always because in that case even gitlab won't allow the user to change the configuration at MR level.
For the earlier case I had to add a method to merge_request
class which was exceeding the number of methods, but in this case we don't have to deal with this class at all, hence reverted.
marge/single_merge_job.py
Outdated
auto_squash = None | ||
if self.is_auto_squash_enabled(merge_request): | ||
auto_squash = True | ||
auto_squash = True if target_project.squash_enforced else None |
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.
Why not True if target_project.squash_enforced else False
?
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.
Again from my previous comment, a user is allowed to choose if he / she wants squash at 3 different places.
- in the project settings
- in the merge request settings
- while merging the merge request
Out of all the case only one case we had to solve for when squash is set to required
at project level. In this case we are supposed to pass this extra parameter squash: True
which more or less actually seems like a bug to me from gitlab
side, remaining cases we are not sending this parameter and letting gitlab take the decision based on it's business logic based on user's input.
Hence a distinction between False & None. It has been sometime since I have worked in python, so not sure if this the best way to write it. But this is intentional, I can add a comment over this line to make it more clear.
I don't think I have maintainer rights here, but this looks OK to me! |
I've also tested this fix just now on one of our private GitLab repos (GitLab SaaS), and I can confirm this fix works quite nicely. ✅ |
Thanks @theipster, @snim2 would require some help with the test cases, I haven't had experience writing test cases in python, I am trying still. There are few things I need to take care I believe:
as always True, becuase squash_enforced is mocked. This is defeating the purpose for test case Is there a better way this can be handled.
|
I'm neither an expert in Python nor marge-bot, but I can try and give some suggestions. 🙂 Firstly, this may help: I consider the MR-level So, in terms of your questions:
This is not defeating the purpose. With the introduction of this project-level setting, this simply means there are now additional scenarios to consider:
Scenarios 1 and 3 (MR For scenario 2, you should add a new test case (e.g. Scenario 4 is the "happy path" where we don't expect any exceptions. You can add a new test case for this if you like. This scenario is not specific to squashing, and I guess it was simply forgotten.
These existing So, in our case, instead of asserting on the exact HTTP response, it simply asserts that a HTTP request was made with certain parameters. This is because it's painful to control the HTTP response. In terms of how to what you need to do:
|
@theipster thanks for this detailed explanation. I am currently busy with my work but would surely like to contribute and complete this PR by the end of this month with proper test cases. |
See https://stackoverflow.com/a/73932581. It seems like importlib-metadata is only required for tests, not production code.
…mplify mocking) the only API calls made in marge-bot are `/projects` (with `simple` undefined) and `/projects/:id`, and both responses always contain the `squash_option` field to limit the scope of validation outside `Project`, convert `squash_option` into an enum
also rename test to reflect wanting vs needing to squash
@anuragagarwal561994 I had some spare time and so I decided to roll up my sleeves and have a go myself - I hope you don't mind! Please see anuragagarwal561994#1, which adds some tests and also fixes some pip dependencies (which are unfortunately necessary for running the test suite). |
@theipster thanks a lot for doing this, I will review the changes from my end. No mind of course, I am not getting time to sit for this honestly :) |
Add tests
@theipster I have found the changes to be appropriate and I have merged the same. @snim2 I guess there is a dependent change by @theipster which is included in this MR as well I suppose we can review and merge the same first and then we can re-review and merge this one. |
@snim2 did you get time to review and merge the same? |
@anuragagarwal561994 I don't have rights to merge in this repo :) |
@snim2 who can help with this? |
Someone from Smarkets, I guess, but you'd have to look back through the old PRs and see who merged them to find a username |
@nithyashree675 @qqshfox can you help with the same? |
GitLab has option to configure squash and merge option at three places:
When we are accepting a merge request, if the option to squash enforced is enabled at a project level, we need to pass
squash: true
while accepting the merge request in the API call or else we get error on GitLab:Currently the MR is stuck in loop and marge bot crashes. This MR tries to address and resolve the following issues:
#326
#297
#333
#152