0

I'm currently running the following python script. The intention is to be able to automatically create a PR.

if new_repo != None: #if there are files within the repo
     current = new_repo.create_head(new_branch)
     new_repo.git.checkout(current)
     new_repo.git.rm('file.yml') #remove the file
     print("deleting file")
     new_repo.git.commit("-m",'deleting file') #apply a commit message
     print("changes are being commited")
     new_repo.git.push('--set-upstream', new_repo.remote().name, new_branch) #set an upstream for the branch to remote
     print("changes are being pushed")
     new_repo.create_pull(title="deleting file", body="just a line to test", head=new_branch, base="master")
     

The code is working up until I try to create a PR. I end up with the following error:

AttributeError: 'Repo' object has no attribute 'create_pull'

Currently I am using python3 and it's version is Python 3.8.2. I'm unsure about the version on pygithub. I know I have installed it because when I run pip3 install pygithub I get the following output:

Requirement already satisfied: pygithub in /usr/local/lib/python3.9/site-packages (1.55) Requirement already satisfied: requests>=2.14.0 in /usr/local/lib/python3.9/site-packages (from pygithub) (2.25.1) Requirement already satisfied: pynacl>=1.4.0 in /usr/local/lib/python3.9/site-packages (from pygithub) (1.4.0) Requirement already satisfied: deprecated in /usr/local/lib/python3.9/site-packages (from pygithub) (1.2.12) Requirement already satisfied: pyjwt>=2.0 in /usr/local/lib/python3.9/site-packages (from pygithub) (2.1.0) Requirement already satisfied: cffi>=1.4.1 in /usr/local/lib/python3.9/site-packages (from pynacl>=1.4.0->pygithub) (1.14.4) Requirement already satisfied: six in /usr/local/lib/python3.9/site-packages (from pynacl>=1.4.0->pygithub) (1.15.0) Requirement already satisfied: pycparser in /usr/local/lib/python3.9/site-packages (from cffi>=1.4.1->pynacl>=1.4.0->pygithub) (2.20) Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.9/site-packages (from requests>=2.14.0->pygithub) (2021.5.30) Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.9/site-packages (from requests>=2.14.0->pygithub) (1.26.6) Requirement already satisfied: chardet<5,>=3.0.2 in /usr/local/lib/python3.9/site-packages (from requests>=2.14.0->pygithub) (4.0.0) Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.9/site-packages (from requests>=2.14.0->pygithub) (2.10) Requirement already satisfied: wrapt<2,>=1.10 in ./Library/Python/3.9/lib/python/site-packages (from deprecated->pygithub) (1.12.1)

Is there something that I am missing with my troubleshooting? Is the code incorrect? As far as I know, I've been looking at the following SO postand this PyGithub post.

Could someone help me out? If someone could provide an explanation as well that'll be amazing.

Thanks!

hachemon
  • 158
  • 8
  • PyGithub doesn’t list any class named `Repo` in its [reference materials](https://pygithub.readthedocs.io/en/latest/github_objects.html), which it seems `new_repo` is an instance of. Another library, `GitPython` *does* seem to implement this [`Repo` class](https://gitpython.readthedocs.io/en/stable/tutorial.html). Can you ensure you’re not mixing the use of the two? The attributes, method signatures, etc. will not be the same between the two libraries, and you’ll need reference material *specific* to the library you’ve chosen. – esqew Jul 13 '21 at 19:59
  • @esqew Oh that makes sense. I'm rather new at programming in general. In this case I guess I can avoid using the Repo class with create_pull(). But if I were to do that, how would I be able to programmatically create a PR? The documentation doesn't have a clear example. Maybe you might be able to shed some light here? – hachemon Jul 13 '21 at 20:24
  • I’ve never used either library and can’t really help you there. It’s entirely possible that the library you seem to be using doesn’t support such a transaction, but you’ll need to read & understand the reference material/documentation for the library you’ve chosen to make an affirmative determination. – esqew Jul 13 '21 at 20:35

0 Answers0