Last active
September 5, 2018 07:09
-
-
Save brejoc/561556f7776279837715c39bb237fcbf to your computer and use it in GitHub Desktop.
saltstack_pr.py prints the pull requests, where the current user or team-suse was required to review.
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
""" | |
saltstack_pr.py prints the pull requests, where the current user | |
or team-suse was required to review. | |
""" | |
from github import Github | |
g = Github("<github-token>") | |
class bcolors: | |
HEADER = '\033[95m' | |
OKBLUE = '\033[94m' | |
OKGREEN = '\033[92m' | |
WARNING = '\033[93m' | |
FAIL = '\033[91m' | |
ENDC = '\033[0m' | |
BOLD = '\033[1m' | |
UNDERLINE = '\033[4m' | |
TEAM_SUSE_ID = 2582043 | |
ORG = "saltstack" | |
REPO_FULL_NAME = "saltstack/salt" | |
# FIXME: this is weird. Can't we do that a bit diffrent? | |
current_user = g.get_user(g.get_user().login) | |
org = g.get_organization(ORG) | |
team = org.get_team(TEAM_SUSE_ID) | |
prs_to_review = [] | |
for repo in org.get_repos(): | |
if repo.full_name == REPO_FULL_NAME: | |
for pr in repo.get_pulls(): | |
team_review_requests = pr.get_review_requests()[1] | |
user_review_requests = pr.get_review_requests()[0] | |
if current_user in user_review_requests and team in team_review_requests: | |
prs_to_review.append((pr, 1, 1)) | |
elif current_user in user_review_requests: | |
prs_to_review.append((pr, 1, 0)) | |
elif team in team_review_requests: | |
prs_to_review.append((pr, 0, 1)) | |
break | |
longest_line = max([len(dataset[0].title) for dataset in prs_to_review]) | |
for dataset in prs_to_review: | |
pr = dataset[0] | |
if "[wip]" in pr.title.lower(): | |
colour_title = bcolors.WARNING | |
else: | |
colour_title = bcolors.BOLD | |
print("{colour_title}{:<{width}}{colour_end} {colour_icons}{}{}{colour_end}".format(pr.title, | |
("👤" if dataset[1] else " "), | |
("👥" if dataset[2] else ""), | |
width=longest_line, | |
colour_title=colour_title, | |
colour_icons=bcolors.OKBLUE, | |
colour_end=bcolors.ENDC)) | |
print("🔗 {colour_url}{}{colour_end}\n".format(pr.html_url, colour_url=bcolors.OKGREEN, colour_end=bcolors.ENDC)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment