]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
gentoo_build: Add gitweb link to every git commit.
authorBenjamin Drung <benjamin.drung@profitbricks.com>
Fri, 17 Jan 2014 16:36:21 +0000 (17:36 +0100)
committerBenjamin Drung <benjamin.drung@profitbricks.com>
Fri, 17 Jan 2014 16:36:21 +0000 (17:36 +0100)
gentoo_build

index 29538ee2b654055cebc7e991d584b70e9beb4c10..c39c7bf94a37721d324dc4d500103ba45eaa3b02 100755 (executable)
@@ -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]