Skip to content

Instantly share code, notes, and snippets.

@KyleJamesWalker
Last active October 26, 2018 19:25
Show Gist options
  • Save KyleJamesWalker/310a17bb27eba079ae8f670edbcd462f to your computer and use it in GitHub Desktop.
Save KyleJamesWalker/310a17bb27eba079ae8f670edbcd462f to your computer and use it in GitHub Desktop.
GitHub PR Review Lookup
#!/usr/bin/env python
# coding: utf-8
"""Find your PRs
Builds a list of PRs you've worked on over the last xxx (year, month, week)
Example Web Search (https://github.com/pulls):
* `is:pr author:a created:>2017-11-01`
* `is:pr mentions:kylejameswalker commenter:kylejameswalker created:>2017-11-01`
Example run:
* `python ~/work/my_prs.py kylejameswalker 2017-11-01`
"""
import argparse
import os
from github import Github
from textwrap import dedent
def get_reviews(client, author, created_after, creator=True):
"""Get GitHub PR Details."""
reviews = client.search_issues(
"is:pr author:{} {} created:>{}".format(
author,
"" if creator else "mentions:{} commenter:{}".format(
author, author
),
created_after,
)
)
return [
dedent("""
Review in {}:
Title: {}
Created by: {}
Created At: {}
Closed On: {}
Commenters: {}
""".format(
x.repository.name,
x.title,
x.user.login,
x.created_at,
x.closed_at,
set(x.user.login for x in x.get_comments()),
)) for x in reviews
]
def main():
parser = argparse.ArgumentParser(
description="GitHub PR Review Overview",
)
parser.add_argument("reviewer", help="Who would you like to review?")
parser.add_argument("since_when", help="How far back would to search?")
args = parser.parse_args()
g = Github(os.environ['GITHUB_ACCESS_TOKEN'])
print("{}'s Reviews:".format(args.reviewer))
reviews = get_reviews(g, args.reviewer, args.since_when)
print("Discovered a total of {} reviews by {}".format(
len(reviews), args.reviewer,
))
print("\n".join(reviews))
print("Review Interactions:")
reviews = get_reviews(g, args.reviewer, args.since_when, False)
print("Discovered a total of {} reviews interactions from {}".format(
len(reviews), args.reviewer,
))
print("\n".join(reviews))
if __name__ == '__main__':
main()
#!/usr/bin/env python
# coding: utf-8
"""Quick Review Script
Builds a list of PRs within a GitHub that have interactions between two users.
Example Web Search (https://github.com/pulls):
* `is:pr author:a mentions:b created:>2017-11-01`
* `is:pr author:b mentions:a created:>2017-11-01`
Example run:
* `python ~/work/pr_reviews.py exampleuser kylejameswalker 2017-11-01`
"""
import argparse
import os
from github import Github
from textwrap import dedent
def get_reviews(client, author, mentions, created_after):
"""Get GitHub PR Details."""
reviews = client.search_issues(
"is:pr author:{} mentions:{} created:>{}".format(
author, mentions, created_after,
)
)
return [
dedent("""
Review in {}:
Title: {}
Created At: {}
Closed On: {}
Commenters: {}
""".format(
x.repository.name,
x.title,
x.created_at,
x.closed_at,
set(x.user.login for x in x.get_comments()),
)) for x in reviews
]
def main():
parser = argparse.ArgumentParser(
description="GitHub PR Review Overview",
)
parser.add_argument("reviewer", help="Who would you like to review?")
parser.add_argument("who_are_you", help="Your GitHub account name.")
parser.add_argument("since_when", help="How far back would to search?")
args = parser.parse_args()
g = Github(os.environ['GITHUB_ACCESS_TOKEN'])
print("Reviews Created by {} with myself mentioned:".format(
args.reviewer,
))
reviews = get_reviews(g, args.reviewer, args.who_are_you, args.since_when)
print("Discovered a total of {} reviews by {}".format(
len(reviews), args.reviewer,
))
print("\n".join(reviews))
print("Reviews Created by {} with myself mentioned:".format(
args.who_are_you,
))
reviews = get_reviews(g, args.who_are_you, args.reviewer, args.since_when)
print("Discovered a total of {} reviews with {}".format(
len(reviews), args.reviewer,
))
print("\n".join(reviews))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment