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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# convenience wrappers to construct links
# into the webinterfaces of different VCSs
from builtins import object
import re
class VCSBrowser(object):
def __init__(self, url):
self.url = url.rstrip('/')
def commit(self, commtid):
raise NotImplemented
def branch(self, branch):
raise NotImplemented
class GitlabBrowser(VCSBrowser):
"""
Gitlab based repo browser
URLs for gitlab:
e.g. http://salsa.debian.org/libvirt-team/libvirt.git
"""
repotype = "gitweb"
def __init__(self, url):
VCSBrowser.__init__(self, url)
@classmethod
def check(cls, url):
return True if 'https://salsa.debian.org/' in url else False
def commit(self, commitid):
return "%s/commit/%s" % (self.url, commitid)
class GitWebBrowser(VCSBrowser):
"""
GitWeb based repo browser
URLs for gitweb:
e.g. http://git.debian.org/?p=pkg-libvirt/gtk-vnc.git
"""
repotype = "gitweb"
def __init__(self, url):
url = re.sub(r';a=summary$', '', url)
VCSBrowser.__init__(self, url)
@classmethod
def check(cls, url):
return True if '/?p=' in url else False
def commit(self, commitid):
return "%s;a=commitdiff;h=%s" % (self.url, commitid)
class CGitBrowser(VCSBrowser):
repotype = "cgit"
def __init__(self, url):
VCSBrowser.__init__(self, url)
@classmethod
def check(cls, url):
return True if '/cgit' in url else False
def commit(self, commitid):
return "%s/commit/?id=%s" % (self.url, commitid)
def guess_git_repo(url):
"""
>>> guess_git_repo("http://example.com/?p=foo").repotype
'gitweb'
>>> guess_git_repo("http://example.com/cgit/foo").repotype
'cgit'
>>> guess_git_repo("http://example.com/bar/foo").repotype
'cgit'
"""
for repotype in [GitlabBrowser, CGitBrowser, GitWebBrowser]:
if repotype.check(url):
return repotype(url)
return CGitBrowser(url)
class HgBrowser(VCSBrowser):
"""
URLs for Mercurial:
e.g. http://hg.et.redhat.com/virt/applications/virtinst--devel
"""
def commit(self, commitid):
return "%s?cs=%s" % (self.url, commitid)
|