[{"element_type":"text","content":"\n        \u003cp\u003eOver the years I've been using github, and especially while I've been working with Adafruit, I have quite the collection of forked repositories on github. Most of them haven't been updated in years. I decided that I wanted to archive all my forks that hadn't been updated in the last 2 years—over 200 repositories. This would take a long time manually on the github website, so I wrote a script to do it instead.\u003c/p\u003e\n\u003cp\u003eTo use the script (included below), you'll need to\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eCreate an authorization token for your github account. It needs access to \u003cstrong\u003eall\u003c/strong\u003e your repositories to perform \u003cstrong\u003eadministration\u003c/strong\u003e tasks. You can create a \"fine grained\" token \u003ca href=\"https://github.com/settings/tokens?type=beta\"\u003ewithin your user's settings on github\u003c/a\u003e.\u003c/li\u003e\n\u003cli\u003eEdit the script to set the correct \u003cstrong\u003eowner_name\u003c/strong\u003e and \u003cstrong\u003etoken\u003c/strong\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eNext, run the script once in the terminal. It'll print a line for each repository it will archive. If the list looks correct, then uncomment the \"repo.edit\" line and run the script a second time. This will actually archive the repositories.\u003c/p\u003e\n      ","metadata":{}},{"element_type":"text","content":"\n  \n  \n  \n  \n        \u003cp\u003eThese images show the permissions you need to give the token created for this purpose. They reflect github's web UI in early 2024:\u003c/p\u003e\n      \n\n\n\n","metadata":{}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/000/626/original/ksnip_20240113-100848.png?1705162291","metadata":{"caption":""}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/000/627/original/ksnip_20240113-100903.png?1705162308","metadata":{"caption":""}},{"element_type":"code","content":"import datetime\n\nfrom github import Github\nfrom github import Auth\n\nactivity_limit = datetime.datetime.now(tz=datetime.timezone.utc) - datetime.timedelta(days=2*365)\nowner_name=\"jepler\"\ntoken = \"github_pat_.....\"\n\nauth = Auth.Token(token)\n\ng = Github(auth=auth)\n\nprint(f\"Archive repositories not active since {activity_limit}\")\nto_archive = []\nfor repo in g.get_user(owner_name).get_repos():\n    if repo.archived: continue\n    if repo.owner.login != owner_name: continue\n    if not repo.fork: continue\n    if repo.updated_at \u003c activity_limit:\n        print(f\"A {repo.name} {repo.updated_at}\")\n        to_archive.append(repo)\n        ### To actually do something, uncomment the following line:\n        # repo.edit(archived=True)","metadata":{"language":"auto","linenums":false}}]