Skip to content

Commit fdddf5c

Browse files
committed
release-script: handle github token to draft release
1 parent dbcc8ee commit fdddf5c

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

release.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,23 @@ def ensure_gothub_is_installed():
175175
'https://github.com/itchio/gothub !'
176176
)
177177

178+
def check_or_setup_github_OAuth_token():
179+
'''Check if github OAuth security token is set as an environment
180+
variable. If not ask for it and give instruction how to get it.
181+
The token is needed for gothub.
182+
'''
183+
if os.environ.get('GITHUB_TOKEN', None):
184+
print ('\n*** github OAuth security token found in $GITHUB_TOKEN.\n')
185+
return
186+
print (
187+
'\n*** No github OAuth security token found in $GITHUB_TOKEN.'
188+
' You need the token for gothub to draft the release on github!'
189+
' (Get the security token via github\'s website, cf.'
190+
'\n*** https://help.github.com/articles/creating-a-personal-access-'
191+
'token-for-the-command-line/ )\n')
192+
token = input('--> Please enter your github OAuth security token:\n')
193+
os.environ['GITHUB_TOKEN'] = token
194+
178195
def ensure_gitpulls_is_installed():
179196
'''Check whether the gem git-pulls (to get github pull requests) is
180197
installed.
@@ -195,10 +212,12 @@ def check_release_tools():
195212
drafting the github release from CLI). If not, ask whether user
196213
wants to continue and draft the release manually (if this is not
197214
the case, raise exception!).
215+
If no github OAuth security token is set, ask for it.
198216
'''
199217
try:
200218
ensure_gitpulls_is_installed()
201219
ensure_gothub_is_installed()
220+
check_or_setup_github_OAuth_token()
202221
return True
203222
except OSError:
204223
answer = ''
@@ -366,12 +385,18 @@ def finalise_release():
366385

367386
# publish github release (with message from pull request)
368387
if draft_release:
369-
assert subprocess.call(
388+
release_failed = subprocess.call(
370389
['gothub', 'release', '-u', github_user, '-r', github_repo,
371390
'-t', 'v' + new_version,
372391
'-n', '"PyHEADTAIL v{}"'.format(new_version),
373392
'-d', '"{}"'.format(message),
374393
'-c', 'master'])
394+
if release_failed:
395+
print ('*** Drafting the release via gothub failed. '
396+
'Did you provide the correct github OAuth security '
397+
'token via $GITHUB_TOKEN? '
398+
'You may draft this release manually from the '
399+
'github website.')
375400
else:
376401
print ('*** Remember to manually draft this release from the '
377402
'github website.')

0 commit comments

Comments
 (0)