diff --git a/src/cli.py b/src/cli.py index 94e4a4c..eb381c3 100644 --- a/src/cli.py +++ b/src/cli.py @@ -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)) ######### @@ -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( diff --git a/src/ghas_cli/utils/repositories.py b/src/ghas_cli/utils/repositories.py index fd7ce31..6830f5f 100644 --- a/src/ghas_cli/utils/repositories.py +++ b/src/ghas_cli/utils/repositories.py @@ -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}",