def test_render_only_commits(request): changelog = model.Changelog(sha='sha', current_version='0.0.1') commit = model.ChangelogCommit(title=request.node.name, url='url', timestamp=121234) changelog.add(commit) expected = """*Changes* **Dangling Commits:** - {} ([Commit](url)) """.format(request.node.name) actual = changelog.render() assert expected == actual
def test_render_all(request): changelog = model.Changelog(sha='sha', current_version='0.0.1') commit = model.ChangelogCommit(title=request.node.name, url='url', timestamp=121234) bug = model.ChangelogIssue(title=request.node.name, url='url', timestamp=121234, kind=model.ChangelogIssue.FEATURE) issue = model.ChangelogIssue(title=request.node.name, url='url', timestamp=121234, kind=model.ChangelogIssue.ISSUE) feature = model.ChangelogIssue(title=request.node.name, url='url', timestamp=121234, kind=model.ChangelogIssue.FEATURE) changelog.add(commit) changelog.add(bug) changelog.add(issue) changelog.add(feature) expected = """*Changes* **New Features:** - {0} ([Issue](url)) **Issues:** - {0} ([Issue](url)) **Dangling Commits:** - {0} ([Commit](url)) """.format(request.node.name) actual = changelog.render() assert expected == actual
def test_not_empty_commits(request): changelog = model.Changelog(sha='sha', current_version='0.0.1') commit = model.ChangelogCommit(title=request.node.name, url='url', timestamp=121234) changelog.add(commit) assert not changelog.empty
def test_add_identical_commits(): changelog = model.Changelog(sha='sha', current_version='0.0.1') commit1 = model.ChangelogCommit(title='commit', url='url', timestamp=100) commit2 = model.ChangelogIssue(title='commit', url='url', timestamp=100) changelog.add(commit1) changelog.add(commit2) expected_number_of_commits = 1 assert expected_number_of_commits == len(changelog.commits)
def test_add_commit(request): changelog = model.Changelog(sha='sha', current_version='0.0.1') commit = model.ChangelogCommit(title=request.node.name, url='url', timestamp=121234) changelog.add(commit) expected_commit_title = request.node.name expected_number_of_commits = 1 assert expected_number_of_commits == len(changelog.commits) assert expected_commit_title == changelog.commits.pop().title assert not changelog.features assert not changelog.bugs assert not changelog.issues
def _create_release(ctx, changelog, version, branch, master_branch, sha): gh = ctx.obj.github next_version = version or changelog.next_version try: # figure out how to avoid calling private api here... # exposing this doesn't seem like a good solution either. # noinspection PyProtectedMember # pylint: disable=protected-access set_version_commit = gh._create_set_version_commit(value=next_version, sha=sha).impl release = ctx.invoke(create_release, sha=set_version_commit.sha) bump = model.ChangelogCommit(title=set_version_commit.message, url=set_version_commit.html_url, timestamp=set_version_commit.author.date, impl=set_version_commit) changelog.add(bump) changelog_file = os.path.join(tempfile.mkdtemp(), 'changelog.md') with open(changelog_file, 'w') as stream: stream.write(changelog.render()) ctx.invoke(upload_changelog, changelog=changelog_file, release=release.title) log.echo('Bumping version to {}'.format(next_version)) ctx.invoke(reset_branch, name=branch, sha=set_version_commit.sha, hard=False) if master_branch != branch: ctx.invoke(reset_branch, name=master_branch, sha=set_version_commit.sha, hard=False) except TerminationException as e: if isinstance(e.cause, exceptions.ReleaseAlreadyExistsException): log.echo('Release {} already exists'.format(e.cause.release)) ref = gh.repo.get_git_ref(ref='tags/{}'.format(e.cause.release)) rel = gh.repo.get_release(id=next_version) release = model.Release(impl=rel, title=rel.title, url=rel.html_url, sha=ref.object.sha) return release if isinstance(e.cause, exceptions.UpdateNotFastForwardException): e.cause.cause = 'You probably merged another PR to the {} branch before this execution ' \ 'ended. This means you wont be able to release this commit. However, ' \ 'the second PR will be released soon enough and contain this commit.' \ .format(branch) log.echo(str(e)) log.echo('Cleaning up...', add=True) ctx.invoke(delete_release, name=next_version) ctx.invoke(delete_tag, name=next_version) log.sub() raise return release
def test_no_timestamp(): with pytest.raises(exceptions.InvalidArgumentsException): model.ChangelogCommit(title='title', url='url', timestamp=None)
def generate_changelog(self, base, hooks): hooks = hooks or {} pre_commit = hooks.get('pre_commit', _empty_hook) pre_collect = hooks.get('pre_collect', _empty_hook) pre_analyze = hooks.get('pre_analyze', _empty_hook) post_analyze = hooks.get('post_analyze', _empty_hook) post_commit = hooks.get('post_commit', _empty_hook) self._debug('Generating changelog...') pre_collect() # additional API call to support branch names as base if base: base = self._repo.repo.get_commit(sha=base).sha base = base or self._fetch_last_release() self._debug('Fetching commits...') commits = self._fetch_commits(base) if not commits: raise exceptions.EmptyChangelogException(sha=self.commit.sha, base=base) self._debug('Fetched commits.', sha=self.commit.sha, base=base) changelog = model.Changelog(current_version=self.setup_py_version, sha=self.commit.sha) pre_analyze(commits) for commit in commits: pre_commit(commit) issues = self._repo.detect_issues(message=commit.commit.message) if not issues: self._debug('Found commit.', sha=commit.sha, commit_message=commit.commit.message) change = model.ChangelogCommit( title=commit.commit.message, url=commit.html_url, timestamp=commit.commit.author.date, impl=commit) self._debug('Adding change to changelog.', change=change.url) changelog.add(change) else: for issue in issues: self._add_issue_to_changelog(issue, changelog) post_commit() post_analyze() self._debug('Generated changelog.') return changelog