def test_message_analysis_with_branch_baseline(self): # pylint: disable=line-too-long git = self.git all_tags = git.query_tag_commits(self.git_dir, TAG_VERSION_PATTERN) tests = [(self.MAJOR_BRANCH, SemanticVersion.MAJOR_INDEX), (self.MINOR_BRANCH, SemanticVersion.MINOR_INDEX), (self.PATCH_BRANCH, SemanticVersion.PATCH_INDEX)] for branch, expect in tests: self.run_git('checkout {branch}'.format(branch=branch)) commit_id = git.query_local_repository_commit_id(self.git_dir) _, messages = git.query_local_repository_commits_to_existing_tag_from_id( self.git_dir, commit_id, all_tags) self.assertEqual( expect, CommitMessage.determine_semver_implication_on_list( messages, major_regexs=CommitMessage.DEFAULT_MAJOR_REGEXS, minor_regexs=CommitMessage.DEFAULT_MINOR_REGEXS, patch_regexs=CommitMessage.DEFAULT_PATCH_REGEXS)) self.assertEqual( expect, CommitMessage.determine_semver_implication_on_list( sorted(messages, reverse=True), major_regexs=CommitMessage.DEFAULT_MAJOR_REGEXS, minor_regexs=CommitMessage.DEFAULT_MINOR_REGEXS, patch_regexs=CommitMessage.DEFAULT_PATCH_REGEXS))
def test_message_analysis_with_branch_baseline(self): # pylint: disable=line-too-long git = self.git all_tags = git.query_tag_commits(self.git_dir, TAG_VERSION_PATTERN) tests = [(self.MAJOR_BRANCH, SemanticVersion.MAJOR_INDEX), (self.MINOR_BRANCH, SemanticVersion.MINOR_INDEX), (self.PATCH_BRANCH, SemanticVersion.PATCH_INDEX)] for branch, expect in tests: self.run_git('checkout {branch}'.format(branch=branch)) commit_id = git.query_local_repository_commit_id(self.git_dir) _, messages = git.query_local_repository_commits_to_existing_tag_from_id( self.git_dir, commit_id, all_tags) self.assertEqual( expect, CommitMessage.determine_semver_implication_on_list( messages, major_regexs=CommitMessage.DEFAULT_MAJOR_REGEXS, minor_regexs=CommitMessage.DEFAULT_MINOR_REGEXS, patch_regexs=CommitMessage.DEFAULT_PATCH_REGEXS)) self.assertEqual( expect, CommitMessage.determine_semver_implication_on_list( sorted(messages, reverse=True), major_regexs=CommitMessage.DEFAULT_MAJOR_REGEXS, minor_regexs=CommitMessage.DEFAULT_MINOR_REGEXS, patch_regexs=CommitMessage.DEFAULT_PATCH_REGEXS))
def add_repository(self, repository, summary): """Add repository changes into the builder.""" message_list = summary.commit_messages normalized_messages = CommitMessage.normalize_message_list( message_list) self.__entries.append( ChangelogRepositoryData(repository, summary, normalized_messages))
def test_merged_branch(self): git = self.git all_tags = git.query_tag_commits(self.git_dir, TAG_VERSION_PATTERN) self.run_git('checkout {branch}'.format(branch=self.MERGED_BRANCH)) commit_id = git.query_local_repository_commit_id(self.git_dir) _, messages = git.query_local_repository_commits_to_existing_tag_from_id( self.git_dir, commit_id, all_tags) self.assertEqual(1, len(messages)) normalized_messages = CommitMessage.normalize_message_list(messages) self.assertEqual(3, len(normalized_messages)) expected_messages = [ (' '*4 + 'feat(testC): added major_file\n' '\n' + ' '*4 + 'Interestingly enough, this is a BREAKING CHANGE.'), ' '*4 + 'feat(testB): added minor_file', ' '*4 + 'fix(testA): added patch_file' ] prototype = messages[0] for index, msg in enumerate(normalized_messages): self.assertEqual(prototype.author, msg.author) self.assertEqual(expected_messages[index], msg.message) # The dates might be off by one sec because of roundoff with # the sequential commits. Typically the times will be the same # but we check for the drift explicitly so the assertion failure # would make more sense should it be neither. prototype_date = dateutil.parser.parse(prototype.date) msg_date = dateutil.parser.parse(msg.date) one_sec = datetime.timedelta(0, 1) if msg_date + one_sec != prototype_date: self.assertEqual(prototype.date, msg.date)
def test_merged_branch(self): git = self.git all_tags = git.query_tag_commits(self.git_dir, TAG_VERSION_PATTERN) self.run_git('checkout {branch}'.format(branch=self.MERGED_BRANCH)) commit_id = git.query_local_repository_commit_id(self.git_dir) _, messages = git.query_local_repository_commits_to_existing_tag_from_id( self.git_dir, commit_id, all_tags) self.assertEqual(1, len(messages)) normalized_messages = CommitMessage.normalize_message_list(messages) self.assertEqual(3, len(normalized_messages)) expected_messages = [ (' ' * 4 + 'feat(testC): added major_file\n' '\n' + ' ' * 4 + 'Interestingly enough, this is a BREAKING CHANGE.'), ' ' * 4 + 'feat(testB): added minor_file', ' ' * 4 + 'fix(testA): added patch_file' ] prototype = messages[0] for index, msg in enumerate(normalized_messages): self.assertEqual(prototype.author, msg.author) self.assertEqual(expected_messages[index], msg.message) # The dates might be off by one sec because of roundoff with # the sequential commits. Typically the times will be the same # but we check for the drift explicitly so the assertion failure # would make more sense should it be neither. prototype_date = dateutil.parser.parse(prototype.date) msg_date = dateutil.parser.parse(msg.date) one_sec = datetime.timedelta(0, 1) if msg_date + one_sec != prototype_date: self.assertEqual(prototype.date, msg.date)
def test_yamilfy(self): # The summary values are arbitrary. Just verifying we can go in and out # of yaml. summary = RepositorySummary('abcd', 'tag-123', '1.2.0', '1.1.5', [ CommitMessage('commitB', 'authorB', 'dateB', 'messageB'), CommitMessage('commitA', 'authorA', 'dateA', 'messageA') ]) yamlized = yaml.safe_load(summary.to_yaml()) self.assertEqual(summary.commit_id, yamlized['commit_id']) self.assertEqual(summary.tag, yamlized['tag']) self.assertEqual(summary.version, yamlized['version']) self.assertEqual(summary.prev_version, yamlized['prev_version']) self.assertEqual([{ 'commit_id': 'commit' + x, 'author': 'author' + x, 'date': 'date' + x, 'message': 'message' + x } for x in ['B', 'A']], yamlized['commit_messages']) self.assertEqual(summary, RepositorySummary.from_dict(yamlized))
def test_to_yaml(self): summary = RepositorySummary( 'abcd1234', 'mytag-987', '0.0.1', '0.0.0', [CommitMessage('commit-abc', 'author', 'date', 'commit message')]) expect = """commit_id: {id} prev_version: {prev} tag: {tag} version: {version} """.format(id=summary.commit_id, tag=summary.tag, version=summary.version, prev=summary.prev_version) self.assertEqual(expect, summary.to_yaml(with_commit_messages=False))
def add_repository(self, repository, summary): """Add repository changes into the builder.""" message_list = summary.commit_messages normalized_messages = CommitMessage.normalize_message_list(message_list) self.__entries.append(ChangelogRepositoryData( repository, summary, normalized_messages))