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: Include required checks while evaluating the mergeable state if apply is bypassed #3916

Closed
wants to merge 1 commit into from

Conversation

bhavith
Copy link

@bhavith bhavith commented Nov 3, 2023

what

Currently when the apply condition is set to mergeable along with --gh-allow-mergeable-bypass-apply flag, Atlantis considers non required status checks as well to decide whether the PR is mergeable or not (to allow apply or not). This is a deviation from standard github mergeable status.

This PR changes that and includes only required status checks while evaluating mergeable status.

why

Atlantis uses mergeable status from github API to check if a PR is mergeable if --gh-allow-mergeable-bypass-apply is not set. That is if the status is unstable, the PR is considered mergeable.

unstable: Failing/pending commit status that is not part of the required
	//           status checks. Merging is allowed (yellow box).

If --gh-allow-mergeable-bypass-apply enabled, github uses some additional checks to see if the PR is mergeable without considering atlantis apply. But in these additional checks, Atlantis looks at all statuses irrespective of if they are required or not. So, if there is a status check that is failing Atlantis will consider it non mergeable even if its not a required status check and thus will block Apply.

In this change, while checking if the state is success, it will also check if the particular status is one of the required checks. Hence Atlantis will report non mergeable only if the failing status check is a required one.

tests

  • I have adjusted the test data to include scenarios where there could be failing non required checks
  • I have tested this by running atlantis locally against a terraform repository with a few valid scenarios

@bhavith bhavith requested a review from a team as a code owner November 3, 2023 21:57
@github-actions github-actions bot added go Pull requests that update Go code provider/github labels Nov 3, 2023
@bhavith bhavith changed the title fix: Include only required checks while evaluating the mergeable state when apply is ignored fix: Include only required checks while evaluating the mergeable state when apply is bypassed Nov 3, 2023
@bhavith bhavith changed the title fix: Include only required checks while evaluating the mergeable state when apply is bypassed fix: Include required checks while evaluating the mergeable state if apply is bypassed Nov 3, 2023
@jamengual
Copy link
Contributor

@lukemassa do you happen to have any input on this?

@lukemassa
Copy link
Contributor

I am much less familiar with github's terminology/expectations around checks, but this logic seems reasonable to me. Right now it seems like we're only considered required vs not for check suites, whereas this change makes it so we look at required vs not for combined check status as well.

@bhavith
Copy link
Author

bhavith commented Nov 7, 2023

Hi @jamengual, Anything needed from my end to take this forward? I am kinda new here as a contributor :) so not sure how exactly it works.

@jamengual
Copy link
Contributor

Hi @bhavith.

We need to review the code when we find some time.

We will get back to you as soon as we can.

Thanks for the contribution.

@bhavith
Copy link
Author

bhavith commented Nov 7, 2023

perfect! 👍

@brandon-fryslie
Copy link

We have run into this a quite a few times and weren't sure what was going on. Here's the scenario:

  • GitHub + Jenkins + Jenkins Branch Source Plugin (automatically creates a separate job per branch and per PR)
  • A user pushes a new branch. This kicks off a job. The job sets a commit status (e.g., branch-build). This is NOT a required check
  • Before the branch build finishes, the user opens a PR from the branch. This check IS required. This job kills the branch build, leaving it in a failure state. We don't care about the status of branch builds, only PR builds
  • Atlantis won't auto-merge the PR as expected because apply is a required check and we have --gh-allow-mergeable-bypass-apply enabled.

This seems to happen intermittently rather than consistently, but it's possible it's only working when either a) the branch build never starts because a PR is opened immediately, or b) the branch build has finished successfully before the PR build begins.

@stasostrovskyi
Copy link
Contributor

It will probably make sense to combine this PR with this change #3812 to make the whole feature even more reliable.

@GenPage GenPage added bug Something isn't working waiting-on-response Waiting for a response from the user work-in-progress labels Dec 12, 2023
@GenPage
Copy link
Member

GenPage commented Dec 12, 2023

Looks like the PR author of #3812 doesn't have time to work on his PR, please feel free to merge both in this PR.

@bhavith
Copy link
Author

bhavith commented Dec 15, 2023

Will have a look at #3812 and get back.

@bhavith
Copy link
Author

bhavith commented Dec 22, 2023

Looks like the PR author of #3812 doesn't have time to work on his PR, please feel free to merge both in this PR.

I will make some changes in this PR based on #3812 (comment). That will be in 2024. Happy holidays. 🎄

Copy link

This issue is stale because it has been open for 1 month with no activity. Remove stale label or comment or this will be closed in 1 month.

@github-actions github-actions bot added the Stale label Jan 23, 2024
@GenPage GenPage removed the Stale label Jan 24, 2024
@GenPage
Copy link
Member

GenPage commented Jan 24, 2024

@bhavith any update?

@bhavith
Copy link
Author

bhavith commented Jan 24, 2024

@bhavith any update?

Came back from vacation sick and weather in Norway wasn't very helpful either. I will try to work on it sometime this week/weekend.

@stasostrovskyi
Copy link
Contributor

@bhavith Our team was trying to fix support for github rulesets and the solution turned out to be overlapping with your PR. Please, take a look at #4193 and let us know what you think

@bhavith
Copy link
Author

bhavith commented Jan 31, 2024

@bhavith Our team was trying to fix support for github rulesets and the solution turned out to be overlapping with your PR. Please, take a look at #4193 and let us know what you think

Nice. That PR looks like a more comprehensive fix including mine and #3812 . I will follow that PR.

Copy link

github-actions bot commented Mar 3, 2024

This issue is stale because it has been open for 1 month with no activity. Remove stale label or comment or this will be closed in 1 month.

@github-actions github-actions bot added the Stale label Mar 3, 2024
@github-actions github-actions bot closed this Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working go Pull requests that update Go code provider/github Stale waiting-on-response Waiting for a response from the user work-in-progress
Projects
Status: Backlog
Development

Successfully merging this pull request may close these issues.

6 participants