def test_index_init(): commit1 = Mock() commit2 = Mock() tagref1 = Mock() tagref1.commit = commit1 tagref1.name = "a" tagref2 = Mock() tagref2.commit = commit2 tagref2.name = "b" tagref3 = Mock() tagref3.commit = commit2 tagref3.name = "c" repo_mock = Mock(spec=Repo, tags=[tagref1, tagref2, tagref3]) index = GitRepository._init_commit_tags_index(repo_mock, r".*") assert index == {commit1: [tagref1], commit2: [tagref2, tagref3]}
def test_tag_pattern(tags, tag_prefix, tag_pattern, expected_tags): tag_refs = [] for tag in tags: tag_ref = Mock(commit=Mock()) tag_ref.name = tag tag_refs.append(tag_ref) repo_mock = Mock(spec=Repo, tags=tag_refs) selected_tag_refs = GitRepository._init_commit_tags_index(repo_mock, tag_prefix, tag_pattern) selected_tags = [] for selected_tag_ref_list in selected_tag_refs.values(): for selected_tag_ref in selected_tag_ref_list: selected_tags.append(selected_tag_ref.name) assert sorted(selected_tags) == sorted(expected_tags)
def main( repo, title, description, output, remote, latest_version: str, unreleased: bool, diff_url, issue_url, issue_pattern, tag_prefix, stdout: bool, tag_pattern: Optional[str], starting_commit: str, stopping_commit: str, ): # Convert the repository name to an absolute path repo = os.path.abspath(repo) repository = GitRepository( repo, latest_version=latest_version, skip_unreleased=not unreleased, tag_prefix=tag_prefix, tag_pattern=tag_pattern, ) presenter = MarkdownPresenter() changelog = generate_changelog( repository, presenter, title, description, remote=remote, issue_pattern=issue_pattern, issue_url=issue_url, diff_url=diff_url, starting_commit=starting_commit, stopping_commit=stopping_commit, ) if stdout: print(changelog) else: output.write(changelog)
def test_index_init(): commit1 = Mock() commit2 = Mock() tagref1 = Mock(commit=commit1) tagref1.name = "1.0.0" tagref2 = Mock(commit=commit2) tagref2.name = "2.0.0" tagref3 = Mock(commit=commit2) tagref3.name = "2.0.0" repo_mock = Mock(spec=Repo, tags=[tagref1, tagref2, tagref3]) # no prefix tag_prefix = "" # we are using default tag pattern => semantic versioning tag_pattern = None index = GitRepository._init_commit_tags_index(repo_mock, tag_prefix, tag_pattern) assert index == {commit1: [tagref1], commit2: [tagref2, tagref3]}
def test_remote_url(input, expected): assert expected == GitRepository._sanitize_remote_url(input)
def test_issue_from_git_remote_url(mock_ru, mock_repo): remote_url = GitRepository(".")._issue_from_git_remote_url(remote="origin") expected = "https://github.com/Michael-F-Bryan/auto-changelog/issues/{id}" assert expected == remote_url
def test_parse_conventional_commit_with_empty_message(message, expected): assert expected == GitRepository._parse_conventional_commit(message)