Skip to content

Instantly share code, notes, and snippets.

@yelizariev
Last active April 12, 2017 07:52
Show Gist options
  • Save yelizariev/3d5152df5226d03f8bcea08ece939e9a to your computer and use it in GitHub Desktop.
Save yelizariev/3d5152df5226d03f8bcea08ece939e9a to your computer and use it in GitHub Desktop.
'''
# Installation:
sudo pip install PyGithub
# create token here: https://github.com/settings/tokens (you don't need to set any access checkboxes there)
# Usage
curl -s https://gist.githubusercontent.com/yelizariev/3d5152df5226d03f8bcea08ece939e9a/raw/pull-requests-portfolio.py | python - --token=ABCDE \
"https://github.com/it-projects-llc/access-addons/pull/26" \
"https://github.com/it-projects-llc/access-addons/pull/21" \
"https://github.com/it-projects-llc/website-addons/pull/53" \
| gedit
'''
import re
import argparse
from github import Github
html_container = '''
<section class="mb16">
<div class="container">
<div class="row mt16 mb16">
%s
</div>
</div>
</section>
'''
html_item = '''
<div class="col-md-4">
<span class="branch-action-icon {merged}">
<svg aria-hidden="true" class="octicon octicon-git-branch" height="32" version="1.1" viewBox="0 0 10 16" width="20"><path d="M10 5c0-1.11-.89-2-2-2a1.993 1.993 0 0 0-1 3.72v.3c-.02.52-.23.98-.63 1.38-.4.4-.86.61-1.38.63-.83.02-1.48.16-2 .45V4.72a1.993 1.993 0 0 0-1-3.72C.88 1 0 1.89 0 3a2 2 0 0 0 1 1.72v6.56c-.59.35-1 .99-1 1.72 0 1.11.89 2 2 2 1.11 0 2-.89 2-2 0-.53-.2-1-.53-1.36.09-.06.48-.41.59-.47.25-.11.56-.17.94-.17 1.05-.05 1.95-.45 2.75-1.25S8.95 7.77 9 6.73h-.02C9.59 6.37 10 5.73 10 5zM2 1.8c.66 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2C1.35 4.2.8 3.65.8 3c0-.65.55-1.2 1.2-1.2zm0 12.41c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zm6-8c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2z"></path></svg>
</span>
<h4 class="mt8 mb0 fix-height">{title}</h3>
<h3 class="mt8 mb0"><a href="{url}">{url_title}</a></h3>
</div>
'''
css = '''
<style type="text/css">
.branch-action-icon {
float: left;
width: 100px;
height: 100px;
padding: 6px;
margin-left: -60px;
color: #fff;
text-align: center;
border-radius: 3px;
background-color: #6cc644;
margin: 0 16px 16px 0;
}
h4.fix-height{
overflow: hidden;
max-height: 2.1em;
}
.branch-action-icon.merged {
background-color: #6e5494;
}
</style>
'''
parser = argparse.ArgumentParser(description='Portfolio generator')
parser.add_argument('--token')
parser.add_argument('prs', nargs='+')
args = parser.parse_args()
def files2modules(files):
files = files or []
files = [f.filename for f in files]
files = [f.split('/')[0] for f in files]
return set(files)
def main():
prs = args.prs
g = Github(args.token)
html = [css]
for pr_url in prs:
repo_name, pull_num = re.match(r"https://github.com/(.*)/pull/([0-9]*)", pr_url).groups()
repo = g.get_repo(repo_name)
pull = repo.get_pull(int(pull_num))
url = pr_url
# state = pull.state
merged = pull.merged
modules = ', '.join(files2modules(pull.get_files()))
version = pull.base.ref
html.append(html_item.format(
merged=merged and 'merged' or '',
title='[%s] %s' % (version, modules),
url=url,
url_title='%s#%s' % (repo_name, pull_num),
))
html = '\n'.join(html)
html = html_container % html
print html
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment