diff --git a/CHANGELOG.md b/CHANGELOG.md index a4f2fbd..27c7b49 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). +## [1.5.0] - 2020-06-23 +### Added +- Added the ability to set labels to sent pull requests using a flag. + ## [1.4.1] - 2020-06-18 ### Fixed - set_target_branch was not cleaning the file cache, resulting in gordian not being able to get new files in the new branches. diff --git a/gordian/gordian.py b/gordian/gordian.py index 18f84d6..53999ef 100644 --- a/gordian/gordian.py +++ b/gordian/gordian.py @@ -84,6 +84,14 @@ def get_basic_parser(): dest='force_changelog', help='Fail if changelog does not exist or cannot be parsed' ) + parser.add_argument( + '-l','--labels', + required=False, + default=[], + nargs='+', + dest='pr_labels', + help='List of space separated label names you wish to add to your pull request(s)' + ) bumpers = parser.add_mutually_exclusive_group(required=False) bumpers.add_argument( '-M', '--major', @@ -149,13 +157,14 @@ def transform(args, transformations, repositories, pr_created_callback): if not args.dry_run: try: pull_request = repo._repo.create_pull(args.pr_message, '', args.target_branch, repo.branch_name) + pull_request.set_labels(*args.pr_labels) pull_request_urls.append(pull_request.html_url) if pr_created_callback is not None: logger.debug(f'Calling post pr created callback with: {pull_request}, {repo.branch_name}') pr_created_callback(repo_name, pull_request) - logger.info(f'PR created: {args.pr_message}. Branch: {repo.branch_name}') + logger.info(f'PR created: {args.pr_message}. Branch: {repo.branch_name}. Labels: {args.pr_labels}') except GithubException as e: - logger.info(f'PR already exists for {repo.branch_name}') + logger.info(f'PR already exists for {repo.branch_name}. Error: {e}') if pull_request_urls: logger.info('Pull requests') diff --git a/setup.py b/setup.py index 44f2c52..5f7961b 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup_reqs = ['pytest', 'pytest-cov', 'pytest-runner', 'flake8'] setuptools.setup( name="gordian", - version="1.4.1", + version="1.5.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_gordian.py b/tests/test_gordian.py index fc932d0..10a0479 100644 --- a/tests/test_gordian.py +++ b/tests/test_gordian.py @@ -18,6 +18,7 @@ def __init__(self, config_file='./tests/fixtures/test_config.yaml', dry_run = Fa self.github_api = None self.semver_label = None self.target_branch = 'master' + self.pr_labels = ['test'] def test_apply_transformations_without_changes(self): with patch('gordian.gordian.Repo') as RepoMock, patch('gordian.transformations.Transformation') as TransformationMockClass: @@ -36,6 +37,7 @@ def test_apply_transformations_with_changes(self): apply_transformations(TestGordian.Args(), [TransformationMockClass]) RepoMock.assert_has_calls([call().bump_version(False), call().bump_version(False)], any_order=True) RepoMock.assert_has_calls([call()._repo.create_pull('test', '', 'master', ANY), call()._repo.create_pull('test', '', 'master', ANY)], any_order=True) + RepoMock.assert_has_calls([call()._repo.create_pull().set_labels('test'), call()._repo.create_pull().set_labels('test')], any_order=True) def test_apply_transformations_with_changes_dry_run(self): with patch('gordian.gordian.Repo') as RepoMock, patch('gordian.transformations.Transformation', ) as TransformationMockClass: @@ -44,6 +46,7 @@ def test_apply_transformations_with_changes_dry_run(self): apply_transformations(TestGordian.Args(dry_run=True), [TransformationMockClass]) RepoMock.assert_has_calls([call().bump_version(True), call().bump_version(True)], any_order=True) self.assertNotIn(call().repo.create_pull('test', '', 'master', ANY), RepoMock.mock_calls) + self.assertNotIn(call()._repo.create_pull().set_labels('test'), RepoMock.mock_calls) def test_apply_transformations_with_changes_and_callback(self): with patch('gordian.gordian.Repo') as RepoMock, patch('gordian.transformations.Transformation', ) as TransformationMockClass: @@ -55,6 +58,7 @@ def test_apply_transformations_with_changes_and_callback(self): apply_transformations(args, [TransformationMockClass], callback_mock) pull_request = RepoMock.return_value._repo.create_pull.return_value RepoMock.assert_has_calls([call().bump_version(False), call().bump_version(False)], any_order=True) + RepoMock.assert_has_calls([call()._repo.create_pull().set_labels('test'), call()._repo.create_pull().set_labels('test')], any_order=True) RepoMock.assert_has_calls([ call()._repo.create_pull('test', '', 'target_branch', ANY), call()._repo.create_pull('test', '', 'target_branch', ANY)], @@ -63,3 +67,15 @@ def test_apply_transformations_with_changes_and_callback(self): call('testOrg/TestService1', pull_request), call('testOrg/TestService2', pull_request)] ) + + def test_apply_transformations_with_changes_default_labels(self): + with patch('gordian.gordian.Repo') as RepoMock, patch('gordian.transformations.Transformation', ) as TransformationMockClass: + instance = RepoMock.return_value + instance.dirty = True + gordian_args = TestGordian.Args() + gordian_args.pr_labels = [] + apply_transformations(gordian_args, [TransformationMockClass]) + RepoMock.assert_has_calls([call().bump_version(False), call().bump_version(False)], any_order=True) + RepoMock.assert_has_calls([call()._repo.create_pull('test', '', 'master', ANY), call()._repo.create_pull('test', '', 'master', ANY)], any_order=True) + self.assertNotIn(call()._repo.create_pull().set_labels(ANY), RepoMock.mock_calls) +