Skip to content

Instantly share code, notes, and snippets.

@Jackenmen
Created November 5, 2021 14:57
Show Gist options
  • Save Jackenmen/296f6c2a7dbf0acf155f7f2542536afa to your computer and use it in GitHub Desktop.
Save Jackenmen/296f6c2a7dbf0acf155f7f2542536afa to your computer and use it in GitHub Desktop.
"""A way to get all GH contributors by diffing tags alone, without using release milestone."""
import subprocess
GET_PR_HISTORY_QUERY = """
query getPRHistory(
$owner: String!
$name: String!
$tag_name: String!
$after: String
$since: GitTimestamp!
) {
repository(owner: $owner, name: $name) {
ref(qualifiedName: $tag_name) {
target {
... on Commit {
# querying 99 costs 1 while querying 100 costs 2
history(first: 99, after: $after, since: $since) {
nodes {
author {
email
name
user {
login
}
}
associatedPullRequests(first:1) {
nodes {
author {
login
}
latestOpinionatedReviews(first: 100, writersOnly: true) {
nodes {
author {
login
}
}
}
}
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
}
}
}
""".strip()
tag_name = "3.3.0"
previous_tag = subprocess.check_output(
("git", "describe", "--abbrev=0", "--tags", f"{tag_name}~")
)
previous_tag_date = subprocess.check_output(
("git", "tag", "-l", previous_tag, "--format", "%(creatordate:iso-strict)")
)
variables = {
"owner": "Cog-Creators",
"name": "Red-DiscordBot",
"tag_name": tag_name,
"after": None,
"since": previous_tag_date,
}
# TODO: Make GraphQL query here with the above query variables,
# and fetch all pages into `nodes` variable
authors = set()
for node in nodes:
commit_user = node["author"]["user"]
if commit_user is not None:
authors.add(commit_user["login"])
prs = node["associatedPullRequests"]["nodes"]
for pr in prs:
authors.add(pr["author"]["login"])
reviews = pr["latestOpinionatedReviews"]["nodes"]
for review in reviews:
authors.add(review["author"]["login"])
print(", ".join(map(":ghuser:`{}`".format, sorted(authors, key=str.lower))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment