Commit 08337780 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

style: fix code formatting

parent d96f9120
Loading
Loading
Loading
Loading
+45 −18
Original line number Diff line number Diff line
@@ -161,14 +161,19 @@ class Synchronizer:

    def is_tag_equal(self, tag1: ProjectTag, tag2: ProjectTag) -> bool:
        # Compare tag by its 'name', 'target' and 'message'
        return all([getattr(tag1, attr) == getattr(tag2, attr) for attr in ['name', 'target', 'message']])
        return all(
            [
                getattr(tag1, attr) == getattr(tag2, attr)
                for attr in ["name", "target", "message"]
            ]
        )

    def is_branch_equal(self, branch1: ProjectBranch, branch2: ProjectBranch) -> bool:
        # Compare tag by its 'name', 'protected' and 'commit.id'
        return (
            branch1.name == branch2.name
            and branch1.protected == branch2.protected
            and branch1.commit['id'] == branch2.commit['id']
            and branch1.commit["id"] == branch2.commit["id"]
        )

    def is_branch_selected(self, branch: ProjectBranch, default_branch: str) -> bool:
@@ -188,9 +193,7 @@ class Synchronizer:
        dest_project: Project,
    ) -> None:
        if self.skip_releases:  # If the flag is enabled, do not synchronize releases
            print(
                f"    - releases: {AnsiColors.HGRAY}skipped{AnsiColors.RESET}"
            )
            print(f"    - releases: {AnsiColors.HGRAY}skipped{AnsiColors.RESET}")
            return
        src_releases = src_project.releases.list(all=True)
        print(f"    - sync {len(src_releases)} releases...")
@@ -260,7 +263,11 @@ class Synchronizer:
    def sync_git_repo(self, src_project: Project, dest_project: Project) -> None:
        ## Prepare 1: get remote branches
        try:
            src_branches = {branch: branch for branch in src_project.branches.list(iterator=True) if self.is_branch_selected(branch, src_project.default_branch)}
            src_branches = {
                branch: branch
                for branch in src_project.branches.list(iterator=True)
                if self.is_branch_selected(branch, src_project.default_branch)
            }
        except GitlabListError as ge:
            print(
                f"    - branches from source repo: get {AnsiColors.HRED}failed{AnsiColors.RESET}",
@@ -270,7 +277,9 @@ class Synchronizer:
            return

        try:
            dest_branches = {branch: branch for branch in dest_project.branches.list(iterator=True)}
            dest_branches = {
                branch: branch for branch in dest_project.branches.list(iterator=True)
            }
        except GitlabListError as ge:
            print(
                f"    - branches from dest repo: get {AnsiColors.HRED}failed{AnsiColors.RESET}",
@@ -308,9 +317,15 @@ class Synchronizer:
        # 4: Exit if already up-to-date
        if (
            set(src_tags) <= set(dest_tags)  # All source tags are in dest
            and set(src_branches) <= set(dest_branches) # All source branches are in dest
            and all(self.is_tag_equal(src_tag, dest_tags[src_tag]) for src_tag in src_tags) # All source tags are equal to dest tags
            and all(self.is_branch_equal(src_branch, dest_branches[src_branch]) for src_branch in src_branches) # All source branches are equal to dest branches
            and set(src_branches)
            <= set(dest_branches)  # All source branches are in dest
            and all(
                self.is_tag_equal(src_tag, dest_tags[src_tag]) for src_tag in src_tags
            )  # All source tags are equal to dest tags
            and all(
                self.is_branch_equal(src_branch, dest_branches[src_branch])
                for src_branch in src_branches
            )  # All source branches are equal to dest branches
        ):
            # Git sync is not required: skip
            print(
@@ -330,11 +345,16 @@ class Synchronizer:
                    ),
                    None,
                )
                if src_release and src_release.commit['id'] != dest_release.commit['id']:
                    e = AssertionError(f"tag hash mismatch ({src_release.commit['id']} != {dest_release.commit['id']})")
                if (
                    src_release
                    and src_release.commit["id"] != dest_release.commit["id"]
                ):
                    e = AssertionError(
                        f"tag hash mismatch ({src_release.commit['id']} != {dest_release.commit['id']})"
                    )
                    print(
                        f"    - release {tag_name}: force update {AnsiColors.HRED}denied{AnsiColors.RESET}",
                        e
                        e,
                    )
                    self.handle_error(e)
                    return
@@ -378,7 +398,9 @@ class Synchronizer:
            try:
                for branch in dest_branches.keys() & src_branches.keys():
                    # Only if branch divergence detected
                    if not self.is_branch_equal(src_branches[branch], dest_branches[branch]):
                    if not self.is_branch_equal(
                        src_branches[branch], dest_branches[branch]
                    ):
                        dest_project.protectedbranches.delete(branch.name)
            except GitlabDeleteError as ge:
                if ge.response_code != 404:
@@ -404,7 +426,9 @@ class Synchronizer:
        try:
            dest = repo.create_remote("dest", dest_repo_url)
            dest.push(
                refspec=[branch.name for branch in src_branches], #List of branches to push
                refspec=[
                    branch.name for branch in src_branches
                ],  # List of branches to push
                force=True,
                tags=True,
                allow_unsafe_options=True,
@@ -419,7 +443,10 @@ class Synchronizer:

        # protect branches
        for branch in src_branches:
            if branch.protected and (branch not in dest_branches or not self.is_branch_equal(branch, dest_branches[branch])):
            if branch.protected and (
                branch not in dest_branches
                or not self.is_branch_equal(branch, dest_branches[branch])
            ):
                try:
                    dest_project.protectedbranches.create({"name": branch.name})
                except GitlabCreateError as ge:
+1 −1

File changed.

Contains only whitespace changes.

+1 −1

File changed.

Contains only whitespace changes.

+1 −1

File changed.

Contains only whitespace changes.