Use merge-base in pull requests to determine the common ancestor #95
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
GopherCI generates its own diffs, not using GitHubs, for the main
reason that GitHub did not have a uniform way to fetch diffs and
we would like to support other platforms (GitLab) potentially later.
So whilst we could generate a diff perfectly fine, we kept doing so.
It's become apparent that we're not generating the diffs correctly
at all. We're creating a diff between HEAD of the PR and the latest
commit in the base branch, this isn't what GitHub is doing, so when
we post a comment to a particular line, the line numbers could be
wrong.
Initially it was thought we could just create a diff interface,
passing this into the Analyser, and never generating the diffs
ourselves, but apicompat needs to know the exact base ref. Previously
it was using FETCH_HEAD, as was git diff.
So, instead of using GitHub's diffs, we'd learn how to accurately
generate a diff by knowing the exact point where the branch for the
PR was created. We'd then pass this to apicompat as well.
To do this, we'll create a refReader interface, because a push already
knows the base ref, but a pull request does not. When invoking the
Analyse method, the caller will determine whether it should use
one of two new types implementing refReader.
A push will use a hard coded base ref that it obtains from the API
and a pull request will use git merge-tool to compare the two branches
FETCH_HEAD and HEAD to find the common ancestor.
Git diff and apicompat will then use the result of refReader.
In doing this, it requires the pull request cloner to clone a much
larger history, to ensure it captures enough history to find the
last common commit. This might be able to be optimised at a later
stage if it could know how many commits are in the pull request.
Fixes #84.