From 77caf01457ece453f76293ef6336433fc63f2e8a Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 6 Mar 2020 14:07:45 +0000 Subject: [PATCH 1/2] Update FIXME comment due to issue being moved Signed-off-by: Philip Withnall --- gitlab-changelog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitlab-changelog.py b/gitlab-changelog.py index a37a936..6c98826 100755 --- a/gitlab-changelog.py +++ b/gitlab-changelog.py @@ -78,7 +78,7 @@ def get_issues_and_merge_requests(commit, gl_project_name): # FIXME: Would be good if gitlab put metadata in merge commits, then we # could parse those instead, rather than the human-readable commit message. - # See https://gitlab.com/gitlab-org/gitlab-ce/issues/56635 + # See https://gitlab.com/gitlab-org/gitlab/-/issues/26266 lines = commit.message.split('\n') issues = set() -- GitLab From 52da2ec915423450735a15afdaf353f2bbc7a02b Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 6 Mar 2020 14:27:00 +0000 Subject: [PATCH 2/2] Rework config file to support multiple hosts Signed-off-by: Philip Withnall --- gitlab-changelog.py | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/gitlab-changelog.py b/gitlab-changelog.py index 6c98826..fc713ac 100755 --- a/gitlab-changelog.py +++ b/gitlab-changelog.py @@ -23,6 +23,13 @@ Usage: gitlab-changelog.py -H https://gitlab.gnome.org/ -t GNOME/glib 2.58.2.. then put the output into NEWS/ChangeLog and make the release. +The -H and -t arguments can be omitted by putting the following in +`~/.config/gitlab-changelog.ini`: + [gitlab-changelog] + default-hostname = https://gitlab.gnome.org/ + [https://gitlab.gnome.org/] + token = + To generate an authentication token for the script, go to https://gitlab.gnome.org/profile/personal_access_tokens and generate a token with the `api` scope. @@ -120,13 +127,14 @@ def main(): 'gitlab-changelog.ini') config.read(config_path) + gl_default_hostname = None + gl_default_token = None + try: - gl_hostname = config['gitlab-changelog']['hostname'] - gl_token = config['gitlab-changelog']['token'] + gl_default_hostname = config['gitlab-changelog']['default-hostname'] + gl_default_token = config[gl_default_hostname]['token'] write_config = False except KeyError: - gl_hostname = None - gl_token = None write_config = True # Parse command line arguments. @@ -142,26 +150,40 @@ def main(): parser.add_argument('-C', dest='path', default='.', help='repository to use (default: current directory)') - parser.add_argument('-H', '--hostname', default=gl_hostname, - required=(gl_hostname is None), + parser.add_argument('-H', '--hostname', default=gl_default_hostname, + required=(gl_default_hostname is None), help='GitLab hostname (for example: ' '‘https://gitlab.gnome.org/’, default: ' 'load from {})'.format(config_path)) - parser.add_argument('-t', '--token', default=gl_token, - required=(gl_token is None), + parser.add_argument('-t', '--token', default=None, required=False, help='GitLab authentication token (default: ' 'load from {})'.format(config_path)) args = parser.parse_args() + # Try and look up the token for the given hostname, if not given on the + # command line. + try: + if not args.token: + args.token = config[args.hostname]['token'] + except KeyError: + parser.error('Configuration key {}.{} not found in {}'.format( + args.hostname, 'token', config_path)) + sys.exit(1) + # Authenticate with GitLab to check the config. gl = gitlab.Gitlab(args.hostname, private_token=args.token) gl_project_name = args.gl_project gl_project = gl.projects.get(gl_project_name) if write_config: - config['gitlab-changelog'] = { - 'hostname': args.hostname, + if 'gitlab-changelog' not in config.sections() or \ + 'default-hostname' not in config['gitlab-changelog']: + config['gitlab-changelog'] = { + 'default-hostname': args.hostname, + } + + config[args.hostname] = { 'token': args.token, } -- GitLab