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

fix(gitlab): Add backwards compatible mergability check #3277

Merged
merged 2 commits into from
Mar 31, 2023

Conversation

jukie
Copy link
Contributor

@jukie jukie commented Mar 29, 2023

what

Adds a conditional for whether the gitlab client version supports detailed_merge_status (anything 15.6+) and will use the old merge_status if it doesn't.

why

In newer versions of Atlantis, apply requirements won't work if users are running older versions of gitlab.

tests

I don't have a gitlab server <15.6 to test with but I've reviewed the api response data and updated tests accordingly

references

@jukie jukie requested a review from a team as a code owner March 29, 2023 19:50
@github-actions github-actions bot added go Pull requests that update Go code provider/gitlab labels Mar 29, 2023
@@ -408,8 +429,8 @@ func TestGitlabClient_MarkdownPullLink(t *testing.T) {
Equals(t, exp, s)
}

var mergeSuccess = `{"id":22461274,"iid":13,"project_id":4580910,"title":"Update main.tf","description":"","state":"merged","created_at":"2019-01-15T18:27:29.375Z","updated_at":"2019-01-25T17:28:01.437Z","merged_by":{"id":1755902,"name":"Luke Kysow","username":"lkysow","state":"active","avatar_url":"https://secure.gravatar.com/avatar/25fd57e71590fe28736624ff24d41c5f?s=80\u0026d=identicon","web_url":"https://gitlab.com/lkysow"},"merged_at":"2019-01-25T17:28:01.459Z","closed_by":null,"closed_at":null,"target_branch":"patch-1","source_branch":"patch-1-merger","upvotes":0,"downvotes":0,"author":{"id":1755902,"name":"Luke Kysow","username":"lkysow","state":"active","avatar_url":"https://secure.gravatar.com/avatar/25fd57e71590fe28736624ff24d41c5f?s=80\u0026d=identicon","web_url":"https://gitlab.com/lkysow"},"assignee":null,"source_project_id":4580910,"target_project_id":4580910,"labels":[],"work_in_progress":false,"milestone":null,"merge_when_pipeline_succeeds":false,"detailed_merge_status":"mergeable","sha":"cb86d70f464632bdfbe1bb9bc0f2f9d847a774a0","merge_commit_sha":"c9b336f1c71d3e64810b8cfa2abcfab232d6bff6","user_notes_count":0,"discussion_locked":null,"should_remove_source_branch":null,"force_remove_source_branch":false,"web_url":"https://gitlab.com/lkysow/atlantis-example/merge_requests/13","time_stats":{"time_estimate":0,"total_time_spent":0,"human_time_estimate":null,"human_total_time_spent":null},"squash":false,"subscribed":true,"changes_count":"1","latest_build_started_at":null,"latest_build_finished_at":null,"first_deployed_to_production_at":null,"pipeline":null,"diff_refs":{"base_sha":"67cb91d3f6198189f433c045154a885784ba6977","head_sha":"cb86d70f464632bdfbe1bb9bc0f2f9d847a774a0","start_sha":"67cb91d3f6198189f433c045154a885784ba6977"},"merge_error":null,"approvals_before_merge":null}`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What I've done here is add "merge_status":"can_be_merged" to the testdata response. If preferred I can add a fully separate dataset instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

I will say maybe add a fully separated dataset instead

Copy link
Member

Choose a reason for hiding this comment

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

Oh missed this comment. Agreed. It would be better to just put it in a separate pretty formatted json file. We do separate supporting test files for terraform tests so json wouldn't be any different

@nitrocode nitrocode added this to the v0.23.4 milestone Mar 29, 2023
@nitrocode
Copy link
Member

@jukie do you mind pairing with someone in issue #3258 like @zerog2k and having them verify that this change will work as expected for older versions since you do not have a version to test with?

If you take your feature branch and merge it with your HEAD branch of your fork, new atlantis container will be built and pushed to your fork. This new image can then be used by anyone to verify the change in this pr works as expected.

@jukie
Copy link
Contributor Author

jukie commented Mar 29, 2023

@zerog2k if you could check with either of the following images:

@nitrocode
Copy link
Member

cc @skruger ^

@nitrocode
Copy link
Member

Also from #3089 cc @rhysm @mustdiechik

@nitrocode nitrocode changed the title Add backwards compatibility for merability check in Gitlab client fix(gitlab): Add backwards compatible merability check Mar 30, 2023
@nitrocode nitrocode changed the title fix(gitlab): Add backwards compatible merability check fix(gitlab): Add backwards compatible mergability check Mar 30, 2023
@zerog2k
Copy link

zerog2k commented Mar 30, 2023

  • docker pull ghcr.io/jukie/atlantis:dev-alpine-bb0882f

Thanks @jukie appears to be working for me on gitlab ee 14.10.5 and your build

@jukie
Copy link
Contributor Author

jukie commented Mar 30, 2023

@nitrocode looks like we're good here then? I'll get the test case updated though.

@nitrocode nitrocode merged commit 8adb001 into runatlantis:main Mar 31, 2023
@nitrocode
Copy link
Member

Thank you @jukie @zerog2k !

I'm 20 minutes this will spin up a new build and save the new image as dev. Feel free to use that image until v0.23.4 is released.

@d-cryptic
Copy link

d-cryptic commented Mar 31, 2023

I tried the dev image, I am still facing the same issue #3270
Will it only work for mergeable argument as of now? Will it work for approved too?

@jukie
Copy link
Contributor Author

jukie commented Mar 31, 2023

@d-cryptic the only API change between these versions was detailed merge status vs merge status so functionality for approvals should be the same.
Could you try adding --require-approval to your server startup flags?

@d-cryptic
Copy link

I did, but it's not working !!

@nitrocode
Copy link
Member

@d-cryptic i know this is frustrating for you. Please remember that we're all doing this as volunteer work so please try to keep your messages as helpful as possible to reduce the back and forth.

For a developer to fix this, can you post error logs and anything that may be helpful in #3270 (the issue you first created)? I have reopened the ticket.

@jukie
Copy link
Contributor Author

jukie commented Apr 1, 2023

Check my note in #3270 (comment)

@d-cryptic is running gitlab community edition so requiring approvals before merge isn't an option.

@jukie jukie deleted the jukie/fix-apply-requirements-gitlab branch April 1, 2023 15:47
@jamengual
Copy link
Contributor

jamengual commented Apr 1, 2023 via email

@jukie
Copy link
Contributor Author

jukie commented Apr 1, 2023

I can add a note within the Gitlab section of https://www.runatlantis.io/docs/command-requirements.html#approved

Also wondering the best place in code is to add a check via https://docs.gitlab.com/ee/api/metadata.html for the value of enterprise and log whether approve requirements are supported.

@jukie
Copy link
Contributor Author

jukie commented Apr 1, 2023

I'll open another WIP PR and we'll discuss there

@jamengual
Copy link
Contributor

jamengual commented Apr 1, 2023 via email

@d-cryptic
Copy link

Check my note in #3270 (comment)

@d-cryptic is running gitlab community edition so requiring approvals before merge isn't an option.

So in community edition, approved requirement won't work right?

@jukie
Copy link
Contributor Author

jukie commented Apr 4, 2023

Correct @d-cryptic.

Looks like there was already a notice in the docs as well so I'm not sure we need any updates there -

* For more information on GitLab merge request reviews and approvals (only supported on GitLab Enterprise) see: [https://docs.gitlab.com/ee/user/project/merge_requests/merge_request_approvals.html](https://docs.gitlab.com/ee/user/project/merge_requests/merge_request_approvals.html).

nitrocode pushed a commit that referenced this pull request May 5, 2023
* Add backwards compatibility for merability check in Gitlab client

* Cleanup
ijames-gc pushed a commit to gocardless/atlantis that referenced this pull request Feb 13, 2024
…3277)

* Add backwards compatibility for merability check in Gitlab client

* Cleanup
ijames-gc pushed a commit to gocardless/atlantis that referenced this pull request Feb 13, 2024
…3277)

* Add backwards compatibility for merability check in Gitlab client

* Cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code provider/gitlab
Projects
None yet
Development

Successfully merging this pull request may close these issues.

apply fails with apply_requirements mergeable on gitlab < 15.6
5 participants