-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext.py
102 lines (78 loc) · 3.25 KB
/
context.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import re
from .database import Database
class Context:
name = 'Pull Requests'
debug = False
debug_db = False
dbname = 'pullrequests'
urlpath = 'pullrequests'
def __init__(self):
self.db = Database(self)
updatePullRequestsDelay = 120
master = None # : :type master: buildbot.master.BuildMaster
trustedAuthors = None # No limitations
reviewers = None # No limitations
builders = {
# runtests1=dict(name='t1', builders=['runtests1'], order=0, isPerf=False),
}
def updatePullRequests(self):
assert False
def getBuildProperties(self, pr, properties, sourcestamps):
assert False
def getWebAddressPullRequest(self, pr):
assert False
def getWebAddressPerfRegressionReport(self, pr):
assert False
def extractRegressionTestFilter(self, desc):
try:
return self.extractParameter(desc, 'check_regression[s]?')
except ValueError:
return None
def validateParameterValue(self, v):
if re.search(r'\\[^a-zA-Z0-9_]', v):
raise ValueError('Parameter check failed (escape rule): "%s"' % v)
for s in v:
if not s.isdigit() and not s.isalpha() and s not in [',', '-', '+', '_', ':', '.', '*', '\\', '/', '=']:
raise ValueError('Parameter check failed: "%s"' % v)
def validateParameter(self, name, value):
try:
self.validateParameterValue(value)
except ValueError as e:
raise ValueError('Parameter "%s"="%s": %s' % (name, value, re.sub('^Parameter ', '', str(e))))
return value
def extractParameterEx(self, desc, nameFilter, validationFn=None, allowSpaces=False):
if not desc:
return None
if re.search(nameFilter + r'=', desc):
forbidSpaces = '' if allowSpaces else r'\s'
m = re.search(r'(^|`|\n|\r)(?P<name>' + nameFilter + r')=(?P<value>[^\r\n\t' + forbidSpaces + '`]*)(\r|\n|`|$)', desc)
if m:
name = m.group('name')
value = m.group('value')
if validationFn is None:
value = self.validateParameter(name, value)
else:
value = validationFn(name, value)
return (name, value)
return None
def extractParameter(self, desc, nameFilter, validationFn=None):
def validationFnWrap(name, value):
validationFn(value)
return value
res = self.extractParameterEx(desc, nameFilter, None if validationFn is None else validationFnWrap)
if res is None:
return None
return res[1]
def pushBuildProperty(self, properties, desc, nameFilter, propertyName):
v = self.extractParameterEx(desc, nameFilter)
if v is not None:
print("%s: Apply property '%s'='%s' (from field '%s')" % (self.name, propertyName, v[1], v[0]))
properties.setProperty(propertyName, v[1], 'Pull request')
return v
return None
def getListOfAutomaticBuilders(self, pr):
assert False
def onUpdatePullRequest(self, prid):
pass
def onPullRequestBuildFinished(self, prid, bid, builderName, build, results):
return self.onUpdatePullRequest(prid)