def test_changelog_sorted_releases(): changelog = Changelog() changelog.add_release(title="1.2.3", date=date.today(), sha="123") changelog.add_release(title="1.1.1", date=date.today() - timedelta(days=1), sha="456") releases = changelog.releases assert len(releases) == 2 assert releases[0].title == "1.2.3" assert releases[1].title == "1.1.1"
def test_changelog_sorted_releases(): changelog = Changelog() changelog.add_release(title='1.2.3', date=date.today(), sha='123') changelog.add_release(title='1.1.1', date=date.today() - timedelta(days=1), sha='456') releases = changelog.releases assert len(releases) == 2 assert releases[0].title == '1.2.3' assert releases[1].title == '1.1.1'
def test_changelog_add_note(): changelog = Changelog() changelog.add_release(title='Unreleased', date=date.today(), sha='') changelog.add_note(sha='123', change_type='fix', description='') changelog.add_note(sha='345', change_type='feat', description='') releases = changelog.releases assert len(releases) == 1 assert releases[0].title == 'Unreleased' assert len(releases[0].fixes) == 1 assert releases[0].fixes[0].sha == '123' assert len(releases[0].features) == 1 assert releases[0].features[0].sha == '345'
def test_changelog_add_note(): changelog = Changelog() changelog.add_release(title="Unreleased", tag="HEAD", date=date.today(), sha="") changelog.add_note(sha="123", change_type="fix", description="") changelog.add_note(sha="345", change_type="feat", description="") # unsupported_type should be ignored changelog.add_note(sha="567", change_type="unsupported_type", description="") releases = changelog.releases assert len(releases) == 1 assert releases[0].title == "Unreleased" assert releases[0].tag == "HEAD" assert len(releases[0].fixes) == 1 assert releases[0].fixes[0].sha == "123" assert len(releases[0].features) == 1 assert releases[0].features[0].sha == "345" assert len(releases[0]._notes) == 2
def generate_changelog( self, title: str = "Changelog", description: str = "", remote: str = "origin", issue_pattern: Optional[str] = None, issue_url: Optional[str] = None, starting_commit: str = "", stopping_commit: str = "HEAD", ) -> Changelog: issue_url = issue_url or self._issue_from_git_remote_url(remote) changelog = Changelog(title, description, issue_pattern, issue_url) if self._repository_is_empty(): logging.info("Repository is empty.") return changelog iter_rev = self._get_iter_rev(starting_commit, stopping_commit) commits = self.repository.iter_commits(iter_rev) # Some thoughts here # First we need to check if all commits are "released". If not, we have to create our special "Unreleased" # release. Then we simply iter over all commits, assign them to current release or create new if we find it. first_commit = True skip = self._skip_unreleased for commit in commits: if skip and commit not in self.commit_tags_index: continue else: skip = False if first_commit and commit not in self.commit_tags_index: changelog.add_release(self._latest_version, date.today(), sha256()) first_commit = False if commit in self.commit_tags_index: attributes = self._extract_release_args( commit, self.commit_tags_index[commit]) changelog.add_release(*attributes) attributes = self._extract_note_args(commit) changelog.add_note(*attributes) return changelog
def generate_changelog(self, title: str = 'Changelog', description: str = '') -> Changelog: changelog = Changelog(title, description) commits = self.repository.iter_commits( 'master') # TODO don't forget to finish revision options # Some thoughts here # First we need to check if all commits are "released". If not, we have to create our special "Unreleased" # release. Then we simply iter over all commits, assign them to current release or create new if we find it. first_commit = True for commit in commits: if first_commit and commit not in self.commit_tags_index: changelog.add_release('Unreleased', date.today(), sha256()) first_commit = False if commit in self.commit_tags_index: attributes = self._extract_release_args( commit, self.commit_tags_index[commit]) changelog.add_release(*attributes) attributes = self._extract_note_args(commit) changelog.add_note(*attributes) return changelog
def generate_changelog( self, title: str = "Changelog", description: str = "", remote: str = "origin", issue_pattern: Optional[str] = None, issue_url: Optional[str] = None, diff_url: Optional[str] = None, starting_commit: str = "", stopping_commit: str = "HEAD", ) -> Changelog: issue_url = issue_url or self._issue_from_git_remote_url(remote) diff_url = diff_url or self._diff_from_git_remote_url(remote) changelog = Changelog(title, description, issue_pattern, issue_url, self.tag_prefix, self.tag_pattern) if self._repository_is_empty(): logging.info("Repository is empty.") return changelog iter_rev = self._get_iter_rev(starting_commit, stopping_commit) commits = self.repository.iter_commits(iter_rev) # Some thoughts here # First we need to check if all commits are "released". If not, we have to create our special "Unreleased" # release. Then we simply iter over all commits, assign them to current release or create new if we find it. first_commit = True skip = self._skip_unreleased for commit in commits: if skip and commit not in self.commit_tags_index: continue else: skip = False if first_commit and commit not in self.commit_tags_index: # if no last version specified by the user => consider HEAD if not self._latest_version: changelog.add_release("Unreleased", "HEAD", date.today(), sha256()) else: changelog.add_release(self._latest_version, self._latest_version, date.today(), sha256()) first_commit = False if commit in self.commit_tags_index: attributes = self._extract_release_args(commit, self.commit_tags_index[commit]) changelog.add_release(*attributes) attributes = self._extract_note_args(commit) changelog.add_note(*attributes) # create the compare url for each release releases = changelog.releases # we are using len(changelog.releases) - 1 because there is not compare url for the oldest version for release_index in reversed(range(len(changelog.releases) - 1)): releases[release_index].set_compare_url(diff_url, releases[release_index + 1].title) return changelog
def generate_changelog( self, title: str = "Changelog", description: str = "", remote: str = "origin", issue_pattern: Optional[str] = None, issue_url: Optional[str] = None, diff_url: Optional[str] = None, starting_commit: str = "", stopping_commit: str = "HEAD", ) -> Changelog: locallogger = logging.getLogger("repository.generate_changelog") issue_url = issue_url or self._issue_from_git_remote_url(remote) diff_url = diff_url or self._diff_from_git_remote_url(remote) changelog = Changelog(title, description, issue_pattern, issue_url, self.tag_prefix, self.tag_pattern) if self._repository_is_empty(): locallogger.info("Repository is empty.") return changelog iter_rev = self._get_iter_rev(starting_commit, stopping_commit) commits = self.repository.iter_commits(iter_rev) # Some thoughts here # First we need to check if all commits are "released". If not, we have to create our special "Unreleased" # release. Then we simply iter over all commits, assign them to current release or create new if we find it. first_commit = True skip = self._skip_unreleased locallogger.debug("Start iterating commits") for commit in commits: sha = commit.hexsha[0:7] locallogger.debug("Found commit {}".format(sha)) if skip and commit not in self.commit_tags_index: locallogger.debug("Skipping unreleased commit " + sha) continue else: skip = False if first_commit and commit not in self.commit_tags_index: # if no last version specified by the user => consider HEAD if not self._latest_version: locallogger.debug("Adding release 'unreleased'") changelog.add_release("Unreleased", "HEAD", date.today(), sha256()) else: locallogger.debug("Adding release '{}'".format( self._latest_version)) changelog.add_release(self._latest_version, self._latest_version, date.today(), sha256()) first_commit = False if commit in self.commit_tags_index: attributes = self._extract_release_args( commit, self.commit_tags_index[commit]) locallogger.debug( "Adding release '{}' with attributes {}".format( attributes[0], attributes)) changelog.add_release(*attributes) attributes = self._extract_note_args(commit) locallogger.debug("Adding commit {} with attributes {}".format( sha, attributes)) changelog.add_note(*attributes) # create the compare url for each release releases = changelog.releases # we are using len(changelog.releases) - 1 because there is not compare url for the oldest version if diff_url is not None: # if links are off for release_index in reversed(range(len(changelog.releases) - 1)): releases[release_index].set_compare_url( diff_url, releases[release_index + 1].title) # Close the link to the repository # If we are not closing it, some references are not cleaned on windows self.repository.close() return changelog