From f5ed496d8ef4bd65f406913c48dd6532d5fa8a70 Mon Sep 17 00:00:00 2001 From: Damian Zaremba Date: Thu, 24 Jun 2021 13:16:48 +0200 Subject: [PATCH 1/2] Update get_committer_data for latest PyGithub v1.55 of PyGithub changed `get_emails` to return a named tuple (#1890) rather than a dict directly from the decoded API response. Update the code to access the fields as a property rather than by index & bump the pin so 1.55 is the minimum version. Also update the existing tests for the now required `headers` parameter on exception classes. --- pyup/providers/github.py | 4 ++-- setup.py | 2 +- tests/test_github.py | 32 +++++++++++++++++--------------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/pyup/providers/github.py b/pyup/providers/github.py index ae2e972..dff2651 100644 --- a/pyup/providers/github.py +++ b/pyup/providers/github.py @@ -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) diff --git a/setup.py b/setup.py index dd3d9fd..d2975c1 100755 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ requirements = [ "requests", - "pygithub>=1.43.3", + "pygithub>=1.55", "click", "tqdm", "pyyaml>=4.2b4", diff --git a/tests/test_github.py b/tests/test_github.py index e3f19ce..3bf033d 100644 --- a/tests/test_github.py +++ b/tests/test_github.py @@ -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 @@ -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) @@ -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) @@ -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")) @@ -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) @@ -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") @@ -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") @@ -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": "primary@bar.com"},] + committer.get_emails.return_value = [namedtuple("EmailData", ["primary", "email"])(True, "primary@bar.com")] data = self.provider.get_committer_data(committer)._identity self.assertEqual(data["name"], "foo") self.assertEqual(data["email"], "primary@bar.com") @@ -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, []) @@ -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) @@ -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, []) @@ -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) @@ -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") From 3bebe387b66a81567f9be45fa285acb07016e6db Mon Sep 17 00:00:00 2001 From: Damian Zaremba Date: Thu, 24 Jun 2021 14:03:43 +0200 Subject: [PATCH 2/2] Move minimum Python version to 3.6 Python 3.5 has been EOL since Sept 2020, 10 months ago at this point. The latest release of PyGithub does not support 3.5 (#1770), thus remove the support here also. Also add test cases for Python 3.9, which is the current stable release. --- .travis.yml | 4 ++-- setup.py | 4 ++-- tox.ini | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4a75912..7b1f728 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/setup.py b/setup.py index d2975c1..d0a653b 100755 --- a/setup.py +++ b/setup.py @@ -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', diff --git a/tox.ini b/tox.ini index 1bfa51e..3077313 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py35, py36, py37, py38 +envlist = py36, py37, py38, py39 [testenv] setenv =