From 5b6c1f9200cf24ce625084576f58a539a63fd287 Mon Sep 17 00:00:00 2001 From: Ryan Herbst Date: Fri, 28 Feb 2020 09:51:52 -0800 Subject: [PATCH 1/3] Allow user to store github token in their environment --- releaseGen.py | 17 ++++++++++++----- releaseNotes.py | 13 ++++++++++++- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/releaseGen.py b/releaseGen.py index 63e74639..c7afa85d 100644 --- a/releaseGen.py +++ b/releaseGen.py @@ -525,12 +525,19 @@ def pushRelease(cfg, relName, relData, ver, tagAttach, prev): print("\nLogging into github....\n") - if args.token is None: - print("Enter your github token. If you do no have one you can generate it here:"); - print(" https://github.com/settings/tokens"); - token = input("\nGithub token: "); - else: + if args.token is not None: + print("Using github token from command line arg.") token = args.token + else: + token = os.environ.get('GITHUB_TOKEN') + + if token is None: + print("Enter your github token. If you do no have one you can generate it here:"); + print(" https://github.com/settings/tokens"); + print("You may set it in your environment as GITHUB_TOKEN") + token = input("\nGithub token: "); + else: + print("Using github token from user's environment.") gh = github.Github(token) remRepo = gh.get_repo(f'slaclab/{project}') diff --git a/releaseNotes.py b/releaseNotes.py index a8d3e053..5c8d77c8 100644 --- a/releaseNotes.py +++ b/releaseNotes.py @@ -117,6 +117,7 @@ def getReleaseNotes(locRepo, remRepo, tagRange, noSort=False): import pyperclip from getpass import getpass import re + import os import git # https://gitpython.readthedocs.io/en/stable/tutorial.html from github import Github # https://pygithub.readthedocs.io/en/latest/introduction.html @@ -174,7 +175,17 @@ def getReleaseNotes(locRepo, remRepo, tagRange, noSort=False): project = re.compile(r'slaclab/(?P.*?).git').search(url).group('name') # Connect to the Git server - token = input("Enter your github token: ") + token = os.environ.get('GITHUB_TOKEN') + + if token is None: + print("Enter your github token. If you do no have one you can generate it here:"); + print(" https://github.com/settings/tokens"); + print("You may set it in your environment as GITHUB_TOKEN") + token = input("\nGithub token: "); + + else: + print("Using github token from user's environment.") + github = Github(token) # Get the repo information From e09eab55e5ea931f12af5ba8ca0903a6043771f6 Mon Sep 17 00:00:00 2001 From: Ryan Herbst Date: Mon, 16 Mar 2020 23:00:52 -0700 Subject: [PATCH 2/3] Add labels to release notes --- releaseNotes.py | 55 ++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/releaseNotes.py b/releaseNotes.py index 830ada68..beb63178 100644 --- a/releaseNotes.py +++ b/releaseNotes.py @@ -17,17 +17,17 @@ # > git merge origin/master # > git merge origin/pre-release # > git push -# - Tag the release in master: +# - Tag the release in master: # > git tag -a vMAJOR.MINOR.0 # > git push --tags # - Create release using tag on github.com, use this script to generate notes # ---------------------------------------------------------------------------- -# This file is part of the 'SLAC Firmware Standard Library'. It is subject to -# the license terms in the LICENSE.txt file found in the top-level directory -# of this distribution and at: -# https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. -# No part of the 'SLAC Firmware Standard Library', including this file, may be -# copied, modified, propagated, or distributed except according to the terms +# This file is part of the 'SLAC Firmware Standard Library'. It is subject to +# the license terms in the LICENSE.txt file found in the top-level directory +# of this distribution and at: +# https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. +# No part of the 'SLAC Firmware Standard Library', including this file, may be +# copied, modified, propagated, or distributed except according to the terms # contained in the LICENSE.txt file. # ---------------------------------------------------------------------------- @@ -71,10 +71,17 @@ def getReleaseNotes(locRepo, remRepo, tagRange, noSort=False): else: entry['Jira'] = None + entry['labels'] = None + for lbl in req.get_labels(): + if entry['labels'] is None: + entry['labels'] = lbl.name + else: + entry['labels'] += ', ' + lbl.name + records.append(entry) - entry = {} - - # Check if sorting the pull request entries + entry = {} + + # Check if sorting the pull request entries if noSort is False: records = sorted(records, key=lambda v : v['changes'], reverse=True) @@ -92,21 +99,21 @@ def getReleaseNotes(locRepo, remRepo, tagRange, noSort=False): md += '\n|||\n|---:|:---|\n' - for i in ['Author','Date','Pull','Branch','Jira']: + for i in ['Author','Date','Pull','Branch','Jira','labels']: if i in entry and entry[i] is not None: md += f'|**{i}:**|{entry[i]}|\n' md += '\n**Notes:**\n' for line in entry['body'].splitlines(): md += '> ' + line + '\n' - md += '\n-------\n' + md += '\n-------\n' md += '\n\n' # Deal with potential UNICODE in the md # Note: Markup language uses the XML # character for unicode - md = md.encode('ascii', 'xmlcharrefreplace') - md = str(md)[2:-1] - md = md.replace('\\n', '\n') + md = md.encode('ascii', 'xmlcharrefreplace') + md = str(md)[2:-1] + md = md.replace('\\n', '\n') return md @@ -129,10 +136,10 @@ def getReleaseNotes(locRepo, remRepo, tagRange, noSort=False): # Add arguments parser.add_argument( - "tag", + "tag", type = str, help = 'reference tag or range. (i.e. v2.5.0 or v2.5.0..v2.6.0)', - ) + ) parser.add_argument( "--noSort", @@ -140,15 +147,15 @@ def getReleaseNotes(locRepo, remRepo, tagRange, noSort=False): required = False, default = False, help = "Disable sort by change counts", - ) + ) parser.add_argument( - "--copy", + "--copy", type = argBool, required = False, default = False, help = "Copy to clipboard", - ) + ) # Get the arguments args = parser.parse_args() @@ -188,9 +195,9 @@ def getReleaseNotes(locRepo, remRepo, tagRange, noSort=False): print(md) if args.copy: - try: - pyperclip.copy(md) - print('Release notes copied to clipboard') - except: + try: + pyperclip.copy(md) + print('Release notes copied to clipboard') + except: print("Copy to clipboard failed!") From 6076fe22cda0c7e2c2de6ae9e8b4a5f336558b98 Mon Sep 17 00:00:00 2001 From: Ryan Herbst Date: Mon, 16 Mar 2020 23:21:18 -0700 Subject: [PATCH 3/3] Capitalize --- releaseNotes.py | 56 ++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/releaseNotes.py b/releaseNotes.py index c4aea3ed..4907ccc0 100644 --- a/releaseNotes.py +++ b/releaseNotes.py @@ -17,17 +17,17 @@ # > git merge origin/master # > git merge origin/pre-release # > git push -# - Tag the release in master: +# - Tag the release in master: # > git tag -a vMAJOR.MINOR.0 # > git push --tags # - Create release using tag on github.com, use this script to generate notes # ---------------------------------------------------------------------------- -# This file is part of the 'SLAC Firmware Standard Library'. It is subject to -# the license terms in the LICENSE.txt file found in the top-level directory -# of this distribution and at: -# https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. -# No part of the 'SLAC Firmware Standard Library', including this file, may be -# copied, modified, propagated, or distributed except according to the terms +# This file is part of the 'SLAC Firmware Standard Library'. It is subject to +# the license terms in the LICENSE.txt file found in the top-level directory +# of this distribution and at: +# https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. +# No part of the 'SLAC Firmware Standard Library', including this file, may be +# copied, modified, propagated, or distributed except according to the terms # contained in the LICENSE.txt file. # ---------------------------------------------------------------------------- @@ -71,19 +71,19 @@ def getReleaseNotes(locRepo, remRepo, tagRange, noSort=False): else: entry['Jira'] = None - entry['labels'] = None + entry['Labels'] = None for lbl in req.get_labels(): - if entry['labels'] is None: - entry['labels'] = lbl.name + if entry['Labels'] is None: + entry['Labels'] = lbl.name else: - entry['labels'] += ', ' + lbl.name + entry['Labels'] += ', ' + lbl.name if 'release candidate' not in req.title.lower(): records.append(entry) - entry = {} - - # Check if sorting the pull request entries + entry = {} + + # Check if sorting the pull request entries if noSort is False: records = sorted(records, key=lambda v : v['changes'], reverse=True) @@ -101,21 +101,21 @@ def getReleaseNotes(locRepo, remRepo, tagRange, noSort=False): md += '\n|||\n|---:|:---|\n' - for i in ['Author','Date','Pull','Branch','Jira','labels']: + for i in ['Author','Date','Pull','Branch','Jira','Labels']: if i in entry and entry[i] is not None: md += f'|**{i}:**|{entry[i]}|\n' md += '\n**Notes:**\n' for line in entry['body'].splitlines(): md += '> ' + line + '\n' - md += '\n-------\n' + md += '\n-------\n' md += '\n\n' # Deal with potential UNICODE in the md # Note: Markup language uses the XML # character for unicode - md = md.encode('ascii', 'xmlcharrefreplace') - md = str(md)[2:-1] - md = md.replace('\\n', '\n') + md = md.encode('ascii', 'xmlcharrefreplace') + md = str(md)[2:-1] + md = md.replace('\\n', '\n') return md @@ -138,10 +138,10 @@ def getReleaseNotes(locRepo, remRepo, tagRange, noSort=False): # Add arguments parser.add_argument( - "tag", + "tag", type = str, help = 'reference tag or range. (i.e. v2.5.0 or v2.5.0..v2.6.0)', - ) + ) parser.add_argument( "--noSort", @@ -149,15 +149,15 @@ def getReleaseNotes(locRepo, remRepo, tagRange, noSort=False): required = False, default = False, help = "Disable sort by change counts", - ) + ) parser.add_argument( - "--copy", + "--copy", type = argBool, required = False, default = False, help = "Copy to clipboard", - ) + ) # Get the arguments args = parser.parse_args() @@ -197,9 +197,9 @@ def getReleaseNotes(locRepo, remRepo, tagRange, noSort=False): print(md) if args.copy: - try: - pyperclip.copy(md) - print('Release notes copied to clipboard') - except: + try: + pyperclip.copy(md) + print('Release notes copied to clipboard') + except: print("Copy to clipboard failed!")