1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import re
22 from twisted.web import resource
23 from twisted.python.reflect import namedModule
24 from twisted.python import log
25 from twisted.internet import defer
28
29 contentType = "text/html; charset=utf-8"
30 children = {}
32 """
33 The keys of 'dialects' select a modules to load under
34 master/buildbot/status/web/hooks/
35 The value is passed to the module's getChanges function, providing
36 configuration options to the dialect.
37 """
38 self.dialects = dialects
39
42
44 """
45 Reponds to events and starts the build process
46 different implementations can decide on what methods they will accept
47 """
48 return self.render_POST(request)
49
50 - def render_POST(self, request):
51 """
52 Reponds to events and starts the build process
53 different implementations can decide on what methods they will accept
54
55 :arguments:
56 request
57 the http request object
58 """
59
60 try:
61 changes = self.getChanges( request )
62 except ValueError, err:
63 request.setResponseCode(400, err.args[0])
64 return defer.succeed(err.args[0])
65
66 log.msg("Payload: " + str(request.args))
67
68 if not changes:
69 log.msg("No changes found")
70 return defer.succeed("no changes found")
71 d = self.submitChanges( changes, request )
72 d.addCallback(lambda _ : "OK")
73 return d
74
75
77 """
78 Take the logic from the change hook, and then delegate it
79 to the proper handler
80 http://localhost/change_hook/DIALECT will load up
81 buildmaster/status/web/hooks/DIALECT.py
82
83 and call getChanges()
84
85 the return value is a list of changes
86
87 if DIALECT is unspecified, a sample implementation is provided
88 """
89 uriRE = re.search(r'^/change_hook/?([a-zA-Z0-9_]*)', request.uri)
90
91 if not uriRE:
92 log.msg("URI doesn't match change_hook regex: %s" % request.uri)
93 raise ValueError("URI doesn't match change_hook regex: %s" % request.uri)
94
95 changes = []
96
97
98 if uriRE.group(1):
99 dialect = uriRE.group(1)
100 else:
101 dialect = 'base'
102
103 if dialect in self.dialects.keys():
104 log.msg("Attempting to load module buildbot.status.web.hooks." + dialect)
105 tempModule = namedModule('buildbot.status.web.hooks.' + dialect)
106 changes = tempModule.getChanges(request,self.dialects[dialect])
107 log.msg("Got the following changes %s" % changes)
108
109 else:
110 m = "The dialect specified, '%s', wasn't whitelisted in change_hook" % dialect
111 log.msg(m)
112 log.msg("Note: if dialect is 'base' then it's possible your URL is malformed and we didn't regex it properly")
113 raise ValueError(m)
114
115 return changes
116
117 @defer.deferredGenerator
119 master = request.site.buildbot_service.master
120 for chdict in changes:
121 wfd = defer.waitForDeferred(master.addChange(**chdict))
122 yield wfd
123 change = wfd.getResult()
124 log.msg("injected change %s" % change)
125