feat: archive repos by regex (#54)

This commit is contained in:
mQzLjP 2025-05-17 08:04:44 +08:00 committed by GitHub
parent 183f4267de
commit 396329f4b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 10 deletions

View File

@ -36,9 +36,9 @@ pytest -svv
## Commands & Features
### `archive-all-repos`
### `archive-repos`
archive all repos in gitea organization
archive repos in gitea organization according to regex (dry-run enabled by default)
### `unwatch-all-repos`

View File

@ -141,9 +141,11 @@ def close_all_issues() -> None:
tea.pot.gitea.close_all_issues()
@app.command("archive-all-repos", help="archive all repos in gitea organization")
def archive_all_repos() -> None:
tea.pot.gitea.archive_all_repos()
@app.command(
"archive-repos", help="archive repos in gitea organization according to regex"
)
def archive_repos(regex: str = Argument(".+"), dry_run: bool = Option(True)) -> None:
tea.pot.gitea.archive_repos(regex, dry_run)
@app.command("unwatch-all-repos", help="unwatch all repos in gitea organization")

View File

@ -413,10 +413,16 @@ class Gitea:
self.org_name, repo_name, issue.number, body={"state": "closed"}
)
def archive_all_repos(self) -> None:
for repo in list_all(self.organization_api.org_list_repos, self.org_name):
def archive_repos(self, regex: str = ".+", dry_run: bool = True) -> None:
if dry_run:
logger.info("Dry run enabled. No changes will be made to the repositories.")
logger.info(f"Archiving repos with name matching {regex}")
for repo_name in self.get_all_repo_names():
if re.match(regex, repo_name):
logger.info(f"Archived {repo_name}")
if not dry_run:
self.repository_api.repo_edit(
self.org_name, repo.name, body={"archived": True}
self.org_name, repo_name, body={"archived": True}
)
def unwatch_all_repos(self) -> None: