github3.py icon indicating copy to clipboard operation
github3.py copied to clipboard

Unable to set branch protections on new branches

Open tedivm opened this issue 5 years ago • 6 comments

On a branch with no protection rules enabled there is no way to get the branch protection object to enable those rules. Attempts to run the protection function result in a 404 Branch not protected error.

Version Information

Please provide:

  • The version of Python you're using

Python 3.7.4

  • The version of pip you used to install github3.py

pip 19.2.3

  • The version of github3.py, requests, uritemplate, and dateutil installed

github3.py==1.3.0 requests==2.22.0 uritemplate==3.0.0 python-dateutil==2.8.0

Minimum Reproducible Example

branch = github.repository('gitconsensus', '.github').branch('master')
branch.protection()

Exception information

  File "./githuborganizer/cli.py", line 145, in get_branch_protection
    print(branch.protection())
  File "/Users/robert/Repositories/GithubOrgSync/env/lib/python3.7/site-packages/github3/decorators.py", line 31, in auth_wrapper
    return func(self, *args, **kwargs)
  File "/Users/robert/Repositories/GithubOrgSync/env/lib/python3.7/site-packages/github3/repos/branch.py", line 73, in protection
    json = self._json(resp, 200)
  File "/Users/robert/Repositories/GithubOrgSync/env/lib/python3.7/site-packages/github3/models.py", line 156, in _json
    raise exceptions.error_for(response)
github3.exceptions.NotFoundError: 404 Branch not protected

tedivm avatar Sep 30 '19 05:09 tedivm

Huh, that's interesting. Though maybe I'm mis-reading the API. It seems that you want to call branch.protect(), which is here in the code.

What happens if you first protect it this way?

omgjlk avatar Sep 30 '19 17:09 omgjlk

Unfortunately that also gives an error (regardless of the arguments passed)-

  File "./githuborganizer/cli.py", line 150, in test
    branch.protect()
  File "/Users/robert/Repositories/GithubOrgSync/env/lib/python3.7/site-packages/github3/decorators.py", line 31, in auth_wrapper
    return func(self, *args, **kwargs)
  File "/Users/robert/Repositories/GithubOrgSync/env/lib/python3.7/site-packages/github3/repos/branch.py", line 116, in protect
    json = self._json(resp, 200)
  File "/Users/robert/Repositories/GithubOrgSync/env/lib/python3.7/site-packages/github3/models.py", line 156, in _json
    raise exceptions.error_for(response)
github3.exceptions.NotFoundError: 404 Not Found

tedivm avatar Sep 30 '19 20:09 tedivm

I did manage a workaround by creating my own function that makes the request against the API, so this isn't blocking me on anything- that being said I'm happy to continue helping debugging, as I'm sure others will run into this too.

tedivm avatar Sep 30 '19 20:09 tedivm

It looks like there's another open issue for the protect 404 error- #892

tedivm avatar Sep 30 '19 20:09 tedivm

Thanks. I'll sort out trying to get that going soon.

omgjlk avatar Sep 30 '19 21:09 omgjlk

Hi ! Any ETA on this?

YGwen avatar Nov 13 '19 17:11 YGwen