gitgithubpygithub

How to enable Require status checks to pass before merging through automation


I was reading over PyGitHub's documentation in: https://pygithub.readthedocs.io/en/latest/github_objects/Branch.html and found some interesting methods that I thought might help

First I made sure that Required status checks to pass before merging was not enabled. Then in my python file I had

branch.edit_required_status_checks(strict=True, contexts=["action-runner"])

When I ran the code it gives me the following error github.GithubException.GithubException: 404 {"message": "Required status checks not enabled", "documentation_url": "https://docs.github.com/enterprise-server@3.7/rest/reference/repos#get-status-checks-protection"}

Based on the error, I went on Github and renabled the require status checks to pass before merging. When I reran the code I saw that it worked because now on Github I see that my GitHub Actions actions-runner was enabled. When I change the value of strict from True to False and ran my code, it unchecks Require branches to be up to date before merging.

This means I can't call edit_required_status_checks() unless I have Required status checks to pass before merging enabled. This is the same situation if I try using get_required_status_checks().

However I can use remove_required_status_checks() to uncheck Require status checks to pass before merging yet I can't find a method that will do it the other way around for enabling.


Solution

  • Calling branch.edit_protection(strict=True) will toggle on Require status checks to pass before merging , which will then allow for edit_required_status_checks() to succeed.