Search code examples
jenkinsgithubgithub-api

How to update build status for PR merge commit


We can use this command to update the build status for a commit:

curl "https://api.github.com/repos/chnlmeter/$repo_name/statuses/$GIT_COMMIT?access_token=$github_build_status_token" \
  -H "Content-Type: application/json" \
  -X POST \
  -d "$(cat <<EOF
{"state": "success","context": "continuous-integration/jenkins", "description": "Jenkins", "target_url": "$BUILD_URL"}
EOF
)"

my question is - I want to create a temporary merge commit between the integration branch and feature branch and then test that commit - after a merge takes place, not before. Is there a way for github to create that merge commit and then notify jenkins of that commit? And then I want to update the build status for that commit so it shows up on the pull request page on Github.

enter image description here

The above image will show up on the PR page, but it only pertains to the feature branch commit, not a merge commit which would result of the actual merge of the two branches.


Solution

  • Assuming the PR is mergeable, you can fetch the reference refs/pull/NUM/merge, where NUM is the PR number, which should contain a merge of the branch in the PR and the base branch. That should be available either immediately as the PR is opened or shortly thereafter.

    Once you've tested that, you can just create another status if you want. It may be useful to create an in-progress status first in order to prevent people from merging without running both sets of tests first.