Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement unarchiving one or many repositories #69

Merged
3 commits merged into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 62 additions & 2 deletions src/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,33 @@ def repositories_archive(
token: str,
) -> None:
"""Archive a repository"""
click.echo(repositories.archive(organization, token, repository))
click.echo(repositories.archive(organization, token, repository, archive=True))


@repositories_cli.command("unarchive")
@click.option(
"-r",
"--repository",
prompt="Repository name",
)
@click.option(
"-t",
"--token",
prompt=False,
type=str,
default=None,
hide_input=True,
confirmation_prompt=False,
show_envvar=True,
)
@click.option("-o", "--organization", prompt="Organization name", type=str)
def repositories_unarchive(
repository: str,
organization: str,
token: str,
) -> None:
"""Unarchive a repository"""
click.echo(repositories.archive(organization, token, repository, archive=False))


#########
Expand Down Expand Up @@ -1205,13 +1231,47 @@ def mass_archive(
click.echo(f"{repo}...", nl=False)

if repositories.archive(
organization=organization, token=token, repository=repo
organization=organization, token=token, repository=repo, archive=True
):
click.echo(" Archived.")
else:
click.echo(" Not Archived.", err=True)


@mass_cli.command("unarchive")
@click.argument("input_repos_list", type=click.File("r"))
@click.option(
"-t",
"--token",
prompt=False,
type=str,
default=None,
hide_input=True,
confirmation_prompt=False,
show_envvar=True,
)
@click.option("-o", "--organization", prompt="Organization name", type=str)
def mass_unarchive(
input_repos_list: Any,
organization: str,
token: str,
) -> None:
repos_list = input_repos_list.readlines()

for repo in repos_list:

repo = repo.rstrip("\n")

click.echo(f"{repo}...", nl=False)

if repositories.archive(
organization=organization, token=token, repository=repo, archive=False
):
click.echo(" Unarchived.")
else:
click.echo(" Not Unarchived.", err=True)


@mass_cli.command("issue_upcoming_archive")
@click.argument("input_repos_list", type=click.File("r"))
@click.option(
Expand Down
6 changes: 4 additions & 2 deletions src/ghas_cli/utils/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,12 @@ def get_default_branch_last_updated(
)


def archive(organization: str, token: str, repository: str) -> bool:
def archive(
organization: str, token: str, repository: str, archive: bool = True
) -> bool:
headers = network.get_github_headers(token)

payload = {"archived": True}
payload = {"archived": archive}

status = network.patch(
url=f"https://api.github.com/repos/{organization}/{repository}",
Expand Down