From 602091fc59161ea39b223fb2bfcf74051a32e548 Mon Sep 17 00:00:00 2001 From: Jonathan Nevelson Date: Wed, 26 Aug 2020 11:19:59 -0700 Subject: [PATCH] Allow creating PR without labels (#31) --- CHANGELOG.md | 4 ++++ gordian/repo.py | 5 +++-- setup.py | 2 +- tests/test_repo.py | 11 +++++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a968483..70a479e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org). +## [3.1.0] - 2020-08-26 +### Added +- Allow `repo#create_pr` to be called without setting labels + ## [3.0.1] - 2020-07-29 ### Fixed - Fixed error handling logic when forking to retry when Github returns 404 (because that implies the repo hasn't yet finished forking) diff --git a/gordian/repo.py b/gordian/repo.py index 2029727..2cd569c 100644 --- a/gordian/repo.py +++ b/gordian/repo.py @@ -210,14 +210,15 @@ def delete_file(self, file, message, dry_run=False): branch=self.branch_name ) - def create_pr(self, pr_message, pr_body, target_branch, labels): + def create_pr(self, pr_message, pr_body, target_branch, labels=[]): pr = self._target_repo.create_pull( pr_message, pr_body, target_branch, f'{self._source_repo.owner.login}:{self.branch_name}' ) - pr.set_labels(*labels) + if labels: + pr.set_labels(*labels) return pr def _get_new_version(self): diff --git a/setup.py b/setup.py index 4d01ce8..7edb97c 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup_reqs = ['pytest', 'pytest-cov', 'pytest-runner', 'flake8'] setuptools.setup( name="gordian", - version="3.0.1", + version="3.1.0", author="Intuit", author_email="cg-sre@intuit.com", description="A tool to search and replace files in a Git repo", diff --git a/tests/test_repo.py b/tests/test_repo.py index 60f76ce..366ae6f 100644 --- a/tests/test_repo.py +++ b/tests/test_repo.py @@ -110,6 +110,17 @@ def test_create_pr(self): pr.set_labels.assert_called_once_with('test') repo._source_repo.create_pull.assert_not_called() + def test_create_pr_no_labels(self): + repo = Repo(None, branch='', github=self.mock_git) + repo._target_repo = MagicMock() + repo._source_repo = MagicMock() + repo._source_repo.owner.login = 'someone' + repo.branch_name = 'branch' + pr = repo.create_pr('test', '', 'target_branch') + repo._target_repo.create_pull.assert_called_once_with('test', '', 'target_branch', 'someone:branch') + pr.set_labels.assert_not_called() + repo._source_repo.create_pull.assert_not_called() + def test__get_new_version_major(self): version_file = MagicMock() version_file.decoded_content = '1.2.3'.encode('utf-8')