[bugzilla-gnome-org-customizations] Automatically link Git commits to the corresponding URL



commit 27f1c5e9e2758bdbd84b208adb078bfe77f69a40
Author: Andre Klapper <a9016009 gmx de>
Date:   Tue Jan 6 01:45:31 2015 +0100

    Automatically link Git commits to the corresponding URL
    
    Automatically link "commit 1a2b3c4d" and "pushed as 1a2b3c4d" to
    the corresponding URL for that commit on https://git.gnome.org.
    
    The ID can have between 8 and 40 characters. The URL construction
    relies on the product name of the Bugzilla report so if the name
    in Bugzilla does not match the repository name in Git the URL
    will be a 404. So you might want to make sure that names are the
    same in Bugzilla and Git if you want this feature to work.
    
    Patch written by Olav Vitters and Andre Klapper.
    
    Bug 559537

 extensions/GNOME/Extension.pm |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
---
diff --git a/extensions/GNOME/Extension.pm b/extensions/GNOME/Extension.pm
index ea55947..0c30b72 100644
--- a/extensions/GNOME/Extension.pm
+++ b/extensions/GNOME/Extension.pm
@@ -28,6 +28,7 @@ use Bugzilla::Extension::GNOME::Util;
 use Bugzilla::Constants;
 use Bugzilla::Field;
 use Bugzilla::Object;
+use Bugzilla::Util;
 
 our $VERSION = '0.01';
 
@@ -307,4 +308,25 @@ sub webservice {
     $dispatch->{GNOME} = "Bugzilla::Extension::GNOME::WebService";
 }
 
+sub bug_format_comment {
+   my ($self, $args) = @_;
+   my $regexes = $args->{'regexes'};
+   my $text = $args->{'text'};
+   if (defined $args->{'bug'}) {
+     my $replacerGitCommit = {
+         match => qr{(\scommit\s|\spushed as\s)\#?([a-f0-9]{8,40})}i,
+         replace => sub { _createGitCommitLink($self, $args); }
+     };
+     push( @$regexes, $replacerGitCommit );
+   }
+}
+
+sub _createGitCommitLink {
+
+   my ($self, $args) = @_;
+   my $productname = $args->{'bug'}->product;
+   my $commit_link = join("", $1, '<a href="https://git.gnome.org/browse/', url_quote($productname), 
'/commit/?id=', $2, '">', $2, '</a>');
+   return $commit_link;
+};
+
 __PACKAGE__->NAME;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]