0

I've been playing around with the Github API to not allow pull requests to merge if commit status are marked as failure.

I'm running into this issue that say if I have 5 commits (most recent - lease)

  • commit1: status-failure
  • commit2: status-failure
  • commit3: status-failure
  • commit4: status-failure
  • commit5: status-success

The merge is allowed as long as the most recent PR commit has a 'success' status when it shouldn't be.

Any combination of failures/success will not allow the merge AS LONG AS the most recent commit is also a failure.

James
  • 21
  • 1
  • What do you mean with `The merge is allowed as long as the most recent PR commit has a 'success' status when it shouldn't be.`? If the last commit is OK, why then is a merge not allowed? – Julian Jun 26 '19 at 20:18
  • For a GH app project I'm working on I was hoping to be able to only allow the merge if every commit met a certain criteria. – James Jun 29 '19 at 20:54
  • Isn't squashing the PR an option (when accepted). Supported by GitHub nowadays – Julian Jun 29 '19 at 21:27

1 Answers1

0

Most CI systems adopt the approach that they are testing the pull request as a whole, and that as long as the pull request as it stands now works (i.e., is passing) then the pull request is acceptable.

However, there are projects like Git where every commit must pass the tests independently to allow for bisectability. If your project is one of those, then you need to explicitly configure your CI system to test every commit in a branch. Most systems allow you to query the base or destination branch and you can then invoke git rebase -x "BUILD-AND-RUN-COMMAND" $BASE_BRANCH (with $BASE_BRANCH set according to your CI system) to verify that each commit passes independently.

Edit: If you're trying to implement a system where each commit must pass, simply find the base branch that you get from GitHub and apply your checks to each commit, and then report back success if and only if all the commits in the PR pass. That's most consistent with the way that GitHub reports status, and it's also consistent with the merge checks that GitHub provides.

bk2204
  • 64,793
  • 6
  • 84
  • 100
  • I'm currently trying to build a GH app that only allows a merge once all commits of a PR pass my checks. I know its a really dumb way to do it right now but currently I just have my app (once a PR webhook is received) mark every commit status as failure, parse and check if all commits meet my criteria, and if they all do I parse all PR commits and set their status to success. – James Jun 29 '19 at 20:56
  • I've updated the answer to hopefully address this question better. – bk2204 Jun 30 '19 at 14:37