soft-serve webhooks

builr in triggers at last

SEAN K.H. LIAO

soft-serve webhooks

builr in triggers at last

webhooks for soft-serve

charmbracelet/soft-serve is my current choice for git hosting and in release v0.7.1 we finally get webhooks.

Previously, we could (had to) write our own webhook generator which would be run on git post-receive. A slightly less nice thing about the new webhooks feature is that it needs per repo config.

Anyway, payloads look like:

 1{
 2  "after": "cf2d3c9bb11e17eca797d8ab0d80aaef68f19b99",
 3  "before": "b10f0188155ec8643b2ad8d28ded62b0d99febe8",
 4  "commits": [
 5    {
 6      "author": {
 7        "date": "2023-11-13T20:34:44Z",
 8        "email": "sean+git@liao.dev",
 9        "name": "Sean Liao"
10      },
11      "committer": {
12        "date": "2023-11-13T20:34:44Z",
13        "email": "sean+git@liao.dev",
14        "name": "Sean Liao"
15      },
16      "id": "cf2d3c9bb11e17eca797d8ab0d80aaef68f19b99",
17      "message": "unused",
18      "timestamp": "2023-11-13T20:34:44Z",
19      "title": "unused"
20    }
21  ],
22  "event": "push",
23  "ref": "refs/heads/main",
24  "repository": {
25    "created_at": "2023-11-06T21:41:14Z",
26    "default_branch": "main",
27    "description": "",
28    "git_url": "git://localhost/mono.git",
29    "http_url": "https://softserve.ihwa.liao.dev/mono.git",
30    "id": 35,
31    "name": "mono",
32    "owner": {
33      "id": 2,
34      "username": "arccy"
35    },
36    "private": false,
37    "project_name": "",
38    "ssh_url": "ssh://ihwa.liao.dev:23231/mono.git",
39    "updated_at": "2023-11-13T20:26:10Z"
40  },
41  "sender": {
42    "id": 2,
43    "username": "arccy"
44  }
45}

For me, that means mapping it into a tekton pipeline with a Trigger looks something like:

 1apiVersion: triggers.tekton.dev/v1beta1
 2kind: Trigger
 3metadata:
 4  labels:
 5    app.kubernetes.io/name: tekton-builds
 6    event-listener: listener
 7  name: softserve
 8  namespace: tekton-builds
 9spec:
10  interceptors:
11    - ref:
12        name: cel
13      params:
14        - name: filter
15          value: requestURL.parseURL().path.startsWith("/softserve")
16        - name: overlays
17          value:
18            - expression: body.after.truncate(7)
19              key: truncated_sha
20            - expression: '"git+ssh://tekton-ihwa@softserve.softserve.svc/REPO.git".replace("REPO", body.repository.name)'
21              key: repo_url
22            - expression: requestURL.parseURL().path.split("/")[2]
23              key: pipeline
24  bindings:
25    - name: repo_name
26      value: $(body.repository.name)
27    - name: revision
28      value: $(body.after)
29    - name: truncated_sha
30      value: $(extensions.truncated_sha)
31    - name: repo_url
32      value: $(extensions.repo_url)
33    - name: pipeline
34      value: $(extensions.pipeline)
35  template:
36    spec:
37      params:
38        - name: repo_name
39        - name: revision
40        - name: truncated_sha
41        - name: repo_url
42        - name: pipeline
43      resourcetemplates:
44        - apiVersion: tekton.dev/v1
45          kind: PipelineRun
46          metadata:
47            generateName: $(tt.params.repo_name)-$(tt.params.truncated_sha)-
48          spec:
49            params:
50              - name: revision
51                value: $(tt.params.revision)
52              - name: url
53                value: $(tt.params.repo_url)
54            pipelineRef:
55              name: $(tt.params.pipeline)
56            taskRunSpecs:
57              - pipelineTaskName: fetch-source
58                serviceAccountName: softserve-clone
59            workspaces:
60              - name: cloned-repo
61                volumeClaimTemplate:
62                  spec:
63                    accessModes:
64                      - ReadWriteOnce
65                    resources:
66                      requests:
67                        storage: 1Gi