Skip to content

Instantly share code, notes, and snippets.

@cthoyt
Created March 3, 2023 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cthoyt/2c82bb08f03c66b3b99cfd848624a95c to your computer and use it in GitHub Desktop.
Save cthoyt/2c82bb08f03c66b3b99cfd848624a95c to your computer and use it in GitHub Desktop.
As a follow-up to https://gist.github.com/cthoyt/95694a05190fc23b997fae62f12f96f1, this gist pings all repositories that haven't responded yet.
import time
import pystow
import requests
from bioregistry.external import get_obofoundry
from tqdm.auto import tqdm
TOKEN = pystow.get_config("github", "token")
TEXT_FORMAT = """\
Hi @{handle}, this is an automated message. On June 8th, 2021 (almost 2 years ago),\
I posted this issue using another automated script in hopes that someone would\
be responsive on this repository and then be able to add a tag to this repository's\
metadata. This is regarding https://github.com/OBOFoundry/OBOFoundry.github.io/issues/1538.
Because it's been so long without addressing the issue, I am concerned\
that this repository is no longer responsive/being maintained. Can you please\
let me know if that's the case? In a few months,\
if this follow-up message goes unanswered, I will recommend to\
the OBO Foundry to change the status of this ontology to either "inactive"\
or "orphaned", meaning that the nominal contact person is no longer responsive\
and/or the repository is no longer maintained.
Given one of the OBO Foundry's principles is about responsiveness\
(see https://obofoundry.org/principles/fp-020-responsiveness.html), it is\
important that we are transparent to the community about the status of each\
resource so potential users can make the best choice of which resources to\
use.
Finally, please let me know if there are any questions about how to add the\
"obofoundry" topic tag to this repository.
"""
def get_issues():
res_json = requests.get(
"https://api.github.com/search/issues",
params={
"q": "Add obofoundry topic to repo metadata -user:obofoundry",
"per_page": 100,
},
headers={
"Accept": "application/vnd.github.mercy-preview+json",
"Authorization": f"token {TOKEN}",
},
).json()
items = res_json["items"]
items = [item for item in items if item["state"] == "open"]
return items
def get_githubs():
# Get mapping from repository to responsible person's github handle
githubs = {}
deprecated = {}
for prefix, record in get_obofoundry().items():
deprecated[prefix] = record.get("deprecated") or False
if deprecated[prefix]:
continue
repo = record.get("repository")
if not repo.startswith("https://github.com/"):
continue
handle = record.get("contact.github")
if not handle:
tqdm.write(f"[{prefix}] missing handle from {repo}.")
continue
repo = repo.removeprefix("https://github.com/").rstrip("/")
githubs[repo.lower()] = handle
return githubs, deprecated
def main():
items = get_issues()
githubs, deprecated = get_githubs()
for item in tqdm(items):
parts = (
item["url"].removeprefix("https://api.github.com/repos/").rsplit("/", 2)[0]
)
handle = githubs.get(parts.lower())
if handle is None:
if parts not in deprecated:
pass
else:
tqdm.write(f"Failed to get contact for {parts}")
continue
res_json = requests.post(
item["url"] + "/comments",
json={
"body": TEXT_FORMAT.format(handle=handle),
},
headers={
"Accept": "application/vnd.github+json",
"Authorization": f"token {TOKEN}",
},
).json()
tqdm.write(f"Posted to {res_json['url']}")
time.sleep(2)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment