2 # ex: set filetype=python:
4 from buildbot.plugins import secrets, util, webhooks
5 from buildbot.util import bytes2unicode
8 from buildbot_config import E, configure
11 class CustomBase(webhooks.base):
12 def getChanges(self, request):
14 content = request.content.read()
15 args = json.loads(bytes2unicode(content))
16 except Exception as e:
17 raise ValueError("Error loading JSON: " + str(e))
19 args.setdefault("comments", "")
20 args.setdefault("repository", "")
21 args.setdefault("author", args.get("who"))
25 class GitoliteHook(webhooks.base):
26 def getChanges(self, request):
28 branch = request.args[b"branch"][0].decode("utf-8")
29 project = request.args[b"project"][0].decode("utf-8")
30 repository = request.args[b"repository"][0].decode("utf-8")
31 author = request.args[b"author"][0].decode("utf-8")
32 except Exception as e:
33 raise ValueError("Error missing key in request: " + str(e))
36 "author": "gitolite for " + author,
37 "category": "gitolite-hooks",
38 "comments": "gitolite post-receive hook",
41 "repository": repository,
46 userInfoProvider = util.LdapUserInfo(
48 bindUser=E.LDAP_ADMIN_USER,
49 bindPw=open(E.SECRETS_FILE + "/ldap", "r").read().rstrip(),
50 accountBase=E.LDAP_BASE,
51 accountPattern=E.LDAP_PATTERN,
54 avatarData="jpegPhoto",
55 groupBase=E.LDAP_BASE,
57 groupMemberPattern=E.LDAP_GROUP_PATTERN,
60 c = BuildmasterConfig = {
62 "titleURL": E.TITLE_URL,
64 "db_url": "sqlite:///state.sqlite"
66 "protocols": { "pb": { "port": E.PB_SOCKET } },
73 secrets.SecretInAFile(E.SECRETS_FILE),
76 "change_hook_dialects": {
77 "base": { "custom_class": CustomBase },
78 "gitolite": { "custom_class": GitoliteHook },
86 "auth": util.RemoteUserAuth(
87 header=b"X-Remote-User",
88 userInfoProvider=userInfoProvider,
89 headerRegex=re.compile(br"(?P<username>[^ @]+)")),