def test_commit_adds_message_with_version_string(multiversion_repo): path = multiversion_repo.workspace f = path / "hello.txt" f.write_text("hello world! v3") multiversion_repo.run("git add hello.txt") Git.commit("new_version") assert multiversion_repo.api.head.commit.message == "Update CHANGELOG for new_version\n"
def test_add_path_stages_changes_for_commit(multiversion_repo): path = multiversion_repo.workspace f = path / "hello.txt" f.write_text("hello world! v3") assert "Changes not staged for commit" in multiversion_repo.run( "git status", True) Git.add_path("hello.txt") assert "Changes not staged for commit" not in multiversion_repo.run( "git status", True)
def test_get_latest_info_raises_if_rev_parse_fails(git_repo, monkeypatch): monkeypatch.setattr( subprocess, "check_output", mock.Mock(side_effect=[ b"", subprocess.CalledProcessError(returncode=1, cmd="") ]), ) with pytest.raises(errors.VcsError) as ex: Git.get_latest_tag_info() assert str(ex.value) == "Unable to get current git branch"
def test_get_latest_info_branch(multiversion_repo): path = multiversion_repo.workspace f = path / "hello.txt" f.write_text("hello world! v3") info = Git.get_latest_tag_info() assert info["branch"] == "master"
def test_get_latest_info_dirty(multiversion_repo): path = multiversion_repo.workspace f = path / "hello.txt" f.write_text("hello world! v3") info = Git.get_latest_tag_info() assert info["dirty"] is True assert info["distance_to_latest_tag"] == 0
def test_get_latest_info_untagged(multiversion_repo): path = multiversion_repo.workspace f = path / "hello.txt" f.write_text("hello world! v3") multiversion_repo.run("git add hello.txt") multiversion_repo.api.index.commit("untagged") info = Git.get_latest_tag_info() assert info["distance_to_latest_tag"] == 1
def _finalise(writer, extractor, version_tag, extension, release=False, dry_run=False, commit=False): if dry_run or click.confirm( "Write CHANGELOG for suggested version {}".format(version_tag), ): writer.write() extractor.clean() if dry_run or not commit: return Git.add_path("CHANGELOG.{extension}".format(extension=extension)) # TODO: Dont add release notes if using commit messages... Git.add_path("release_notes") Git.commit(version_tag) if release: BumpVersion.release(version_tag)
def test_get_latest_info_current_version_vtag(multiversion_v_repo): info = Git.get_latest_tag_info() assert info["current_version"] == "0.0.2"
def test_get_latest_info_clean(multiversion_repo): info = Git.get_latest_tag_info() assert info["dirty"] is False
def test_get_latest_info_raises_if_no_tags_found(git_repo): with pytest.raises(errors.VcsError) as ex: Git.get_latest_tag_info() assert str(ex.value) == "Unable to get version number from git tags"
def test_get_latest_info_commit_sha(multiversion_repo): head_hash = multiversion_repo.api.head.commit info = Git.get_latest_tag_info() assert info["commit_sha"] == str(head_hash)[:7]
def _gen(dry_run=False, allow_dirty=False, release=False, commit=False, version_tag=None): config = Config().read() release = config.get("release") or release allow_dirty = config.get("allow_dirty") or allow_dirty commit = config.get("commit") or commit extension = util.detect_extension() if extension is None: click.echo("No CHANGELOG file detected, run changelog-init") raise click.Abort() process_info(Git.get_latest_tag_info(), dry_run, allow_dirty, config) # TODO: supported default extensions (steal from conventional commits) # TODO: support multiple extras by default (the usuals) section_mapping = config.get("section_mapping", {}) supported_sections = config.get("sections", SUPPORTED_SECTIONS) e = extractor.ReleaseNoteExtractor(dry_run=dry_run, supported_sections=supported_sections) sections = e.extract(section_mapping) semver = None if version_tag is None: semver = "minor" if "feat" in sections else "patch" for section_issues in sections.values(): for issue in section_issues.values(): if issue["breaking"]: semver = "major" version_info = BumpVersion.get_version_info(semver) version_tag = version_info["new"] # TODO: take a note from bumpversion, read in versioning format string version_string = "v{version_tag}".format(version_tag=version_tag) w = writer.new_writer(extension, dry_run=dry_run, issue_link=config.get("issue_link")) w.add_version(version_string) for section in sorted(e.supported_sections): if section not in sections: continue header = e.supported_sections[section] w.add_section( header, {k: v["description"] for k, v in sections[section].items()}) click.echo(w) _finalise(w, e, version_tag, extension, dry_run=dry_run, release=release, commit=commit)