Created
January 26, 2022 17:07
Querying author association from github
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
#!/usr/bin/env python3 | |
# Author of https://github.com/pytorch/pytorch/pull/71735 is me (malfet) | |
# And if executed with my PAT it will return my association as "MEMBER" | |
# But if executed by somebody outside of org, it will say that association is "CONTRIBUTOR" | |
# Instead of getting PAT, one can simply execute the query at https://docs.github.com/en/graphql/overview/explorer | |
GH_GET_ASSOCIATION = """ | |
query { | |
repository(owner: "pytorch", name: "pytorch") { | |
pullRequest(number: 71735) { | |
author { | |
login | |
} | |
authorAssociation | |
} | |
} | |
} | |
""" | |
def gh_graphql(query): | |
import os | |
import json | |
from urllib.request import urlopen, Request | |
token = os.getenv("GITHUB_TOKEN") | |
headers = {"Accept": "application/vnd.github.v3+json", "Authorization": f"token {token}"} | |
data = json.dumps({"query": query}).encode() | |
with urlopen(Request("https://api.github.com/graphql", data=data, headers=headers)) as conn: | |
return json.load(conn) | |
if __name__ == "__main__": | |
print(gh_graphql(GH_GET_ASSOCIATION)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment