From fb1b1c796b1fb13ab52bb4ff45952598c7e2ca03 Mon Sep 17 00:00:00 2001 From: dklawren Date: Thu, 29 Aug 2019 09:38:13 -0400 Subject: Bug 1575003 - Can't link to gitlab issues in the "see also" field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch from https://github.com/mozilla-bteam/bmo/commit/3751928389c0062877ac23b5040226f849a88cfd. Thanks to asturm for digging it up. Signed-off-by: Michał Górny --- Bugzilla/BugUrl.pm | 1 + Bugzilla/BugUrl/GitLab.pm | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 Bugzilla/BugUrl/GitLab.pm diff --git a/Bugzilla/BugUrl.pm b/Bugzilla/BugUrl.pm index 5d62d1b17..42e993bf4 100644 --- a/Bugzilla/BugUrl.pm +++ b/Bugzilla/BugUrl.pm @@ -65,6 +65,7 @@ use constant SUB_CLASSES => qw( Bugzilla::BugUrl::MantisBT Bugzilla::BugUrl::SourceForge Bugzilla::BugUrl::GitHub + Bugzilla::BugUrl::GitLab ); ############################### diff --git a/Bugzilla/BugUrl/GitLab.pm b/Bugzilla/BugUrl/GitLab.pm new file mode 100644 index 000000000..8e546c1dc --- /dev/null +++ b/Bugzilla/BugUrl/GitLab.pm @@ -0,0 +1,45 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. + +package Bugzilla::BugUrl::GitLab; + +use 5.10.1; +use strict; +use warnings; + +use base qw(Bugzilla::BugUrl); + +############################### +#### Methods #### +############################### + +sub should_handle { + my ($class, $uri) = @_; + +# GitLab issue URLs can have the form: +# https://gitlab.com/projectA/subprojectB/subprojectC/../issues/53 + return ($uri->path =~ m!^/.*/issues/\d+$!) ? 1 : 0; +} + +sub _check_value { + my ($class, $uri) = @_; + + $uri = $class->SUPER::_check_value($uri); + + # Require the HTTPS scheme. + $uri->scheme('https'); + + # Make sure there are no query parameters. + $uri->query(undef); + + # And remove any # part if there is one. + $uri->fragment(undef); + + return $uri; +} + +1; -- cgit v1.2.3-65-gdbad