]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - flakes/private/buildbot/common/master.cfg
Add config for CI
[perso/Immae/Config/Nix.git] / flakes / private / buildbot / common / master.cfg
1 # -*- python -*-
2 # ex: set filetype=python:
3
4 from buildbot.plugins import secrets, util, webhooks
5 from buildbot.util import bytes2unicode
6 import re
7 import os
8 from buildbot_config import E, configure
9 import json
10
11 class CustomBase(webhooks.base):
12 def getChanges(self, request):
13 try:
14 content = request.content.read()
15 args = json.loads(bytes2unicode(content))
16 except Exception as e:
17 raise ValueError("Error loading JSON: " + str(e))
18
19 args.setdefault("comments", "")
20 args.setdefault("repository", "")
21 args.setdefault("author", args.get("who"))
22
23 return ([args], None)
24
25 class GitoliteHook(webhooks.base):
26 def getChanges(self, request):
27 try:
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))
34
35 args = {
36 "author": "gitolite for " + author,
37 "category": "gitolite-hooks",
38 "comments": "gitolite post-receive hook",
39 "branch": branch,
40 "project": project,
41 "repository": repository,
42 }
43
44 return ([args], None)
45
46 userInfoProvider = util.LdapUserInfo(
47 uri=E.LDAP_URL,
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,
52 accountFullName='cn',
53 accountEmail='mail',
54 avatarData="jpegPhoto",
55 groupBase=E.LDAP_BASE,
56 groupName="cn",
57 groupMemberPattern=E.LDAP_GROUP_PATTERN,
58 )
59
60 c = BuildmasterConfig = {
61 "title": E.TITLE,
62 "titleURL": E.TITLE_URL,
63 "db": {
64 "db_url": "sqlite:///state.sqlite"
65 },
66 "protocols": { "pb": { "port": E.PB_SOCKET } },
67 "workers": [],
68 "change_source": [],
69 "schedulers": [],
70 "builders": [],
71 "services": [],
72 "secretsProviders": [
73 secrets.SecretInAFile(E.SECRETS_FILE),
74 ],
75 "www": {
76 "change_hook_dialects": {
77 "base": { "custom_class": CustomBase },
78 "gitolite": { "custom_class": GitoliteHook },
79 },
80 "plugins": {
81 "waterfall_view": {},
82 "console_view": {},
83 "grid_view": {},
84 "buildslist": {},
85 },
86 "auth": util.RemoteUserAuth(
87 header=b"X-Remote-User",
88 userInfoProvider=userInfoProvider,
89 headerRegex=re.compile(br"(?P<username>[^ @]+)")),
90 }
91 }
92
93 configure(c)