Checkout merged code for pull requests

github

#1

Before getting into the feature request, consider the purpose and bigger picture for pull request builds.

  1. A contributor submits a pull request.
  2. An owner needs to review the code changes before merging the pull request.
  3. Part of the owner’s criteria for merging the pull request is seeing the circleci build status go green. This status implies “safe to merge”.

When CircleCI runs a pull request build, it simply pulls the code from the pull request source branch. It does not merge with the target branch. This means that the built code, and therefore the status, does not necessarily apply to whether or not the pull request is “safe to merge”.

Allow me to try to illustrate a scenario:

  • Tuesday: User A pulls code locally. He changes a function signature and updates all usages.
  • Wednesday: User B pushes code that adds a new usage of this function.
  • Thursday: User A submits a pull request with his refactor.
    • Note that User A never rebased his change to pick up User B’s new code.
    • The CircleCI build passes, because it only pulled the PR source branch.
    • The owner merges the PR, and the upstream build fails, because User A’s and User B’s changes are functionally incompatible.

The scenario would be solved if CircleCI would automatically merge the source branch with the target branch during the “checkout” phase of the build.


#2

This may be related to Python build for Pull request fails but after merging succeeds


#3

Are there any thoughts on this from the CircleCI team?


#4

I’d love to see some support for this. I’ve previously used TeamCity, and it had this functionality.

GitHub updates read-only refs in git that makes it possible to checkout merged code. I’ve in my local git config:

[remote “origin”]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@github.com:xxx/xxx.git
fetch = +refs/pull/*/merge:refs/remotes/origin/pr-merged/*

Then I can simply git checkout pr-merged/<number> to see what the codebase looks after the merge. Now CircleCi just simply needs to checkout that and make build out of it.

I don’t know what Github does with merge conflicts, need to find out that.


#5