Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update get_committer_data for latest PyGithub #410

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ install: pip install -U tox
language: python
matrix:
include:
- env: TOXENV=py39
python: 3.9.1
- env: TOXENV=py38
python: 3.8.2
- env: TOXENV=py37
python: 3.7.7
- env: TOXENV=py36
python: 3.6.10
- env: TOXENV=py35
python: 3.5.9
script: tox
4 changes: 2 additions & 2 deletions pyup/providers/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ def get_committer_data(self, committer):
email = committer.email
else:
for item in committer.get_emails():
if item["primary"]:
email = item["email"]
if item.primary:
email = item.email
if email is None:
msg = "Unable to get {login}'s email adress. " \
"You may have to add the scope user:email".format(login=committer.login)
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

requirements = [
"requests",
"pygithub>=1.43.3",
"pygithub>=1.55",
"click",
"tqdm",
"pyyaml>=4.2b4",
Expand Down Expand Up @@ -54,13 +54,13 @@
'Natural Language :: English',
"Programming Language :: Python",
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: Implementation :: CPython',
],
python_requires=">=3.5",
python_requires=">=3.6",
entry_points={
'console_scripts': [
'pyup = pyup.cli:main',
Expand Down
32 changes: 17 additions & 15 deletions tests/test_github.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals

from collections import namedtuple
from unittest import TestCase
from pyup.providers.github import Provider
from pyup.requirements import RequirementsBundle
Expand Down Expand Up @@ -70,7 +72,7 @@ def test_get_default_branch(self):
"foo"
)

p = PropertyMock(side_effect=UnknownObjectException(data="", status=1))
p = PropertyMock(side_effect=UnknownObjectException(data="", status=1, headers={}))
type(self.repo).default_branch = p
with self.assertRaises(errors.RepoDoesNotExistError):
self.provider.get_default_branch(self.repo)
Expand All @@ -81,7 +83,7 @@ def test_get_pull_request_permissions(self):
self.provider.get_pull_request_permissions(user, self.repo)
self.repo.add_to_collaborators.assert_called_once_with("some-dude")

self.repo.add_to_collaborators.side_effect = GithubException(data="", status=1)
self.repo.add_to_collaborators.side_effect = GithubException(data="", status=1, headers={})
with self.assertRaises(errors.NoPermissionError):
self.provider.get_pull_request_permissions(user, self.repo)

Expand All @@ -91,7 +93,7 @@ def test_iter_git_tree(self):
items = list(self.provider.iter_git_tree(self.repo, "some branch"))
self.assertEqual(items, [("type", "path")])

self.repo.get_git_tree.side_effect = GithubException(data="", status=999)
self.repo.get_git_tree.side_effect = GithubException(data="", status=999, headers={})
with self.assertRaises(GithubException):
list(self.provider.iter_git_tree(self.repo, "some branch"))

Expand All @@ -101,7 +103,7 @@ def test_get_file(self):
self.assertIsNotNone(obj)
self.repo.get_contents.assert_called_with("path", ref="branch")

self.repo.get_contents.side_effect = GithubException(data="", status=1)
self.repo.get_contents.side_effect = GithubException(data="", status=1, headers={})
content, obj = self.provider.get_file(self.repo, "path", "branch")
self.assertIsNone(content)
self.assertIsNone(obj)
Expand All @@ -127,7 +129,7 @@ def test_create_branch(self):
self.provider.create_branch(self.repo, "base branch", "new branch")
self.repo.get_git_ref.assert_called_once_with("heads/base branch")

self.repo.get_git_ref.side_effect = GithubException(data="", status=1)
self.repo.get_git_ref.side_effect = GithubException(data="", status=1, headers={})
with self.assertRaises(errors.BranchExistsError):
self.provider.create_branch(self.repo, "base branch", "new branch")

Expand Down Expand Up @@ -167,7 +169,7 @@ def test_create_commit(self, time):
self.provider.create_commit("path", "branch", "commit", "content", "sha", self.repo, "com")
self.assertEqual(self.repo.update_file.call_count, 1)

self.repo.update_file.side_effect = GithubException(data="", status=1)
self.repo.update_file.side_effect = GithubException(data="", status=1, headers={})
with self.assertRaises(GithubException):
self.provider.create_commit("path", "branch", "commit", "content", "sha", self.repo,
"com")
Expand Down Expand Up @@ -211,7 +213,7 @@ def test_get_committer_data(self):
committer = Mock()
committer.email = None
committer.login = "foo"
committer.get_emails.return_value = [{"primary": True, "email": "[email protected]"},]
committer.get_emails.return_value = [namedtuple("EmailData", ["primary", "email"])(True, "[email protected]")]
data = self.provider.get_committer_data(committer)._identity
self.assertEqual(data["name"], "foo")
self.assertEqual(data["email"], "[email protected]")
Expand All @@ -231,7 +233,7 @@ def test_get_pull_request_committer(self):
data = self.provider.get_pull_request_committer(self.repo, pr)
self.assertEqual(data, ["foo"])

self.repo.get_pull.side_effect = UnknownObjectException(data="", status=1)
self.repo.get_pull.side_effect = UnknownObjectException(data="", status=1, headers={})
data = self.provider.get_pull_request_committer(self.repo, pr)
self.assertEqual(data, [])

Expand All @@ -247,7 +249,7 @@ def test_close_pull_request(self):
self.provider.close_pull_request(self.repo, self.repo, pr, "comment", prefix="pyup-")
self.assertEqual(self.repo.get_git_ref().delete.call_count, 1)

self.repo.get_pull.side_effect = UnknownObjectException(data="", status=1)
self.repo.get_pull.side_effect = UnknownObjectException(data="", status=1, headers={})
data = self.provider.close_pull_request(self.repo, self.repo, Mock(), "comment",
prefix="pyup-")
self.assertEqual(data, False)
Expand All @@ -263,7 +265,7 @@ def test_create_pull_request(self):
self.assertEqual(self.provider.bundle.get_pull_request_class.call_count, 1)
self.assertEqual(self.provider.bundle.get_pull_request_class().call_count, 1)

self.repo.create_pull.side_effect = GithubException(data="", status=1)
self.repo.create_pull.side_effect = GithubException(data="", status=1, headers={})
with self.assertRaises(errors.NoPermissionError):
self.provider.create_pull_request(self.repo, "title", "body", "master", "new", False, [])

Expand All @@ -283,10 +285,10 @@ def test_create_pull_request_with_assignees(self):
def test_create_issue(self):
self.assertIsNot(self.provider.create_issue(self.repo, "title", "body"), False)

self.repo.create_issue.side_effect = GithubException(data="", status=404)
self.repo.create_issue.side_effect = GithubException(data="", status=404, headers={})
self.assertEqual(self.provider.create_issue(self.repo, "title", "body"), False)

self.repo.create_issue.side_effect = GithubException(data="", status=999)
self.repo.create_issue.side_effect = GithubException(data="", status=999, headers={})
with self.assertRaises(GithubException):
self.assertEqual(self.provider.create_issue(self.repo, "title", "body"), False)

Expand All @@ -302,15 +304,15 @@ def test_get_or_create_label(self):

def test_create_label(self):
# label does not exist, need to create it
self.repo.get_label.side_effect = UnknownObjectException(None, None)
self.repo.get_label.side_effect = UnknownObjectException(None, None, headers={})
self.provider.get_or_create_label(self.repo, "another-label")
self.repo.get_label.assert_called_once_with(name="another-label")
self.repo.create_label.assert_called_once_with(name="another-label", color="1BB0CE")

def test_create_label_fails(self):
# label does not exist, need to create it
self.repo.get_label.side_effect = UnknownObjectException(None, None)
self.repo.create_label.side_effect = GithubException(None, None)
self.repo.get_label.side_effect = UnknownObjectException(None, None, headers={})
self.repo.create_label.side_effect = GithubException(None, None, headers={})
label = self.provider.get_or_create_label(self.repo, "another-label")
self.assertIsNone(label)
self.repo.get_label.assert_called_once_with(name="another-label")
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py35, py36, py37, py38
envlist = py36, py37, py38, py39

[testenv]
setenv =
Expand Down