-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrepository.py
71 lines (55 loc) · 2.01 KB
/
repository.py
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
import re, git
import buildbot.steps.source
from twisted.python import log
repositories = {}
class Repository(object):
stepClass = None
def __init__(self, url, properties=None):
self.url = url
repositories[url] = self
def match_url(self, url):
"""Used for change filtering; True iff url identifies the same repository."""
return self.url == url
def steps(self, *args, **kw):
return [ self.stepClass(repourl = self.url, *args, **kw) ]
class GitStep(buildbot.steps.source.Git):
def computeSourceRevision(self, changes):
if changes:
for c in list(changes).reversed():
log.msg('checking repo match: %s/%s' % (c.repository, self.repourl))
if git.probably_same_repo(c.repository, self.repourl):
log.msg('MATCHED')
return c.revision
return None
class Git(Repository):
"""
A repository whose steps use Git, but unlike BuildBot, *do*
consider submodules by default. Seriously, who wants to ignore
submodules?
"""
stepClass = git.SourceStep
def steps(self, *args, **kw):
kw.setdefault('submodules', True)
return super(Git,self).steps(*args, **kw)
@property
def name(self):
"""
The name of the repository: the last element of the url, sans .git extension if any
"""
return re.match('.*/(.*?)(?:.git)?$', self.url).group(1)
class GitHub(Git):
protocols=dict(
git='git://github.com/%s',
http='http://github.com/%s',
https='https://github.com/%s',
ssh='[email protected]:%s',
)
def __init__(self, id, protocol='http'):
super(GitHub,self).__init__(GitHub.protocols[protocol] % id)
self.id = id
self.protocol = protocol
def __repr__(self):
return self.__class__.__module__ + '.' \
+ self.__class__.__name__+repr((self.id,self.protocol))
def match_url(self, url):
return git.probably_same_repo(self.url,url)