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: the logic when checking the check suites #3812

Closed

Conversation

Yasmine92
Copy link

@Yasmine92 Yasmine92 commented Oct 4, 2023

what

this is an aim to fix #3811

why

as explained in the issue, Atlantis is able to apply when the required checks are still in progress. it seems to me that the logic is broken in the GetCombinedStatusMinusApply function , as it will return true when c.Status =! "completed"

tests

I have tested my changes by building Atlantis with the update I included, and built a custom image that I used in the same context and workflow, and Atlantis seemed to behave as expected.

references

@Yasmine92 Yasmine92 requested a review from a team as a code owner October 4, 2023 11:55
@github-actions github-actions bot added go Pull requests that update Go code provider/github labels Oct 4, 2023
@@ -451,6 +451,8 @@ func (g *GithubClient) GetCombinedStatusMinusApply(repo models.Repo, pull *githu
}

}
} else {
return false, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not always correct because a check can be in progress but it may as well be not set as required, in which case PR will still be mergeable.

Copy link
Member

Choose a reason for hiding this comment

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

This is checked prior to the function call here:

state := githubPR.GetMergeableState()
// We map our mergeable check to when the GitHub merge button is clickable.
// This corresponds to the following states:
// clean: No conflicts, all requirements satisfied.
// Merging is allowed (green box).
// unstable: Failing/pending commit status that is not part of the required
// status checks. Merging is allowed (yellow box).
// has_hooks: GitHub Enterprise only, if a repo has custom pre-receive
// hooks. Merging is allowed (green box).
// See: https://github.com/octokit/octokit.net/issues/1763
if state != "clean" && state != "unstable" && state != "has_hooks" {
//mergeable bypass apply code hidden by feature flag
if g.config.AllowMergeableBypassApply {
g.logger.Debug("AllowMergeableBypassApply feature flag is enabled - attempting to bypass apply from mergeable requirements")
if state == "blocked" {
//check status excluding atlantis apply
status, err := g.GetCombinedStatusMinusApply(repo, githubPR, vcsstatusname)
if err != nil {
return false, errors.Wrap(err, "getting pull request status")
}
//check to see if pr is approved using reviewDecision
approved, err := g.GetPullReviewDecision(repo, pull)
if err != nil {
return false, errors.Wrap(err, "getting pull request reviewDecision")
}
//if all other status checks EXCEPT atlantis/apply are successful, and the PR is approved based on reviewDecision, let it proceed
if status && approved {
return true, nil
}
}
}
return false, nil
}
return true, nil
}

The state you are referring to is considered "unstable"

Copy link

@bhavith bhavith Dec 15, 2023

Choose a reason for hiding this comment

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

I think @stasostrovskyi is right here. Assume atlantis/apply is pending and one another check which is not a required one is also pending. So the status will not be unstable and will go on to the function GetCombinedStatusMinusApply since AllowMergeableBypassApply is enabled.

There the changes that are done in this PR will come into picture. Here it will fail the check if *c.Status == "completed" and proceed to to return return false, nil, even before checking if the status check is failing due to a required check or not.

I think we might have to go further if *c.Status != "completed" and then check if the checkrun is a required one or not.

Does that make sense?

Copy link
Contributor

@stasostrovskyi stasostrovskyi Dec 20, 2023

Choose a reason for hiding this comment

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

For me it finally makes sense with the issue you've discovered and fixing in #3916

@jamengual jamengual added needs discussion Large change that needs review from community/maintainers provider/gitlab labels Oct 6, 2023
Copy link
Member

@GenPage GenPage left a comment

Choose a reason for hiding this comment

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

Can we update the tests? I think they start around here:

func TestGithubClient_PullIsMergeableWithAllowMergeableBypassApply(t *testing.T) {

@GenPage GenPage added waiting-on-response Waiting for a response from the user needs tests Change requires tests and removed needs discussion Large change that needs review from community/maintainers provider/gitlab labels Oct 6, 2023
@GenPage
Copy link
Member

GenPage commented Oct 6, 2023

Might help to review #2436 as a reference for the feature.

@jamengual
Copy link
Contributor

@Yasmine92 do you have time to work on this?

@Yasmine92
Copy link
Author

@Yasmine92 do you have time to work on this?

@jamengual Unfortunately not, I apologize for not coming back to this one. I need time to understand well the logic of the github checks suite and how it's explored here.
if anyone knows how to fix it, feel free to commit changes to my branch.

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 Stale and removed Stale labels Jan 21, 2024
@GenPage
Copy link
Member

GenPage commented Jan 22, 2024

Closing in favor of #3916

@GenPage GenPage closed this Jan 22, 2024
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 needs tests Change requires tests provider/github waiting-on-response Waiting for a response from the user
Projects
None yet
5 participants