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

Certain merges can lead to ignored commits during evaluation #647

Open
bluekeyes opened this issue Oct 20, 2023 · 0 comments
Open

Certain merges can lead to ignored commits during evaluation #647

bluekeyes opened this issue Oct 20, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@bluekeyes
Copy link
Member

We recently found an internal PR where someone had effectively merged a branch with itself. When processing approvals for the PR, the sortCommits function

func sortCommits(commits []*pull.Commit, head string) []*pull.Commit {
commitsBySHA := make(map[string]*pull.Commit)
for _, c := range commits {
commitsBySHA[c.SHA] = c
}
ordered := make([]*pull.Commit, 0, len(commits))
for {
c, ok := commitsBySHA[head]
if !ok {
break
}
ordered = append(ordered, c)
if len(c.Parents) == 0 {
break
}
head = c.Parents[0]
}
return ordered
}

orders commits by their parents, only using the first parent of each commit. Any commits not in that first parent chain are discarded from the result. This works if the second parent is always another branch, but if both parents are present on the PR branch, only exploring the first path can discard commits.

The result was that a user who should have been a contributor was able to approve the PR, because their commits were only reachable through the second parent of a merge commit.

I think we need to update sortCommits to make sure the result always contains every commit in the input. However, I'm not sure yet how to order commits in this situation (e.g. should we evaluate parents depth-first or breadth-first?). This sorting function was introduced as part of #602, so we'll need to make sure than any ordering is valid for the invalidate_on_push option.

@bluekeyes bluekeyes added the bug Something isn't working label Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant