From: Benjamin Drung Date: Fri, 17 Jan 2014 16:36:21 +0000 (+0100) Subject: gentoo_build: Add gitweb link to every git commit. X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=10d031d9344c9124a1123261b52d61864f652708;p=profitbricks%2Fjenkins-build-scripts.git gentoo_build: Add gitweb link to every git commit. --- diff --git a/gentoo_build b/gentoo_build index 29538ee..c39c7bf 100755 --- a/gentoo_build +++ b/gentoo_build @@ -36,6 +36,9 @@ import common_code DEFAULT_CHROOT_NAME = "gentoo" DEFAULT_CHROOT_USER = "root" +GITWEB_RE = r'^((file://|git\+ssh://[A-Za-z.:@]+)?/srv/git|git://[A-Za-z.:@]+)' +GITWEB_URL = 'http://git/gitweb.cgi' + ENV_CATEGORY = "CATEGORY" ENV_CHROOT = "CHROOT_NAME" ENV_CHROOT_USER = "CHROOT_USER" @@ -336,11 +339,11 @@ def tag_head_commit(logger, new_tag, resolve_existing_msg=""): msg = ('The head commit {commit} is already tagged with {tag}.\n' 'Call this script without --tag-from-debian-changelog ' 'to release the ebuild file.') - msg = msg.format(commit=current_commit.hexsha[0:7], tag=new_tag) + msg = msg.format(commit=format_commit(current_commit), tag=new_tag) else: msg = ('The head commit {commit} is already tagged: {tags}\n' 'The script expects a commit without additional tags.') - msg = msg.format(commit=current_commit.hexsha[0:7], + msg = msg.format(commit=format_commit(current_commit), tags=" ".join(tags)) logger.error(msg) sys.exit(1) @@ -348,13 +351,21 @@ def tag_head_commit(logger, new_tag, resolve_existing_msg=""): if len(remote_tag) > 0: msg = ('Tag {tag} was already created for commit ' '{commit}.'.format(tag=new_tag, - commit=remote_tag[0].commit.hexsha[0:7])) + commit=format_commit(remote_tag[0].commit))) logger.error(msg + resolve_existing_msg) sys.exit(1) logger.info("Tagging commit {commit} with {tag}" - "...".format(commit=current_commit.hexsha[0:7], tag=new_tag)) + "...".format(commit=format_commit(current_commit), + tag=new_tag)) repo.git.tag(new_tag) +def format_commit(commit): + """Create a human readable string for a given git commit.""" + remote_url = commit.repo.config_reader().get('remote "origin"', "url") + weburl = re.sub(GITWEB_RE, GITWEB_URL, remote_url) + weburl += "/commit/" + commit.hexsha[0:7] + return commit.hexsha[0:7] + ' ( ' + weburl + ' )' + def get_latest_tag(logger): """Get the tag name for the branch head commit. The function will fail if the branch head commit is not tagged or has @@ -364,13 +375,13 @@ def get_latest_tag(logger): current_commit = repo.commit(repo.active_branch) tags = [t.name for t in repo.tags if t.commit == current_commit] if len(tags) == 0: - logger.error('No tag found for commit {commit}.\nHave you tagged ' - 'your release?'.format(commit=current_commit.hexsha[0:7])) + logger.error('No tag found for commit {commit}.\nHave you tagged your ' + 'release?'.format(commit=format_commit(current_commit))) sys.exit(1) if len(tags) > 1: msg = ('More than one tag found for commit {commit}: {tags}\n' 'The script expects exactly one tag.') - logger.error(msg.format(commit=current_commit.hexsha[0:7], + logger.error(msg.format(commit=format_commit(current_commit), tags=" ".join(tags))) sys.exit(1) tag = tags[0]