[bin] Rework get-gitlab-shortcode to handle group/subgroup/project URLS
This commit is contained in:
parent
d7122a4a5c
commit
6158cfc632
|
@ -4,24 +4,26 @@ require "uri"
|
||||||
|
|
||||||
begin
|
begin
|
||||||
abort "Please supply a valid URL to this script." if ARGV.empty?
|
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."
|
abort "Not a valid forge URI" unless uri.host.start_with? "git."
|
||||||
|
|
||||||
uri_match = uri.path.match(%r{/(?<group>[a-z/]+?)/-/(?<type>[\w]+)/(?<issue>[\d]+)})
|
if uri_match = uri.path.match(%r{/(?<group>[a-z/]+?)(/-/)(?<type>[\w]+)/(?<issue>[\w]+)})
|
||||||
|
short_code = case uri_match[:type]
|
||||||
abort "Could not find anything to match in #{uri}" if uri_match.nil?
|
when "merge_requests"
|
||||||
|
"!"
|
||||||
short_code = case uri_match[:type]
|
when "issues"
|
||||||
when "merge_requests"
|
"#"
|
||||||
"!"
|
when "commit"
|
||||||
when "issues"
|
"@"
|
||||||
"#"
|
end
|
||||||
|
out = [uri_match[:group], uri_match[:issue]].join(short_code)
|
||||||
|
elsif uri_match = uri.path.match(%r{/(?<group>([a-z/]+)?)/(?<project>([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
|
end
|
||||||
|
|
||||||
out = [uri_match[:group], uri_match[:issue]].join(short_code)
|
|
||||||
|
|
||||||
binding.pry
|
|
||||||
`notify-send #{ARGV.inspect}`
|
`notify-send #{ARGV.inspect}`
|
||||||
$stdout.puts out
|
$stdout.puts out
|
||||||
rescue URI::InvalidURIError => e
|
rescue URI::InvalidURIError => e
|
||||||
|
|
Loading…
Reference in New Issue