atlantis: Able to apply despite GitHub's PR not being mergeable
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Searching for pre-existing feature requests helps us consolidate datapoints for identical requirements into a single place, thank you!
- Please do not leave “+1” or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
- If you are interested in working on this issue or have submitted a pull request, please leave a comment.
Overview of the Issue
Atlantis applies change set even when PR has pending CODEOWNERS reviews.
Merge button is read:
Mergeable_status is blocked:
"author_association": "CONTRIBUTOR",
"auto_merge": null,
"active_lock_reason": null,
"merged": false,
"mergeable": true,
"rebaseable": true,
"mergeable_state": "blocked",
"merged_by": null,
Reproduction Steps
Open a PR that requires CODEOWNERS approval.
Comment atlantis apply
Atlantis will apply plan, but fail automerge because its blocked.
Logs
Environment details
If not already included, please provide the following:
- Atlantis version: 0.18.1
- If not running the latest Atlantis version have you tried to reproduce this issue on the latest version: Not yet
- Atlantis flags:
atlantis server --config /etc/atlantis/config.yaml
Atlantis server-side config file:
---
repos:
- id: /.*/
apply_requirements: [mergeable]
Repo atlantis.yaml file:
version: 3
delete_source_branch_on_merge: true
projects:
- dir: some/project
- dir: someother/project
Additional Context
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 18
- Comments: 23 (14 by maintainers)
This seems to have been fixed for us. Previously it was possible to run
atlantis applywith anyone’s approval on a PR even ifCODEOWNERSapproval was required in the branch protection but now Atlantis properly prevents the apply from executing.Info from our environment in case it helps anyone:
v0.20.1apply_requirements: [approved, mergeable]Require review from Code Ownersenabled.Require status checks to pass before mergingincludingatlantis/planandatlantis/applystatus checks.ATLANTIS_GH_ALLOW_MERGEABLE_BYPASS_APPLYset totruein order to work with theatlantis/applystatus check.Administration -> readas commented here"unable to get pull request status: fetching mergeability status for repo: omitted, and pull number: omitted: getting pull request status: getting required status checks: GET https://api.github.com/repos/omitted/omitted/branches/main/protection: 403 Resource not accessible by integration []@chicocvenancio Unfortunately we had to revert it due to the regression. However, https://github.com/runatlantis/atlantis/pull/2436 is another attempt to add in the feature without breaking existing use cases. It would be highly appreciated if you can share your knowledge there. Hopefully, we can get it right this time 🤞
I reached out as requested to
security[AT]runatlantis[DOT]ioper https://github.com/runatlantis/atlantis/blob/master/SECURITY.md pointing them to this thread.I think there’s potentially a regression after https://github.com/runatlantis/atlantis/pull/2053
If I understand correctly, the condition in https://github.com/runatlantis/atlantis/blob/76d7080b60b09445c686b35d2697fa9308842a53/server/events/vcs/github_client.go#L319 would apply to a PR that’s passed all checks except
atlantis/applyand it’d returntrueforPullIsMergeableeven if it hasn’t been approved.Furthermore, even if we have
approvedinapply_requirements, this takes in any approval not necessarily one byCODEOWNERS. So, in our setup, even withanyone can approve the PR and merge it, as long as the only check missing is
atlantis/apply.I actually realized earlier and made this other comment about it and still pasted here the wrong name 🤦🏻♂️ . Edited now, thanks! 😄
@Roberdvs
Make sure to change
ATLANTIS_GH_MERGEABLE_BYPASS_APPLYtoATLANTIS_GH_ALLOW_MERGEABLE_BYPASS_APPLYref: https://www.runatlantis.io/docs/server-configuration.html#gh-allow-mergeable-bypass-apply
I’ve got a workaround working using a custom apply step (we use
terragruntalready so we have it configured elsewhere). We run on GitHub Enterprise hence the/apiURL. Our apply steps look like this:This uses the GraphQL API to query for the PR
reviewDecisionas documented in https://docs.github.com/en/graphql/reference/objects#pullrequest and https://docs.github.com/en/graphql/reference/enums#pullrequestreviewdecision. The PR is not inAPPROVEDstate unless a code owner has reviewed it.It’s definitely a quick workaround and could be improved, but it saves us from having changes applied with any review (not coming from a code owner). I’d like to find some time and add this back into the codebase. Hopefully next week.
@chenrui333 Hard to tell. According to atlantis documentation, mergeable requirement includes review from CODEOWNERS already.
My issue isn’t that I want PR to mergeable only after atlantis did apply, my issue is that atlantis applies unapproved changes.