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 <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann
2017-10-16 11:33:12 -04:00
parent fffdada0bd
commit 0ea15a31e8
2 changed files with 29 additions and 1 deletions

View File

@@ -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

View File

@@ -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):