diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-03-26 01:31:24 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-03-26 10:45:04 +0100 |
commit | 85817848f29f1e2c3680da216a8dfc54a2ad3932 (patch) | |
tree | 21a57b50106701fa461a3767429b5a9f532138cb /nixops/modules/buildbot/projects/caldance | |
parent | 587b9e340bb5cb14ca55e62a0498295e702b56c5 (diff) | |
download | Nix-85817848f29f1e2c3680da216a8dfc54a2ad3932.tar.gz Nix-85817848f29f1e2c3680da216a8dfc54a2ad3932.tar.zst Nix-85817848f29f1e2c3680da216a8dfc54a2ad3932.zip |
Add deploy webhook
Diffstat (limited to 'nixops/modules/buildbot/projects/caldance')
-rw-r--r-- | nixops/modules/buildbot/projects/caldance/__init__.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/nixops/modules/buildbot/projects/caldance/__init__.py b/nixops/modules/buildbot/projects/caldance/__init__.py index e28ef72..1069c35 100644 --- a/nixops/modules/buildbot/projects/caldance/__init__.py +++ b/nixops/modules/buildbot/projects/caldance/__init__.py | |||
@@ -1,6 +1,8 @@ | |||
1 | from buildbot.plugins import * | 1 | from buildbot.plugins import * |
2 | from buildbot_common.build_helpers import * | 2 | from buildbot_common.build_helpers import * |
3 | import os | 3 | import os |
4 | from buildbot.util import bytes2unicode | ||
5 | import json | ||
4 | 6 | ||
5 | __all__ = [ "configure", "E" ] | 7 | __all__ = [ "configure", "E" ] |
6 | 8 | ||
@@ -32,16 +34,52 @@ class E(): | |||
32 | TITLE_URL = "https://caldance.immae.eu" | 34 | TITLE_URL = "https://caldance.immae.eu" |
33 | TITLE = "Caldance" | 35 | TITLE = "Caldance" |
34 | 36 | ||
37 | class CustomBase(webhooks.base): | ||
38 | def getChanges(self, request): | ||
39 | try: | ||
40 | content = request.content.read() | ||
41 | args = json.loads(bytes2unicode(content)) | ||
42 | except Exception as e: | ||
43 | raise ValueError("Error loading JSON: " + str(e)) | ||
44 | |||
45 | args.setdefault("comments", "") | ||
46 | args.setdefault("repository", "") | ||
47 | args.setdefault("author", args.get("who", "unknown")) | ||
48 | |||
49 | if args["category"] == "deploy_webhook": | ||
50 | args = { | ||
51 | "category": "deploy_webhook", | ||
52 | "comments": "", | ||
53 | "repository": "", | ||
54 | "author": "webhook", | ||
55 | "project": "Caldance", | ||
56 | "properties": { | ||
57 | "environment": args.get("environment", "integration"), | ||
58 | "build": "caldance_{}.tar.gz".format(args.get("build", "master")) | ||
59 | } | ||
60 | } | ||
61 | |||
62 | return ([args], None) | ||
63 | |||
64 | def deploy_hook_scheduler(project, timer=1): | ||
65 | return schedulers.AnyBranchScheduler( | ||
66 | change_filter=util.ChangeFilter(category="deploy_webhook", project=project), | ||
67 | name="{}_deploy".format(project), treeStableTimer=timer, builderNames=["{}_deploy".format(project)]) | ||
68 | |||
35 | def configure(c): | 69 | def configure(c): |
36 | c["buildbotURL"] = E.BUILDBOT_URL | 70 | c["buildbotURL"] = E.BUILDBOT_URL |
37 | c["www"]["port"] = E.SOCKET | 71 | c["www"]["port"] = E.SOCKET |
38 | 72 | ||
73 | c["www"]["change_hook_dialects"]["base"] = { | ||
74 | "custom_class": CustomBase | ||
75 | } | ||
39 | c['workers'].append(worker.LocalWorker("generic-worker")) | 76 | c['workers'].append(worker.LocalWorker("generic-worker")) |
40 | c['workers'].append(worker.LocalWorker("deploy-worker")) | 77 | c['workers'].append(worker.LocalWorker("deploy-worker")) |
41 | 78 | ||
42 | c['schedulers'].append(hook_scheduler("Caldance", timer=1)) | 79 | c['schedulers'].append(hook_scheduler("Caldance", timer=1)) |
43 | c['schedulers'].append(force_scheduler("force_caldance", ["Caldance_build"])) | 80 | c['schedulers'].append(force_scheduler("force_caldance", ["Caldance_build"])) |
44 | c['schedulers'].append(deploy_scheduler("deploy_caldance", ["Caldance_deploy"])) | 81 | c['schedulers'].append(deploy_scheduler("deploy_caldance", ["Caldance_deploy"])) |
82 | c['schedulers'].append(deploy_hook_scheduler("Caldance", timer=1)) | ||
45 | 83 | ||
46 | c['builders'].append(factory("caldance")) | 84 | c['builders'].append(factory("caldance")) |
47 | 85 | ||