Skip to content

Commit

Permalink
git add release/annotate_pr.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mpenkov committed Dec 30, 2020
1 parent 29e4e68 commit 36327f5
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions release/annotate_pr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Helper script for including change log entries in an open PR.
Automatically constructs the change log entry from the PR title.
Copies the entry to the window manager clipboard.
Opens the change log belonging to the specific PR in a browser window.
All you have to do is paste and click "commit changes".
"""
import json
import sys
import webbrowser

import smart_open


def copy_to_clipboard(text):
try:
import pyperclip
except ImportError:
print('pyperclip <https://pypi.org/project/pyperclip/> is missing.', file=sys.stderr)
print('copy-paste the following text manually:', file=sys.stderr)
print('\t', text, file=sys.stderr)
else:
pyperclip.copy(text)


prid = int(sys.argv[1])
url = "https://api.github.com/repos/RaRe-Technologies/smart_open/pulls/%d" % prid
with smart_open.open(url) as fin:
prinfo = json.load(fin)

prinfo['user_login'] = prinfo['user']['login']
prinfo['user_html_url'] = prinfo['user']['html_url']
text = '- %(title)s (PR [#%(number)s](%(html_url)s), [@%(user_login)s](%(user_html_url)s))' % prinfo
copy_to_clipboard(text)

prinfo['head_repo_html_url'] = prinfo['head']['repo']['html_url']
prinfo['head_ref'] = prinfo['head']['ref']
edit_url = '%(head_repo_html_url)s/edit/%(head_ref)s/CHANGELOG.md' % prinfo
webbrowser.open(edit_url)

0 comments on commit 36327f5

Please sign in to comment.