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

feat: improving apply requirements for mergeable on Gitlab #1675

Merged

Conversation

devlucasc
Copy link
Contributor

@devlucasc devlucasc commented Jun 30, 2021

Why:
This PR solves the following issues:

  1. MR can be applied even if it has a failed pipeline in Gitlab CI/CD when "Pipelines must succeed" is enabled
  2. MR can be applied even if it has open unresolved threads when "All discussions must be resolved" is enabled
  3. Atlantis auto-merge fails on auto merging the MR due to a delay between updating the pipeline build status and updating the status of the head pipeline in MR. Gitlab auto merge race condition #1609

This PR changes the behavior of apply_requirements for the mergeable requirement.

  • First, the code gets the project settings.

  • Second, the code gets statuses for all jobs for the head pipeline.

  • Then, will be checked the status for each build job. If the build job has a failure status and if doesn't allow failures, if it is a requirement, it will be marked as a non-mergeable status. (The status for Atlantis apply command will be ignored to avoid blocking the apply command itself).

  • Then, if the pipeline has a skipped status and if the project doesn't allow merge on skipped pipelines, it will be marked as a non-mergeable status.

  • Lastly, the verification of the blocking_discussions_resolved field was implemented. When the MR has open threads and it is a project requirement for the merge, this field returns false. When there are threads open but it is not a requirement or when there are no threads open regardless of whether it is a requirement or not of the project, this field returns true. This field exists since v12.5 for all tiers.

  • I added a pipeline wait routine because Atlantis was trying to merge the MR before the pipeline ended. The pipeline status returned from the Get Merge Request API has a delay compared to the statuses from the Get Commit Statuses API.
    In summary, this PR allows blocking the merge, given the project requirements, that pipelines have success status and that there are no open discussions.

@devlucasc devlucasc requested a review from a team as a code owner June 30, 2021 01:50
@chenrui333 chenrui333 changed the title Improving apply requirements for mergeable on Gitlab feat: improving apply requirements for mergeable on Gitlab Jul 7, 2021
@swade1987
Copy link

Awesome work @devlucasc can't wait to see a release with this be cut, will save us a lot of issues.

@devlucasc
Copy link
Contributor Author

Someone can rerun the CI, please? An exception was raised due to docker container and I don't have permission to do that.

@chenrui333
Copy link
Member

@devlucasc you got it.

@swade1987
Copy link

Any update on this it would greatly improve issues we are seeing at present.

@jamengual jamengual merged commit cbef84f into runatlantis:master Aug 2, 2021
@devlucasc devlucasc deleted the gitlab_mr_apply_reqs_improvement branch August 3, 2021 13:25
msarvar referenced this pull request in lyft/atlantis Sep 27, 2021
* Improving apply requirements for mergeable on Gitlab

* Fixing end of line

* Renaming variables

* Renaming variables

* Fixing variable assignment

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

Successfully merging this pull request may close these issues.

4 participants