Skip to content
Snippets Groups Projects
Commit 504c9ed0 authored by nimrod's avatar nimrod
Browse files

git-manage: Refactor archive_repo.

Address pylint warnings. Make a clear seperation of GitHub and GitLab
repo handling. Don't try to create a GitHub connection if there are no
GitHub mirrors.
parent 7f676ac1
Branches
No related tags found
No related merge requests found
...@@ -345,37 +345,43 @@ def archive_repo(args): ...@@ -345,37 +345,43 @@ def archive_repo(args):
Does the following: Does the following:
- Archives the repository (sets it to read-only). - Archives the repository (sets it to read-only).
- Archives all GitHub mirrors. - Archives all GitHub mirrors (for a GitLab project).
""" """
if args.github:
try: try:
gh_conn = rcfiles.github.connect() gh_conn = rcfiles.github.connect()
except Exception as e: # pylint: disable=broad-except except Exception as e: # pylint: disable=broad-except
error(f"Failed to connect to GitHub: {e}") error(f"Failed to connect to GitHub: {e}")
if not args.github:
try:
gl_conn = rcfiles.gitlab.connect()
except Exception as e: # pylint: disable=broad-except
error(f"Failed to connect to GitLab: {e}")
if args.github:
owner, name = guess_name(args, gh_conn=gh_conn, gl_conn=None).split( owner, name = guess_name(args, gh_conn=gh_conn, gl_conn=None).split(
"/" "/"
) )
else:
name = guess_name(args, gh_conn=None, gl_conn=gl_conn)
if args.github:
repo = gh_conn.repository(owner, name) repo = gh_conn.repository(owner, name)
repo.edit(name, archived=True) repo.edit(name, archived=True)
print(f"Archived repository {repo.html_url}.", file=sys.stderr) print(f"Archived repository {repo.html_url}.", file=sys.stderr)
else: else:
try:
gl_conn = rcfiles.gitlab.connect()
except Exception as e: # pylint: disable=broad-except
error(f"Failed to connect to GitLab: {e}")
name = guess_name(args, gh_conn=None, gl_conn=gl_conn)
project = gl_conn.projects.get(name) project = gl_conn.projects.get(name)
project.archive() project.archive()
print(f"Archived repository {project.web_url}.", file=sys.stderr) print(f"Archived repository {project.web_url}.", file=sys.stderr)
# Archive the GitHub mirrors if there are any.
remotes = rcfiles.git.get_all_remotes()
if len(remotes) > 1 and any(
map(lambda x: "github.com" in x["url"], remotes.values())
):
try:
gh_conn = rcfiles.github.connect()
except Exception as e: # pylint: disable=broad-except
error(f"Failed to connect to GitHub: {e}")
for mirror in github_mirrors(project, gh_conn): for mirror in github_mirrors(project, gh_conn):
mirror.edit(mirror.name, archived=True) mirror.edit(mirror.name, archived=True)
print( print(
f"Archived GitHub mirror {mirror.html_url}.", file=sys.stderr f"Archived GitHub mirror {mirror.html_url}.",
file=sys.stderr,
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment