From e5f1f8896a0a6f6eca6aef4c13c216b5a8e6fb51 Mon Sep 17 00:00:00 2001 From: Rene Martin Date: Thu, 18 Jun 2020 09:46:41 -0700 Subject: [PATCH] Reseting the file cache when changing the target branch * Fixing cache files bug * Bumped the version and updated changelog --- CHANGELOG.md | 4 ++++ gordian/repo.py | 6 ++++++ setup.py | 2 +- tests/test_repo.py | 11 +++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a549295..a4f2fbd 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.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. + ## [1.4.0] - 2020-06-17 ### Added - Print out PR URLs at the end of a Gordian run diff --git a/gordian/repo.py b/gordian/repo.py index a17fbf7..46479e6 100644 --- a/gordian/repo.py +++ b/gordian/repo.py @@ -40,6 +40,7 @@ def __init__(self, repo_name, github_api_url=None, branch=None, git=None, files= self.dirty = False self.new_version = None self.semver_label = semver_label + self.target_branch = None self.set_target_branch(target_branch) logger.debug(f'Target ref: {target_branch}') @@ -50,8 +51,13 @@ def __init__(self, repo_name, github_api_url=None, branch=None, git=None, files= logger.debug(f'Branch name for this changes: {self.branch_name}') def set_target_branch(self, branch): + if branch == self.target_branch: + return + self.target_branch = branch self.target_ref = f"refs/heads/{self.target_branch}" + # Resetting the file cache when we change the branch + self.files = [] def get_objects(self, filename, klass=None): file = self.find_file(filename) diff --git a/setup.py b/setup.py index 939df60..44f2c52 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.0", + version="1.4.1", 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 4fc213a..a98335a 100644 --- a/tests/test_repo.py +++ b/tests/test_repo.py @@ -58,3 +58,14 @@ def test_get_files(self): self.repo.get_files() self.repo._repo.get_contents.assert_has_calls([call('', 'refs/heads/target'), call('directory', 'refs/heads/target')]) self.assertEquals(self.repo.files, [repository_file]) + + def test_set_target_branch(self): + cached_files = ['cached_file', 'cached_file', 'cached_file'] + self.repo.files = cached_files.copy() + self.repo.set_target_branch('master') + self.assertEqual(self.repo.files, cached_files) + + self.repo.set_target_branch('Something different') + self.assertEqual(self.repo.files, []) + self.assertEqual(self.repo.target_branch, 'Something different') + self.assertEqual(self.repo.target_ref, 'refs/heads/Something different')