From 6158cfc6325e38e0fe41340484b385913efffca5 Mon Sep 17 00:00:00 2001 From: Sebastian Schulze Date: Wed, 6 Jul 2022 20:18:57 +0200 Subject: [PATCH] [bin] Rework get-gitlab-shortcode to handle group/subgroup/project URLS --- bin/executable_get-gitlab-shortcode | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/bin/executable_get-gitlab-shortcode b/bin/executable_get-gitlab-shortcode index 24c8f8e..df12b1d 100644 --- a/bin/executable_get-gitlab-shortcode +++ b/bin/executable_get-gitlab-shortcode @@ -4,24 +4,26 @@ require "uri" begin abort "Please supply a valid URL to this script." if ARGV.empty? - uri = URI.parse(ARGV.first.strip) + uri = URI.parse(ARGV.last.strip) abort "Not a valid forge URI" unless uri.host.start_with? "git." - uri_match = uri.path.match(%r{/(?[a-z/]+?)/-/(?[\w]+)/(?[\d]+)}) - - abort "Could not find anything to match in #{uri}" if uri_match.nil? - - short_code = case uri_match[:type] - when "merge_requests" - "!" - when "issues" - "#" + if uri_match = uri.path.match(%r{/(?[a-z/]+?)(/-/)(?[\w]+)/(?[\w]+)}) + short_code = case uri_match[:type] + when "merge_requests" + "!" + when "issues" + "#" + when "commit" + "@" + end + out = [uri_match[:group], uri_match[:issue]].join(short_code) + elsif uri_match = uri.path.match(%r{/(?([a-z/]+)?)/(?([a-z]+))(/)?}) + out = [uri_match[:group], uri_match[:project]].join("/") + ">" + else + abort "Could not find anything to match in #{uri}" if uri_match.nil? end - out = [uri_match[:group], uri_match[:issue]].join(short_code) - - binding.pry `notify-send #{ARGV.inspect}` $stdout.puts out rescue URI::InvalidURIError => e