aboutsummaryrefslogtreecommitdiffstats
path: root/osurl
blob: 74486847d9b2d6ed0b5935e6ecd4995dd4df03da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/lua

local lpeg = require 'lpeg'
local P,C,Cs,Cf,R,S = lpeg.P, lpeg.C, lpeg.Cs, lpeg.Cf, lpeg.R, lpeg.S

local tokens = {
    NONHASH    = C((1 - P("#"))^1),             -- any nonempty string not containing #
    SEP        = S("#-"),                       -- separators, can be # or -
    NUM        = C(R("09")^1),                  -- nonempty digit string
    WORD       = C(R("AZ","az","09","__")^1),   -- nonempty word
    JIRID      = C(R("AZ","az","09","--")^1)    -- nonempty word
}
local patterns = {
    ["bgo%SEP%NUM"] = "https://bugzilla.gnome.org/show_bug.cgi?id=%1",
    ["bpo%SEP%NUM"] = "https://bugs.python.org/issue%1",
    ["bko%SEP%NUM"] = "https://bugzilla.kernel.org/show_bug.cgi?id=%1",
    ["bmo%SEP%NUM"] = "https://bugzilla.mozilla.org/show_bug.cgi?id=%1",
    ["boo%SEP%NUM"] = "https://bugzilla.opensuse.org/show_bug.cgi?id=%1",
    ["bnc%SEP%NUM"] = "https://bugzilla.novell.com/show_bug.cgi?id=%1",
    ["bsc%SEP%NUM"] = "https://bugzilla.suse.com/show_bug.cgi?id=%1",
    ["bds%SEP%NUM"] = "https://build.suse.de/request/show/%1",
    ["ssr%SEP%NUM"] = "https://build.suse.de/request/show/%1",
    ["bdo%SEP%NUM"] = "https://build.opensuse.org/request/show/%1",
    ["sr%SEP%NUM"] = "https://build.opensuse.org/request/show/%1",
    ["jsc%SEP%JIRID"] = "https://jira.suse.com/browse/%1",
    ["gh%SEP%NONHASH%SEP%WORD"] = "https://github.com/%1/issues/%2",
    ["gl%SEP%NONHASH%SEP%WORD"] = "https://gitlab.com/%1/issues/%2",
    ["bt%SEP%NONHASH%SEP%WORD"] = "https://bitbucket.org/%1/issues/%2",
    ["sh%SEP%NUM"] = "http://sourecforge.net/support/tracker.php?aid=%1",
    ["shb%SEP%NONHASH%SEP%NUM"] = "https://sourceforge.net/p/%1/bugs/%2/",
    ["shp%SEP%NONHASH%SEP%NUM"] = "https://sourceforge.net/p/%1/patches/%2/",
    ["lp%SEP%NUM"] = "https://launchpad.net/bugs/%1",
    ["rh%SEP%NUM"] = "https://bugzilla.redhat.com/show_bug.cgi?id=%1",
    ["tdf%SEP%NUM"] = "https://bugs.documentfoundation.org/show_bug.cgi?id=%1",
    ["pep%SEP%NUM"] = "https://www.python.org/dev/peps/pep-%1",
}

-- turn "foo#%BLAH" into a pattern that matches everything literally except
-- %BLAH
local makepat = Cf(
    (
        ((P("%") * C(R("AZ")^1)) / tokens)        -- %BLAH is from tokens
        + (P"%%" / function() return P"%" end)    -- %% treat as literal %
        + (C(P(1)) / P)                           -- anything else is literal
    )^0,
    function(a,b) return a * b end)
local function make_pattern(str)
    return assert(makepat:match(str), "invalid pattern")
end

local bugpat = P(false)
for k,v in pairs(patterns) do
    bugpat = bugpat + (make_pattern(k) / v)
end
local pat = Cs((bugpat + P(1))^0)

local in_url = arg[1]
local out_url = pat:match(in_url:lower())
if out_url == in_url:lower() then
    out_url = in_url
end

os.execute("xdg-open " .. out_url)