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

Gitlab MR with approvals_before_merge > 0 causes issues with mergeable requirement #876

Open
JoshiiSinfield opened this issue Dec 11, 2019 · 4 comments
Labels
provider/gitlab question Further information is requested Stale

Comments

@JoshiiSinfield
Copy link
Contributor

Hi,

When apply_requirements: [approved, mergeable] is specified, and a MR is generated, we are unable to apply the MR due to the following error message:

Apply Failed: Pull request must be mergeable before running apply.

Looking through the code I believe it's because of

if mr.MergeStatus == "can_be_merged" && mr.ApprovalsBeforeMerge <= 0 {

When a merge request has approvals required the "approvals_before_merge" field on the MR has as number >0. This causes the MR to always be "not mergeable" based on the above.

Is this expected behaviour? I'm still not sure what makes this field be >1, because we have the same apply_requirements on other gitlab repos, with approval rules to require >=1 approval and this issue doesn't happen.

Running atlantis 0.9.0.

Cheers,
Josh

@lkysow lkysow added the question Further information is requested label Dec 11, 2019
@lkysow
Copy link
Member

lkysow commented Dec 11, 2019

Hi Josh, that number should be set to the number of approvals required and then decremented by each approval.

If this is not happening can you provide me screenshots of your settings, the approvals, and the result of the API call as well your version of GitLab.

Thanks!

@lkysow lkysow added the waiting-on-response Waiting for a response from the user label Dec 11, 2019
@lkysow
Copy link
Member

lkysow commented Jan 3, 2020

Closing this because I haven't heard back.

@lkysow lkysow closed this as completed Jan 3, 2020
@lkysow lkysow removed the waiting-on-response Waiting for a response from the user label Jan 3, 2020
@JoshiiSinfield
Copy link
Contributor Author

Hi @lkysow,

Apologies for not replying to you sooner.
the number wasn't been decremented no. I'll do my best to get you some screenshots in the next few days or so.

Cheers,
Josh

@ghost
Copy link

ghost commented Jan 10, 2020

I ran into this bug awhile back and did some digging in the code but never got around to filing an issue. The problem is that Atlantis checks the approval count on the wrong Gitlab resource. It is looking at the approvals_before_merge field on the merge request resource when it should be looking at the approvals_left field on the merge request approvals resource. As far as I can tell, the approvals_before_merge field is the configured number of approvals required for the MR and not the remaining number of approvals. That is why the value doesn't is still greater than zero even though the MR has been approved. When I was digging through the code, the Gitlab Go library did not have support for the merge request approvals resource but it looks like it has since been added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
provider/gitlab question Further information is requested Stale
Projects
None yet
Development

No branches or pull requests

3 participants