Exemplo n.º 1
0
def test_get_metadata_from_d(changelog_d_file):
    meta = changelog.get_metadata(changelog_d_file)
    assert meta == {
        "latest_version": None,
        "latest_version_position": None,
        "unreleased_end": 2,
        "unreleased_start": 1,
    }
Exemplo n.º 2
0
def test_get_metadata_from_c(changelog_c_file):
    meta = changelog.get_metadata(changelog_c_file)
    assert meta == {
        "latest_version": "1.0.0",
        "latest_version_position": 3,
        "unreleased_end": 3,
        "unreleased_start": 1,
    }
Exemplo n.º 3
0
    def __call__(self):
        commit_parser = self.cz.commit_parser
        changelog_pattern = self.cz.changelog_pattern
        start_rev = self.start_rev
        unreleased_version = self.unreleased_version
        changelog_meta: Dict = {}

        if not changelog_pattern or not commit_parser:
            out.error(
                f"'{self.config.settings['name']}' rule does not support changelog"
            )
            raise SystemExit(NO_PATTERN_MAP)

        tags = git.get_tags()
        if not tags:
            tags = []

        if self.incremental:
            changelog_meta = changelog.get_metadata(self.file_name)
            latest_version = changelog_meta.get("latest_version")
            if latest_version:
                start_rev = self._find_incremental_rev(latest_version, tags)

        commits = git.get_commits(start=start_rev, args="--author-date-order")
        if not commits:
            out.error("No commits found")
            raise SystemExit(NO_COMMITS_FOUND)

        tree = changelog.generate_tree_from_commits(commits, tags,
                                                    commit_parser,
                                                    changelog_pattern,
                                                    unreleased_version)
        changelog_out = changelog.render_changelog(tree)

        if self.dry_run:
            out.write(changelog_out)
            raise SystemExit(0)

        lines = []
        if self.incremental and os.path.isfile(self.file_name):
            with open(self.file_name, "r") as changelog_file:
                lines = changelog_file.readlines()

        with open(self.file_name, "w") as changelog_file:
            if self.incremental:
                new_lines = changelog.incremental_build(
                    changelog_out, lines, changelog_meta)
                changelog_file.writelines(new_lines)
            else:
                changelog_file.write(changelog_out)
Exemplo n.º 4
0
    def __call__(self):
        commit_parser = self.cz.commit_parser
        changelog_pattern = self.cz.changelog_pattern
        start_rev = self.start_rev
        unreleased_version = self.unreleased_version
        changelog_meta: Dict = {}
        change_type_map: Optional[Dict] = self.change_type_map
        changelog_message_builder_hook: Optional[
            Callable] = self.cz.changelog_message_builder_hook
        changelog_hook: Optional[Callable] = self.cz.changelog_hook

        if not changelog_pattern or not commit_parser:
            out.error(
                f"'{self.config.settings['name']}' rule does not support changelog"
            )
            raise SystemExit(NO_PATTERN_MAP)

        tags = git.get_tags()
        if not tags:
            tags = []

        if self.incremental:
            changelog_meta = changelog.get_metadata(self.file_name)
            latest_version = changelog_meta.get("latest_version")
            if latest_version:
                start_rev = self._find_incremental_rev(latest_version, tags)

        commits = git.get_commits(start=start_rev, args="--author-date-order")
        if not commits:
            out.error("No commits found")
            raise SystemExit(NO_COMMITS_FOUND)

        tree = changelog.generate_tree_from_commits(
            commits,
            tags,
            commit_parser,
            changelog_pattern,
            unreleased_version,
            change_type_map=change_type_map,
            changelog_message_builder_hook=changelog_message_builder_hook,
        )
        changelog_out = changelog.render_changelog(tree)
        changelog_out = changelog_out.lstrip("\n")

        if self.dry_run:
            out.write(changelog_out)
            raise SystemExit(0)

        lines = []
        if self.incremental and os.path.isfile(self.file_name):
            with open(self.file_name, "r") as changelog_file:
                lines = changelog_file.readlines()

        with open(self.file_name, "w") as changelog_file:
            partial_changelog: Optional[str] = None
            if self.incremental:
                new_lines = changelog.incremental_build(
                    changelog_out, lines, changelog_meta)
                changelog_out = "".join(new_lines)
                partial_changelog = changelog_out

            if changelog_hook:
                changelog_out = changelog_hook(changelog_out,
                                               partial_changelog)
            changelog_file.write(changelog_out)
 def __call__(
     self,
     chlog_path,
     latest_version,
     start_rev=None,
     incremental=False,
     dry_run=False,
     change_type_map=None,
 ):
     """
     :param start_rev: If None, changelog from beginning
     """
     # THE FOLLOWING CODE DOESN'T HAVE SIDE EFFECTS TO FILESYS OR GIT:
     commit_parser = self.cz.commit_parser
     changelog_pattern = self.cz.changelog_pattern
     changelog_meta = {}
     changelog_message_builder_hook = self.cz.changelog_message_builder_hook
     changelog_hook = self.cz.changelog_hook
     if not changelog_pattern or not commit_parser:
         raise NoPatternMapError(
             f"'{self.commiter_name}' rule doesn't support changelog")
     #
     tags = git.get_tags()
     if not tags:
         tags = []
     #
     if incremental:
         changelog_meta = changelog.get_metadata(chlog_path)
         latest_version = changelog_meta.get("latest_version")
         if latest_version:
             start_rev = self._find_incremental_rev(latest_version, tags)
     #
     commits = git.get_commits(start=start_rev, args="--author-date-order")
     if not commits:
         raise NoCommitsFoundError("No commits found")
     #
     tree = changelog.generate_tree_from_commits(
         commits,
         tags,
         commit_parser,
         changelog_pattern,
         latest_version,
         change_type_map=change_type_map,
         changelog_message_builder_hook=changelog_message_builder_hook,
     )
     changelog_out = changelog.render_changelog(tree)
     changelog_out = changelog_out.lstrip("\n")
     #
     if dry_run:
         out.write(changelog_out)
         raise DryRunExit()
     #
     # CHANGES TO FILESYSTEM: WRITE TO CHLOG_PATH (AFTER READING)
     lines = []
     if incremental and os.path.isfile(chlog_path):
         with open(chlog_path, "r") as changelog_file:
             lines = changelog_file.readlines()
     #
     with open(chlog_path, "w") as changelog_file:
         partial_changelog = None
         if incremental:
             new_lines = changelog.incremental_build(
                 changelog_out, lines, changelog_meta)
             changelog_out = "".join(new_lines)
             partial_changelog = changelog_out
         if changelog_hook:
             changelog_out = changelog_hook(changelog_out,
                                            partial_changelog)
         changelog_file.write(changelog_out)
         out.write(f"Wrote changelog to {chlog_path}!\n")
Exemplo n.º 6
0
    def __call__(self):
        commit_parser = self.cz.commit_parser
        changelog_pattern = self.cz.changelog_pattern
        start_rev = self.start_rev
        unreleased_version = self.unreleased_version
        changelog_meta: Dict = {}
        change_type_map: Optional[Dict] = self.change_type_map
        changelog_message_builder_hook: Optional[
            Callable
        ] = self.cz.changelog_message_builder_hook

        if not changelog_pattern or not commit_parser:
            raise NoPatternMapError(
                f"'{self.config.settings['name']}' rule does not support changelog"
            )

        if self.incremental and self.rev_range:
            raise NotAllowed("--incremental cannot be combined with a rev_range")

        tags = git.get_tags()
        if not tags:
            tags = []

        end_rev = ""

        if self.incremental:
            changelog_meta = changelog.get_metadata(self.file_name)
            latest_version = changelog_meta.get("latest_version")
            if latest_version:
                start_rev = self._find_incremental_rev(latest_version, tags)

        if self.rev_range and self.tag_format:
            start_rev, end_rev = changelog.get_oldest_and_newest_rev(
                tags,
                version=self.rev_range,
                tag_format=self.tag_format,
            )

        commits = git.get_commits(
            start=start_rev, end=end_rev, args="--author-date-order"
        )
        if not commits:
            raise NoCommitsFoundError("No commits found")

        tree = changelog.generate_tree_from_commits(
            commits,
            tags,
            commit_parser,
            changelog_pattern,
            unreleased_version,
            change_type_map=change_type_map,
            changelog_message_builder_hook=changelog_message_builder_hook,
        )
        if self.change_type_order:
            tree = changelog.order_changelog_tree(tree, self.change_type_order)
        changelog_out = changelog.render_changelog(tree)
        changelog_out = changelog_out.lstrip("\n")

        if self.dry_run:
            out.write(changelog_out)
            raise DryRunExit()

        lines = []
        if self.incremental and os.path.isfile(self.file_name):
            with open(self.file_name, "r") as changelog_file:
                lines = changelog_file.readlines()

        self.write_changelog(changelog_out, lines, changelog_meta)