forked from flathub/flathub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to archive orphaned repos
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import datetime | ||
import os | ||
import time | ||
|
||
import github | ||
from github.GithubException import ( | ||
RateLimitExceededException, | ||
GithubException, | ||
) | ||
|
||
|
||
def main() -> None: | ||
|
||
token = os.environ["GITHUB_TOKEN"] | ||
g = github.Github(auth=github.Auth.Token(token)) | ||
|
||
org = g.get_organization("flathub") | ||
|
||
excludes = {} | ||
|
||
earliest = datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta( | ||
weeks=60 | ||
) | ||
|
||
for repo in org.get_repos(): | ||
if not repo.archived: | ||
try: | ||
default_branch = repo.default_branch | ||
branch = repo.get_branch(default_branch) | ||
last_commit = repo.get_commit(branch.commit.sha) | ||
last_commit_time = last_commit.commit.committer.date.astimezone( | ||
datetime.timezone.utc | ||
) | ||
collaborators = repo.get_collaborators(affiliation="direct") | ||
colb_count = collaborators.totalCount | ||
except GithubException: | ||
last_commit_time = datetime.datetime.now( | ||
datetime.timezone.utc | ||
) + datetime.timedelta(seconds=10) | ||
colb_count = 1 | ||
pass | ||
except RateLimitExceededException: | ||
print("Rate limited") | ||
time.sleep(g.rate_limiting_resettime - time.time() + 10) | ||
continue | ||
|
||
if colb_count == 0 and last_commit_time < earliest: | ||
print( | ||
"Archiving: {} Repo has no collaborators. Last push: {}, earlier than: {}".format( | ||
repo.html_url, | ||
last_commit_time.isoformat(), | ||
earliest.isoformat(), | ||
) | ||
) | ||
desc = "This repo is archived by Flathub as it is orphaned. If this was done in error or you wish to maintain it, please open an issue at https://github.com/flathub/flathub/issues" | ||
repo.edit(description=desc) | ||
repo.edit(archived=True) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters