forked from tektoncd/triggers
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add changed files to the github interceptor
This change enriches the github payload of an incoming request with the list of changed files related to a pull_request or push event. The changed files list can be verified using a CEL interceptor to halt processing and/or can be passed down to the pipelineRun where the file list can be used by a task
- Loading branch information
1 parent
b395647
commit f6bd456
Showing
17 changed files
with
1,412 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
## GitHub EventListener | ||
|
||
Creates an EventListener that listens for GitHub webhook events and adds the files that have changed within the pull request or push to the github payload. The list of changed files are added to the `changed_files` property of the event payload in the top-level `extensions` field | ||
|
||
### Try it out locally: | ||
|
||
1. To create the GitHub trigger and all related resources, run: | ||
|
||
```bash | ||
kubectl apply -f . | ||
``` | ||
|
||
1. Port forward: | ||
|
||
```bash | ||
kubectl port-forward service/el-github-add-changed-files-pr-listener 8080 | ||
``` | ||
|
||
1. Test by sending the sample payload. | ||
|
||
```bash | ||
curl -v \ | ||
-H 'X-GitHub-Event: pull_request' \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{"action": "opened","number": 1503,"pull_request": {"head": {"sha": "16dd484bb4888dd30154f5ccb765beae1aaf72de"}},"repository": {"full_name": "tektoncd/triggers","clone_url": "https://github.com/tektoncd/triggers.git"}}' \ | ||
http://localhost:8080 | ||
``` | ||
|
||
The response status code should be `202 Accepted` | ||
|
||
[`HMAC`](https://www.freeformatter.com/hmac-generator.html) tool used to create X-Hub-Signature. | ||
|
||
In [`HMAC`](https://www.freeformatter.com/hmac-generator.html) `string` is the *body payload ex:* `{"action": "opened", "pull_request":{"head":{"sha": "28911bbb5a3e2ea034daf1f6be0a822d50e31e73"}},"repository":{"clone_url": "https://github.com/tektoncd/triggers.git"}}` | ||
and `secretKey` is the *given secretToken ex:* `1234567`. | ||
|
||
1. You should see a new TaskRun that got created: | ||
|
||
```bash | ||
kubectl get taskruns | github-add-changed-files-pr-run- | ||
``` | ||
|
||
1. Get the pod created from the TaskRun and show the logs to see the changed files: | ||
|
||
```bash | ||
kubectl get pods | grep github-add-changed-files-pr-run- | ||
kubectl logs <POD NAME> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
curl -v \ | ||
-H 'X-GitHub-Event: pull_request' \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{"action": "opened","number": 1503,"pull_request": {"head": {"sha": "16dd484bb4888dd30154f5ccb765beae1aaf72de"}},"repository": {"full_name": "tektoncd/triggers","clone_url": "https://github.com/tektoncd/triggers.git"}}' \ | ||
http://localhost:8080 |
65 changes: 65 additions & 0 deletions
65
examples/v1beta1/github-add-changed-files-pr/github-eventlistener-interceptor.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
apiVersion: triggers.tekton.dev/v1beta1 | ||
kind: EventListener | ||
metadata: | ||
name: github-add-changed-files-pr-listener | ||
spec: | ||
triggers: | ||
- name: github-add-changed-files-pr-listener | ||
interceptors: | ||
- ref: | ||
name: "github" | ||
params: | ||
- name: "eventTypes" | ||
value: ["pull_request", "push"] | ||
- name: "addChangedFiles" | ||
value: | ||
enabled: true | ||
bindings: | ||
- ref: github-add-changed-files-pr-pr-binding | ||
template: | ||
ref: github-add-changed-files-pr-template | ||
resources: | ||
kubernetesResource: | ||
spec: | ||
template: | ||
spec: | ||
serviceAccountName: tekton-triggers-example-sa | ||
containers: | ||
- resources: | ||
requests: | ||
memory: "64Mi" | ||
cpu: "250m" | ||
limits: | ||
memory: "128Mi" | ||
cpu: "500m" | ||
--- | ||
apiVersion: triggers.tekton.dev/v1beta1 | ||
kind: TriggerBinding | ||
metadata: | ||
name: github-add-changed-files-pr-pr-binding | ||
spec: | ||
params: | ||
- name: changedfiles | ||
value: $(extensions.changed_files) | ||
|
||
--- | ||
apiVersion: triggers.tekton.dev/v1beta1 | ||
kind: TriggerTemplate | ||
metadata: | ||
name: github-add-changed-files-pr-template | ||
spec: | ||
params: | ||
- name: changedfiles | ||
resourcetemplates: | ||
- apiVersion: tekton.dev/v1beta1 | ||
kind: TaskRun | ||
metadata: | ||
generateName: github-add-changed-files-pr-run- | ||
spec: | ||
taskSpec: | ||
steps: | ||
- image: ubuntu | ||
script: | | ||
#! /bin/bash | ||
echo "Changed Files: $(tt.params.changedfiles)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../rbac.yaml |
53 changes: 53 additions & 0 deletions
53
examples/v1beta1/github-add-changed-files-push-cel/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
## GitHub EventListener | ||
|
||
Creates an EventListener that listens for GitHub webhook events and adds the files that have changed within the pull request or push to the github payload. The list of changed files are added to the `changed_files` property of the event payload in the top-level `extensions` field. It also contains a CEL interceptor that uses the list of changed files to determine whether or not to halt processing | ||
|
||
### Try it out locally: | ||
|
||
1. To create the GitHub trigger and all related resources, run: | ||
|
||
```bash | ||
kubectl apply -f . | ||
``` | ||
|
||
1. Port forward: | ||
|
||
```bash | ||
kubectl port-forward service/el-github-add-changed-files-push-cel-listener 8080 | ||
``` | ||
|
||
1. Test by sending the sample payload. | ||
|
||
```bash | ||
curl -v \ | ||
-H 'X-GitHub-Event: push' \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{"repository":{"full_name":"testowner/testrepo","clone_url":"https://github.com/testowner/testrepo.git"},"commits":[{"added":["api/v1beta1/tektonhelperconfig_types.go","config/crd/bases/tekton-helper..com_tektonhelperconfigs.yaml"],"removed":["config/samples/tektonhelperconfig-oomkillpipeline.yaml","config/samples/tektonhelperconfig-timeout.yaml"],"modified":["controllers/tektonhelperconfig_controller.go"]}]}' \ | ||
http://localhost:8080 | ||
``` | ||
|
||
The response status code should be `202 Accepted` | ||
|
||
[`HMAC`](https://www.freeformatter.com/hmac-generator.html) tool used to create X-Hub-Signature. | ||
|
||
In [`HMAC`](https://www.freeformatter.com/hmac-generator.html) `string` is the *body payload ex:* `{"action": "opened", "pull_request":{"head":{"sha": "28911bbb5a3e2ea034daf1f6be0a822d50e31e73"}},"repository":{"clone_url": "https://github.com/tektoncd/triggers.git"}}` | ||
and `secretKey` is the *given secretToken ex:* `1234567`. | ||
|
||
1. You should see a new TaskRun that got created: | ||
|
||
```bash | ||
kubectl get taskruns | grep github-add-changed-files-push-cel-run- | ||
``` | ||
|
||
1. You should see a new TaskRun that got created: | ||
|
||
```bash | ||
kubectl get taskruns | grep github-add-changed-files-push-cel-run- | ||
``` | ||
|
||
1. Get the pod created from the TaskRun and show the logs to see the changed files: | ||
|
||
```bash | ||
kubectl get pods | grep github-add-changed-files-push-cel-run- | ||
kubectl logs <POD NAME> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
curl -v \ | ||
-H 'X-GitHub-Event: push' \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{"repository":{"full_name":"testowner/testrepo","clone_url":"https://github.com/testowner/testrepo.git"},"commits":[{"added":["api/v1beta1/tektonhelperconfig_types.go","config/crd/bases/tekton-helper..com_tektonhelperconfigs.yaml"],"removed":["config/samples/tektonhelperconfig-oomkillpipeline.yaml","config/samples/tektonhelperconfig-timeout.yaml"],"modified":["controllers/tektonhelperconfig_controller.go"]}]}' \ | ||
http://localhost:8080 |
Oops, something went wrong.