[sysadmin-bin] Drop groups loop and mirror repositories with custom attribute
- From: Bartłomiej Piotrowski <bpiotrowski src gnome org>
- To: gnome-sysadmin gnome org,commits-list gnome org
- Subject: [sysadmin-bin] Drop groups loop and mirror repositories with custom attribute
- Date: Fri, 17 Jul 2020 13:21:17 +0000 (UTC)
commit 19b10d616dfe4af873630b05f68bf004980f7bb2
Author: Bartłomiej Piotrowski <bpiotrowski gnome org>
Date: Fri Jul 17 15:19:50 2020 +0200
Drop groups loop and mirror repositories with custom attribute
gitlab/mirror2github | 102 ++++++++++++++++++++++++++-------------------------
1 file changed, 53 insertions(+), 49 deletions(-)
---
diff --git a/gitlab/mirror2github b/gitlab/mirror2github
index 12cc24b..16b3807 100755
--- a/gitlab/mirror2github
+++ b/gitlab/mirror2github
@@ -29,61 +29,65 @@ def main():
gitlab_token = get_token("GITLAB_TOKEN", "gitlab_rw")
github_token = get_token("GITHUB_TOKEN", "github_rw")
- groups = ["GNOME"]
gl = gitlab.Gitlab(
"https://gitlab.gnome.org", private_token=gitlab_token, per_page=100
)
+
gh = github.Github(github_token)
gh_org = gh.get_organization("GNOME")
- for group_name in groups:
- group = gl.groups.get(group_name, lazy=True)
- projects = group.projects.list(all=True)
-
- for prj in projects:
- # Skip project if it has been migrated from GNOME group
- prj = gl.projects.get(prj.id)
- if prj.namespace["name"] != group.id:
- continue
-
- # Skip projects without git repository
- if "default_branch" not in prj.attributes:
- continue
-
- mirror_settings = {
- "description": f"Read-only mirror of {prj.web_url}",
- "homepage": prj.web_url,
- "has_issues": False,
- "has_wiki": False,
- }
-
- try:
- gh_mirror = gh_org.get_repo(prj.path)
- gh_branches = [br.name for br in gh_mirror.get_branches()]
-
- if len(gh_branches):
- if (
- prj.default_branch not in gh_branches
- and prj.default_branch != gh_mirror.default_branch
- ):
- gh_mirror.create_git_ref(
- f"refs/heads/{prj.default_branch}",
- gh_mirror.get_commit(
- f"refs/heads/{gh_mirror.default_branch}"
- ).sha,
- )
-
- gh_mirror.edit(default_branch=prj.default_branch)
-
- gh_mirror.edit(**mirror_settings)
- except UnknownObjectException:
- print(404)
- gh_mirror = gh_org.create_repo(prj.path, **mirror_settings)
-
- mirrors = prj.remote_mirrors.list(all=True, lazy=True)
- if not len(mirrors):
- ssh_url = f"ssh://git github com/GNOME/{prj.path}.git"
- prj.remote_mirrors.create({"url": ssh_url, "enabled": True})
+ group_name = "GNOME"
+ group = gl.groups.get(group_name, lazy=True)
+ projects = group.projects.list(all=True)
+
+ extra_projects = gl.projects.list(
+ custom_attributes={"enable_github_mirror": "true"}
+ )
+
+ for prj in projects + extra_projects:
+ # Skip project if it has been migrated from GNOME group
+ prj = gl.projects.get(prj.id)
+ if prj.namespace["name"] != group.id and prj not in extra_projects:
+ continue
+
+ # Skip projects without git repository
+ if "default_branch" not in prj.attributes:
+ continue
+
+ mirror_settings = {
+ "description": f"Read-only mirror of {prj.web_url}",
+ "homepage": prj.web_url,
+ "has_issues": False,
+ "has_wiki": False,
+ }
+
+ try:
+ gh_mirror = gh_org.get_repo(prj.path)
+ gh_branches = [br.name for br in gh_mirror.get_branches()]
+
+ if len(gh_branches):
+ if (
+ prj.default_branch not in gh_branches
+ and prj.default_branch != gh_mirror.default_branch
+ ):
+ gh_mirror.create_git_ref(
+ f"refs/heads/{prj.default_branch}",
+ gh_mirror.get_commit(
+ f"refs/heads/{gh_mirror.default_branch}"
+ ).sha,
+ )
+
+ gh_mirror.edit(default_branch=prj.default_branch)
+
+ gh_mirror.edit(**mirror_settings)
+ except UnknownObjectException:
+ print(404)
+ gh_mirror = gh_org.create_repo(prj.path, **mirror_settings)
+
+ mirrors = prj.remote_mirrors.list(all=True, lazy=True)
+ if not len(mirrors):
+ ssh_url = f"ssh://git github com/GNOME/{prj.path}.git"
+ prj.remote_mirrors.create({"url": ssh_url, "enabled": True})
if __name__ == "__main__":
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]