Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: honor parameter value passed#1271

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nejch merged 1 commit intopython-gitlab:masterfromunknown repositoryFeb 15, 2021
Merged

fix: honor parameter value passed#1271

nejch merged 1 commit intopython-gitlab:masterfromunknown repositoryFeb 15, 2021

Conversation

ghost
Copy link

Gitlab allows setting the defaults for MR to delete the source. Also
the inline help of the CLI suggest that a boolean is expected, but no
matter what value you set, it will always delete.

To mimic the existing behavior as good as possible, we check for not false
instead of true. This way the impact on the cli will be minimal.

@codecov-io
Copy link

codecov-io commentedJan 28, 2021
edited
Loading

Codecov Report

Merging#1271 (c2f8f0e) intomaster (9fcd962) willnot change coverage.
The diff coverage is0.00%.

Impacted file tree graph

@@           Coverage Diff           @@##           master    #1271   +/-   ##=======================================  Coverage   80.58%   80.58%           =======================================  Files          65       65             Lines        3240     3240           =======================================  Hits         2611     2611             Misses        629      629
FlagCoverage Δ
unit80.58% <0.00%> (ø)

Flags with carried forward coverage won't be shown.Click here to find out more.

Impacted FilesCoverage Δ
gitlab/v4/objects/merge_requests.py65.45% <0.00%> (ø)

Continue to review full report at Codecov.

Legend -Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered byCodecov. Last update9fcd962...c2f8f0e. Read thecomment docs.

@ghostghost changed the titlefix: Honor parameter value passedfix: honor parameter value passedJan 28, 2021
@max-wittig
Copy link
Member

The existing behavior only happens, if you setshould_remove_source_branch to default be true:

image

Wouldn't this also work?:

data["should_remove_source_branch"]=should_remove_source_branch

@ghost
Copy link
Author

@max-wittig with existing behavior I was referring to GitLab CLI behavior.

If I use the released code to executegitlab project-merge-request merge --project-id 22306244 --iid 197 --should-remove-source-branch XXXX, where XXXX can be anything,true will be sent on the API request.

My MR changes the behavior to, while XXXX is anything butfalse,true is sent on the API request. So it's as close as possible to the current behavior, while still allowing to set it to false. Currently, you can't set it to false at all.

Yes, we have theEnable "Delete source branch" option by default set. That's why we ran into the issue in the first place.

@ghostghost removed their assignmentJan 29, 2021
@max-wittig
Copy link
Member

I got that, but wouldn't the mentioned line of code also work?

data["should_remove_source_branch"]=should_remove_source_branch

@ghost
Copy link
Author

Yes, it would work but reduce XXXX to onlytrue orfalse (case insensitive). This will break backward compatibility a little but if you don't mind in this specific case being backward compatible, I can change it.

@max-wittig
Copy link
Member

If you omit the flag, GitLab will use the default setting in your project (could be true or false).

And also your fix is not gonna work, only for your configuration. python-gitlab is not actively sendingshould_remove_source_branch for every request. If it's omitted, GitLab just uses the default. Whatever your projects/groups default is.

The string value should be converted to a boolean value

Something like this should work

ifshould_remove_source_branchisnotNone:should_remove_source_branch=bool(distutils.util.strtobool(data["should_remove_source_branch"]))

data["should_remove_source_branch"] = True
if should_remove_source_branch is not None:
data["should_remove_source_branch"] = bool(
strtobool(should_remove_source_branch)
Copy link
Member

Choose a reason for hiding this comment

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

the only problem here is whenshould_remove_source_branch is already a bool. Then this will crash 🤔

@max-wittig
Copy link
Member

Might not be the cleanest solution, but that works. Any other ideas@nejch

@ghost
Copy link
Author

ghost commentedFeb 1, 2021
edited by ghost
Loading

Might not be the cleanest solution, but that works. Any other ideas@nejch

@max-wittig would you prefer the shorter solution ofbool(strtobool(str(should_remove_source_branch)))? That would also avoid the crash but I'd consider it unclean.

Or should I create a utils.py function that streamlines the code?

@max-wittig
Copy link
Member

I prefer your current approach, but I'm unsure.@nejch any further ideas?

@nejch
Copy link
Member

I prefer your current approach, but I'm unsure.@nejch any further ideas?

It also seems a bit more readable but I'm wondering if there are other custom methods that might be affected by this, in which case it might make sense to have utils function for it. I will have a quick look for others now and update here.

@nejch
Copy link
Member

After testing the existing behavior, I think going for the simpler option with justdata["should_remove_source_branch"] = should_remove_source_branch makes the most sense.

With this fix, passing--should-remove-source-branch withTrue/true will delete it,false/False will not, and any other value will raise an error withshould_remove_source_branch is invalid. I tested it manually but maybe we can add some tests.

I don't think it's worth preserving existing behavior for other edge cases because it wasn't documented anywhere and the only reasonable expectation IMO is that one of the above options is passed. People who have been using it as documented (even if it had no effect) would not see any undesired change. In any case it's one of themany places where the CLI is misbehaving and we warn in the CLI reference that some options may be unstable I think :)

Do you agree @allcloud-jonathan@max-wittig?

max-wittig reacted with thumbs up emoji

@nejchnejch assignedghost and unassignednejchFeb 7, 2021
@ghost
Copy link
Author

Maybe I'm not getting your suggestion,@nejch, butdata["should_remove_source_branch"] = should_remove_source_branch would you mean this:

if should_remove_source_branch is not None:    data["should_remove_source_branch"] = should_remove_source_branch

or this:

data["should_remove_source_branch"] = should_remove_source_branch

The first one fails for the non-CLI tests. The second one additionally now makes the parameter mandatory which means I can no longer use the default setup on the repo.

@nejch
Copy link
Member

I meant the first option - what API tests are failing for you? Maybe it's just some of the flaky functional tests. I've tried and all tests passed it seems - I also tried manually withmr.merge(should_remove_source_branch="false") which receives a truthy value that still gets sent 'correctly' as"false" to the API and the branch is not deleted.

@ghost
Copy link
Author

@nejch can you retrigger the tests? Haven't changed that part and previously it worked...

@nejch
Copy link
Member

@nejch can you retrigger the tests? Haven't changed that part and previously it worked...

Thanks @allcloud-jonathan that definitely looks like those flaky tests, running again.

Gitlab allows setting the defaults for MR to delete the source. Alsothe inline help of the CLI suggest that a boolean is expected, but nomatter what value you set, it will always delete.
@max-wittig
Copy link
Member

@nejch Should be good now then, right?

@nejch
Copy link
Member

@nejch Should be good now then, right?

Ah sorry, looks good to me too :) @allcloud-jonathan sorry this took a while.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@codecov-io@max-wittig@nejch@bitte-ein-bit

[8]ページ先頭

©2009-2025 Movatter.jp