Exemple #1
0
    def from_commit(commit: git.Commit, patch_path: Path):
        metadata = get_metadata_from_message(commit) or {}
        if metadata:
            logger.debug(f"Commit {commit.hexsha:.8} metadata:\n"
                         f"{yaml.dump(metadata, indent=4)}")
        else:
            logger.debug(
                f"Commit {commit.hexsha:.8} does not contain any metadata.")

        name = metadata.get("patch_name")
        if name:
            new_path = patch_path.parent / name
            logger.debug(
                f"Renaming the patch: {patch_path.name} -> {new_path}")
            patch_path.rename(new_path)
            patch_path = new_path
        else:
            name = patch_path.name

        return PatchMetadata(
            name=name,
            path=patch_path,
            description=metadata.get("description"),
            present_in_specfile=metadata.get("present_in_specfile"),
            location_in_specfile=metadata.get("location_in_specfile"),
            ignore=metadata.get("ignore"),
            commit=commit,
        )
Exemple #2
0
    def from_commit(commit: git.Commit,
                    patch_path: Optional[Path] = None) -> "PatchMetadata":
        """
        Load PatchMetadata from an existing git.Commit

        @param commit: the git.Commit to load the metadata from
        @param patch_path: optional Path to an existing patch file present on the disk
        @return: PatchMetadata instance
        """
        metadata = get_metadata_from_message(commit) or {}
        metadata_defined = False
        if metadata:
            logger.debug(
                f"Commit {commit.hexsha:.8} metadata:\n"
                f"{yaml.dump(metadata, indent=4, default_flow_style=False)}")
            metadata_defined = True
        else:
            logger.debug(
                f"Commit {commit.hexsha:.8} does not contain any metadata.")

        name = metadata.get("patch_name")
        if patch_path:
            if name:
                new_path = patch_path.parent / name
                logger.debug(
                    f"Renaming the patch: {patch_path.name} -> {new_path}")
                patch_path.rename(new_path)
                patch_path = new_path
            else:
                name = patch_path.name

        return PatchMetadata(
            name=name,
            path=patch_path,
            description=metadata.get("description"),
            present_in_specfile=metadata.get("present_in_specfile"),
            location_in_specfile=metadata.get("location_in_specfile"),
            ignore=metadata.get("ignore"),
            commit=commit,
            squash_commits=metadata.get("squash_commits"),
            no_prefix=metadata.get("no_prefix"),
            metadata_defined=metadata_defined,
        )
Exemple #3
0
def test_get_metadata_from_message(source, result):
    assert get_metadata_from_message(commit=flexmock(message=source)) == result