From 0ea15a31e82f7c4f3d95b52a45c96a238998ba57 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Mon, 16 Oct 2017 11:33:12 -0400 Subject: [PATCH] ensure the git user identity is configured In order for list-changes to tag the repo we need to ensure the git user identity is set. We do that conditionally to avoid overwriting local user settings when running the command outside of CI. Change-Id: I6ac6be1ad1907f19e9ba8850d80460f84d34446c Signed-off-by: Doug Hellmann --- openstack_releases/cmds/list_changes.py | 7 +++++++ openstack_releases/gitutils.py | 23 ++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/openstack_releases/cmds/list_changes.py b/openstack_releases/cmds/list_changes.py index dc8bbcfd4d..156357cb40 100644 --- a/openstack_releases/cmds/list_changes.py +++ b/openstack_releases/cmds/list_changes.py @@ -315,6 +315,13 @@ def main(): project['repo'], ] ) + # Set some git configuration values to allow us to perform + # local operations like tagging. + gitutils.ensure_basic_git_config( + workdir, project['repo'], + {'user.email': 'openstack-infra@lists.openstack.org', + 'user.name': 'OpenStack Proposal Bot'}, + ) # Determine which branch we should actually be looking # at. Assume any series for which there is no stable diff --git a/openstack_releases/gitutils.py b/openstack_releases/gitutils.py index bbca82a903..f2321cb06d 100644 --- a/openstack_releases/gitutils.py +++ b/openstack_releases/gitutils.py @@ -72,7 +72,28 @@ def tag_exists(repo, ref): return links.link_exists(url) -def clone_repo(workdir, repo, ref=None): +def ensure_basic_git_config(workdir, repo, settings): + """Given a repo directory and a settings dict, set local config values + if those settings are not already defined. + """ + dest = os.path.join(workdir, repo) + for key, value in settings.items(): + LOG.info('looking for git config {}'.format(key)) + try: + existing = subprocess.check_output( + ['git', 'config', '--get', key], + cwd=dest, + ).decode('utf-8').strip() + LOG.info('using existing setting of {}: {!r}'.format(key, existing)) + except subprocess.CalledProcessError: + LOG.info('updating setting of {} to {!r}'.format(key, value)) + subprocess.check_call( + ['git', 'config', key, value], + cwd=dest, + ) + + +def clone_repo(workdir, repo, ref=None, branch=None): "Check out the code." dest = os.path.join(workdir, repo) if not os.path.exists(dest):