internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: PyGithub/PyGithub

Issue:
MainGithub  get_organizations unexpected return type
Hello. I have started writting a Git interaction tool for my current workplace. We have our own instance of GHE and organise everything into orgs. I have started used PyGithub, currently using v1.43.7, which should be the latest one.

Apologies if this has been asked before, I did have a look and could find nothing of the sort.

The `get_organizations` pydoc on the `MainClass.Github` seems to suggest that the returned type for `get_organizations` is a `PaginatedList` of `Organizations`, as can be seen at the following URL: 
[get_organizations docs](https://pygithub.readthedocs.io/en/latest/github.html#github.MainClass.Github.get_organizations)

However, a successful call to `get_organizations` seems to return a `PaginatedList` of `NamedUser`, where each `NamedUser` is actually a git org (so it goes off and finds the right things on GHE, but returns the wrong type).

A quick fix to get the right type is to do something like this:

```py
named_users = git.get_organizations()
for named_user in named_users:
	actual_org = git.get_organization(named_user.login)
```

That is not in line with the documentation though, so I am wondering whether I am doing something wrong, or if this is the intended behaviour.

Kind regards,
Dragos


Discussion:

Resolving patch:
diff --git a/github/MainClass.py b/github/MainClass.py
--- a/github/MainClass.py
+++ b/github/MainClass.py
@@ -273,7 +273,7 @@ def get_organizations(self, since=github.GithubObject.NotSet):
         if since is not github.GithubObject.NotSet:
             url_parameters["since"] = since
         return github.PaginatedList.PaginatedList(
-            github.NamedUser.NamedUser,
+            github.Organization.Organization,
             self.__requester,
             "/organizations",
             url_parameters


Test patch:
Repository: PyGithub/PyGithub

Issue:
`update_file` says to base64 encode your input, but that's not necessary
https://github.com/PyGithub/PyGithub/blob/118def30a3ee69e203113cc64dceea27ece12e13/github/Repository.py#L1666

This should read: "The updated file content, either Base64 encoded or ready to be encoded".


Discussion:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Not stale.  Stop it.

Resolving patch:
diff --git a/github/Repository.py b/github/Repository.py
--- a/github/Repository.py
+++ b/github/Repository.py
@@ -1681,7 +1681,7 @@ def update_file(self, path, message, content, sha,
         :calls: `PUT /repos/:owner/:repo/contents/:path <http://developer.github.com/v3/repos/contents#update-a-file>`_
         :param path: string, Required. The content path.
         :param message: string, Required. The commit message.
-        :param content: string, Required. The updated file content, Base64 encoded.
+        :param content: string, Required. The updated file content, either base64 encoded, or ready to be encoded.
         :param sha: string, Required. The blob SHA of the file being replaced.
         :param branch: string. The branch name. Default: the repository’s default branch (usually master)
         :param committer: InputGitAuthor, (optional), if no information is given the authenticated user's information will be used. You must specify both a name and email.


Test patch:
Repository: PyGithub/PyGithub

Issue:
After v 1.44, TypeError: encoding or errors without a string argument
I have a job that runs regularly... it threw this error today- `TypeError: encoding or errors without a string argument`. So I pinned the version to v1.43.8 and it works fine. 
![Screen Shot 2019-10-21 at 12 46 30 PM](https://user-images.githubusercontent.com/45208412/67234786-5c305600-f40b-11e9-89d9-40cd9da0751e.png)
I wonder if anyone else has experienced the same issue.



Discussion:
I changed that code explicitly during one of my remove Python 2 only code crusades. I'll investigate.

Resolving patch:
diff --git a/github/Repository.py b/github/Repository.py
--- a/github/Repository.py
+++ b/github/Repository.py
@@ -1645,9 +1645,9 @@ def create_file(self, path, message, content,
             or isinstance(committer, github.InputGitAuthor),       \
             'committer must be a github.InputGitAuthor object'
 
-        content = b64encode(bytearray(content, 'utf-8'))
-        if isinstance(content, bytes):
-            content = content.decode('utf-8')
+        if not isinstance(content, bytes):
+            content = content.encode('utf-8')
+        content = b64encode(content).decode('utf-8')
         put_parameters = {'message': message, 'content': content}
 
         if branch is not github.GithubObject.NotSet:
@@ -1702,9 +1702,9 @@ def update_file(self, path, message, content, sha,
             or isinstance(committer, github.InputGitAuthor),       \
             'committer must be a github.InputGitAuthor object'
 
-        content = b64encode(bytearray(content, 'utf-8'))
-        if isinstance(content, bytes):
-            content = content.decode('utf-8')
+        if not isinstance(content, bytes):
+            content = content.encode('utf-8')
+        content = b64encode(content).decode('utf-8')
 
         put_parameters = {'message': message, 'content': content,
                           'sha': sha}


Test patch:
diff --git a/tests/Repository.py b/tests/Repository.py
--- a/tests/Repository.py
+++ b/tests/Repository.py
@@ -548,7 +548,7 @@ def testGetContentsWithRef(self):
 
     def testCreateFile(self):
         newFile = 'doc/testCreateUpdateDeleteFile.md'
-        content = 'Hello world'
+        content = 'Hello world'.encode()
         self.repo.create_file(
             path=newFile, message='Create file for testCreateFile', content=content,
             branch="master", committer=github.InputGitAuthor("Enix Yu", "enix223@163.com", "2016-01-15T16:13:30+12:00"),
Repository: PyGithub/PyGithub

Issue:
pr.add_to_assignees doesn't POST to the correct url
Using latest PyGithub version (`^1.44`) the POST url that gets used when doing:
```py
github.get_repo('repo_name').get_pulls()[0].add_to_assignees('pgilad')
```

is `POST /repos/:owner/:repo/pulls/:number/assignees` instead of `POST /repos/:owner/:repo/issues/:number/assignees` which ends up with Github responding with 404

A possible temp workaround is to do `.as_issue().add_to_assignees('pgilad')` but then the documentation is wrong and needs to be updated. This should be incorporated into both `pr.add_to_assignees` and `pr.remove_from_assignees`


Discussion:

Resolving patch:
diff --git a/github/PullRequest.py b/github/PullRequest.py
--- a/github/PullRequest.py
+++ b/github/PullRequest.py
@@ -804,7 +804,7 @@ def add_to_assignees(self, *assignees):
         post_parameters = {"assignees": [assignee.login if isinstance(assignee, github.NamedUser.NamedUser) else assignee for assignee in assignees]}
         headers, data = self._requester.requestJsonAndCheck(
             "POST",
-            self.url + "/assignees",
+            self.issue_url + "/assignees",
             input=post_parameters
         )
         self._useAttributes(data)
@@ -819,7 +819,7 @@ def remove_from_assignees(self, *assignees):
         post_parameters = {"assignees": [assignee.login if isinstance(assignee, github.NamedUser.NamedUser) else assignee for assignee in assignees]}
         headers, data = self._requester.requestJsonAndCheck(
             "DELETE",
-            self.url + "/assignees",
+            self.issue_url + "/assignees",
             input=post_parameters
         )
         self._useAttributes(data)


Test patch:
diff --git a/tests/ReplayData/PullRequest.testAddAndRemoveAssignees.txt b/tests/ReplayData/PullRequest.testAddAndRemoveAssignees.txt
--- a/tests/ReplayData/PullRequest.testAddAndRemoveAssignees.txt
+++ b/tests/ReplayData/PullRequest.testAddAndRemoveAssignees.txt
@@ -13,7 +13,7 @@ https
 POST
 api.github.com
 None
-/repos/jacquev6/PyGithub/pulls/31/assignees
+/repos/jacquev6/PyGithub/issues/31/assignees
 {'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
 {"assignees":["jayfk","jzelinskie"]}
 201
@@ -24,7 +24,7 @@ https
 DELETE
 api.github.com
 None
-/repos/jacquev6/PyGithub/pulls/31/assignees
+/repos/jacquev6/PyGithub/issues/31/assignees
 {'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
 {"assignees":["jayfk","jzelinskie"]}
 200
Repository: PyGithub/PyGithub

Issue:
Creating a project without body argument leads to exception
Hi guys,

According to [documentation](https://pygithub.readthedocs.io/en/latest/github_objects/Repository.html#github.Repository.Repository.create_project) one can create project w/o body. However when I'm trying to do it I'm getting a `TypeError: Object of type _NotSetType is not JSON serializable`.

### Steps to reproduce

Run `poc.py` with your Personal Access Token as a first parameter:

```
$ cat poc.py
import sys
from github import Github
Github(sys.argv[1]).get_user().create_repo("bug").create_project("here")
$ pipenv run python3 -m pdb poc.py TOKEN
...
TypeError: Object of type _NotSetType is not JSON serializable
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
```

### Root cause analysis

The root cause seems to be that unspecified `body` has the value `NotSet`. In pdb:

```
...
TypeError: Object of type _NotSetType is not JSON serializable
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> /usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py(179)default()
-> raise TypeError(f'Object of type {o.__class__.__name__} '
(Pdb) u
> /usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py(257)iterencode()
-> return _iterencode(o, 0)
(Pdb) p o
{'name': 'here', 'body': NotSet}
```

After I've changed the `body` to `""` project was created successfully.

### Software versions

Python 3.7.6 (default, Dec 30 2019, 19:38:26) 
[Clang 11.0.0 (clang-1100.0.33.16)] on darwin


Discussion:

Resolving patch:
diff --git a/github/Repository.py b/github/Repository.py
--- a/github/Repository.py
+++ b/github/Repository.py
@@ -1262,15 +1262,15 @@ def create_milestone(
 
     def create_project(self, name, body=github.GithubObject.NotSet):
         """
-        calls: `POST /repos/:owner/:repo/projects <https://developer.github.com/v3/projects/#create-a-repository-project>`_
+        :calls: `POST /repos/:owner/:repo/projects <https://developer.github.com/v3/projects/#create-a-repository-project>`_
         :param name: string
         :param body: string
+        :rtype: :class:`github.Project.Project`
         """
         assert isinstance(name, str), name
         assert body is github.GithubObject.NotSet or isinstance(body, str), body
         post_parameters = {
             "name": name,
-            "body": body,
         }
         import_header = {"Accept": Consts.mediaTypeProjectsPreview}
         if body is not github.GithubObject.NotSet:


Test patch:
Repository: PyGithub/PyGithub

Issue:
No reference docs for create_git_tag_and_release
The docs for a [Repository](https://pygithub.readthedocs.io/en/latest/github_objects/Repository.html#github.Repository.Repository.create_git_release) doesn't have any mention of `create_git_tag_and_release()`




Discussion:
The function doesn't have a docstring. I'll put together a PR soon-ish.

Resolving patch:
diff --git a/github/Repository.py b/github/Repository.py
--- a/github/Repository.py
+++ b/github/Repository.py
@@ -961,6 +961,10 @@ def create_git_tag_and_release(
         draft=False,
         prerelease=False,
     ):
+        """
+        Convenience function that calls :meth:`Repository.create_git_tag` and
+        :meth:`Repository.create_git_release`.
+        """
         self.create_git_tag(tag, tag_message, object, type, tagger)
         return self.create_git_release(
             tag,


Test patch:
Repository: PyGithub/PyGithub

Issue:
The documentation implies that PaginatedList has __len__, but it doesn't.
https://github.com/PyGithub/PyGithub/blob/393bd21bd168769d8ecf4b23f4b32e9a4de5f17a/github/PaginatedList.py#L107

In REPL:

```python
>>> print(len(g.search_code(query="filename:vimrc")))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: object of type 'PaginatedList' has no len()
```

8ae2bcb implemented `__len__` and mentioned it in the `__doc__`. 8a589c9 removed `__len__` implementation but left `__doc__` as is. Related #579.


Discussion:

Resolving patch:
diff --git a/github/PaginatedList.py b/github/PaginatedList.py
--- a/github/PaginatedList.py
+++ b/github/PaginatedList.py
@@ -104,7 +104,6 @@ class PaginatedList(PaginatedListBase):
     If you want to know the total number of items in the list::
 
         print(user.get_repos().totalCount)
-        print(len(user.get_repos()))
 
     You can also index them or take slices::
 


Test patch:
Repository: PyGithub/PyGithub

Issue:
Repository.topics does not match Repository.get_topics()
For a repository with topics, `Repository.topics` is returning `None` whereas `Repository.get_topics()` properly returns a list of string (my topics). The latter is correct.

This occurred for a private org repo.

```
Python Version: 3.7.4
      PyGithub: 1.51
```


Discussion:
I suspect topics is no longer populated because it isn't being sent by GitHub. I'll push up a PR to remove it.

Resolving patch:
diff --git a/github/Repository.py b/github/Repository.py
--- a/github/Repository.py
+++ b/github/Repository.py
@@ -758,14 +758,6 @@ def teams_url(self):
         self._completeIfNotSet(self._teams_url)
         return self._teams_url.value
 
-    @property
-    def topics(self):
-        """
-        :type: list of strings
-        """
-        self._completeIfNotSet(self._topics)
-        return self._topics.value
-
     @property
     def trees_url(self):
         """
@@ -3412,7 +3404,6 @@ def _initAttributes(self):
         self._svn_url = github.GithubObject.NotSet
         self._tags_url = github.GithubObject.NotSet
         self._teams_url = github.GithubObject.NotSet
-        self._topics = github.GithubObject.NotSet
         self._trees_url = github.GithubObject.NotSet
         self._updated_at = github.GithubObject.NotSet
         self._url = github.GithubObject.NotSet
@@ -3618,8 +3609,6 @@ def _useAttributes(self, attributes):
             self._teams_url = self._makeStringAttribute(attributes["teams_url"])
         if "trees_url" in attributes:  # pragma no branch
             self._trees_url = self._makeStringAttribute(attributes["trees_url"])
-        if "topics" in attributes:  # pragma no branch
-            self._topics = self._makeListOfStringsAttribute(attributes["topics"])
         if "updated_at" in attributes:  # pragma no branch
             self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"])
         if "url" in attributes:  # pragma no branch


Test patch:
diff --git a/tests/Repository.py b/tests/Repository.py
--- a/tests/Repository.py
+++ b/tests/Repository.py
@@ -105,7 +105,6 @@ def testAttributes(self):
         self.assertEqual(self.repo.source, None)
         self.assertEqual(self.repo.ssh_url, "git@github.com:jacquev6/PyGithub.git")
         self.assertEqual(self.repo.svn_url, "https://github.com/jacquev6/PyGithub")
-        self.assertEqual(self.repo.topics, None)
         self.assertEqual(
             self.repo.updated_at, datetime.datetime(2012, 5, 27, 6, 55, 28)
         )
Repository: PyGithub/PyGithub

Issue:
allow PyJWT 2+
other libraries are moving to PyJWT2+ as requirement, is it possible to update pygithub as well? currently we can't use for example pygithub together with django-social-core



Discussion:
It's on my list, just a lack of free time to tackle it. :-(
I'm looking forward to see support for PyJWT > 2. The NixOS package will break if we update PyJWT and this will happen.

Thanks
Any progress?

It's blocking the PyJWT package update on NixOS. I guess that it affecting other distributions as well.
What breaking changes does PyJWT>2 introduce?
https://github.com/PyGithub/PyGithub/issues/1796 is what caused me to pin it, I just haven't time to dig into it
@s-t-e-v-e-n-k the issues mentioned there are related to Python 3.5 specifically. I'm assuming these syntax errors occur due to syntax changes with Python 3.6. Which makes sense considering the drop of Python 3.5 support.

Isn't the current version of PyGithub dropping Python 3.5 support as well? That was mentioned in the latest release.
The current version has dropped support for 3.5, yes. I'll propose a PR to drop the pin soon.

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -105,7 +105,7 @@
         python_requires=">=3.6",
         install_requires=[
             "deprecated",
-            "pyjwt<2.0",
+            "pyjwt>=2.0",
             "pynacl>=1.4.0",
             "requests>=2.14.0",
         ],


Test patch:
diff --git a/tests/GitRelease.py b/tests/GitRelease.py
--- a/tests/GitRelease.py
+++ b/tests/GitRelease.py
@@ -206,7 +206,9 @@ def testUploadAsset(self):
     def testUploadAssetWithName(self):
         self.setUpNewRelease()
         release = self.new_release
-        r = release.upload_asset(self.artifact_path, name="foobar.zip")
+        r = release.upload_asset(
+            self.artifact_path, name="foobar.zip", content_type="application/zip"
+        )
         self.assertEqual(r.name, "foobar.zip")
         self.tearDownNewRelease()
Repository: PyGithub/PyGithub

Issue:
Hashable classes
Hello people!

I wonder if entities like Repository, Issue, PullRequest and etc. could be hashable in future, i.e. using them in structures like dictionary or sets would be possible?


Discussion:
Not currently planned, but an interesting idea.
Looks like there was already a PR for this, it's just been ignored for years: https://github.com/PyGithub/PyGithub/pull/531

Resolving patch:
diff --git a/github/GithubObject.py b/github/GithubObject.py
--- a/github/GithubObject.py
+++ b/github/GithubObject.py
@@ -286,6 +286,9 @@ def __init__(self, requester, headers, attributes, completed):
     def __eq__(self, other):
         return other.__class__ is self.__class__ and other._url.value == self._url.value
 
+    def __hash__(self):
+        return hash(self._url.value)
+
     def __ne__(self, other):
         return not self == other
 


Test patch:
diff --git a/tests/Equality.py b/tests/Equality.py
--- a/tests/Equality.py
+++ b/tests/Equality.py
@@ -30,16 +30,14 @@ class Equality(Framework.TestCase):
     def testUserEquality(self):
         u1 = self.g.get_user("jacquev6")
         u2 = self.g.get_user("jacquev6")
-        self.assertTrue(u1 == u2)
-        self.assertFalse(u1 != u2)
         self.assertEqual(u1, u2)
+        self.assertEqual(hash(u1), hash(u2))
 
     def testUserDifference(self):
         u1 = self.g.get_user("jacquev6")
         u2 = self.g.get_user("OddBloke")
-        self.assertFalse(u1 == u2)
-        self.assertTrue(u1 != u2)
         self.assertNotEqual(u1, u2)
+        self.assertNotEqual(hash(u1), hash(u2))
 
     def testBranchEquality(self):
         # Erf, equality of NonCompletableGithubObjects will be difficult to implement
Repository: PyGithub/PyGithub

Issue:
[CLONE] Separate request for requested reviewers
@sfdye The response of listing pull requests already contains the requested reviewers' information. However, currently, if you want to list all requested reviewers for all pull requests, you must first list all pull requests (a paginated query) and then list request reviewers one pr by another (N paginated query), while you should have implemented it with only one paginated query.

That is, you should be able to fulfill the field with:

```python
        if "requested_reviewers" in attributes:
            self._requested_reviewers = self._makeIntAttribute(
                attributes["requested_reviewers"]
            )
```

_Originally posted by @tisonkun in https://github.com/PyGithub/PyGithub/issues/679#issuecomment-1301914566_

This can be a significant performance factor.
      


Discussion:
You can search `requested_reviewers` and `requested_teams` in this page https://docs.github.com/en/rest/pulls/pulls#list-pull-requests.
I think I have a fix now. I'll send a patch for review.

Resolving patch:
diff --git a/github/PullRequest.py b/github/PullRequest.py
--- a/github/PullRequest.py
+++ b/github/PullRequest.py
@@ -53,6 +53,7 @@
 import github.PullRequestMergeStatus
 import github.PullRequestPart
 import github.PullRequestReview
+import github.Team
 
 from . import Consts
 
@@ -355,6 +356,16 @@ def updated_at(self):
         self._completeIfNotSet(self._updated_at)
         return self._updated_at.value
 
+    @property
+    def requested_reviewers(self):
+        self._completeIfNotSet(self._requested_reviewers)
+        return self._requested_reviewers.value
+
+    @property
+    def requested_teams(self):
+        self._completeIfNotSet(self._requested_teams)
+        return self._requested_teams.value
+
     @property
     def url(self):
         """
@@ -984,6 +995,8 @@ def _initAttributes(self):
         self._updated_at = github.GithubObject.NotSet
         self._url = github.GithubObject.NotSet
         self._user = github.GithubObject.NotSet
+        self._requested_reviewers = github.GithubObject.NotSet
+        self._requested_teams = github.GithubObject.NotSet
 
     def _useAttributes(self, attributes):
         if "additions" in attributes:  # pragma no branch
@@ -1101,3 +1114,11 @@ def _useAttributes(self, attributes):
             self._user = self._makeClassAttribute(
                 github.NamedUser.NamedUser, attributes["user"]
             )
+        if "requested_reviewers" in attributes:
+            self._requested_reviewers = self._makeListOfClassesAttribute(
+                github.NamedUser.NamedUser, attributes["requested_reviewers"]
+            )
+        if "requested_teams" in attributes:
+            self._requested_teams = self._makeListOfClassesAttribute(
+                github.Team.Team, attributes["requested_teams"]
+            )


Test patch: