Skip to content

Commit

Permalink
Turn on PRCommenter on completion of PR builds
Browse files Browse the repository at this point in the history
Closes tektoncd#483

I could have added a new `TriggerTemplate`, but it made more sense to just turn the existing `tekton-ci-github-check-end` into a `PipelineRun`.

I did have to add a couple new parameters - the bare repo name (since I wrote up the PR commenter to have the org as a global configuration), and a boolean for pass/fail. It may make sense to tweak the PR commenter to handle `org/repo` instead of just `repo`, and `"success"` or `"failure"` instead of `true` or `false`, but I thought I'd wait to see what people think. =)

Signed-off-by: Andrew Bayer <andrew.bayer@gmail.com>
  • Loading branch information
abayer committed Sep 29, 2022
1 parent 51cbc8b commit 5840e44
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
2 changes: 2 additions & 0 deletions tekton/resources/cd/eventlistener.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ spec:
expression: body.taskRun.metadata.annotations['tekton.dev/gitURL'].parseURL().path.substring(1).split('/').join('_')
- key: shortSourceEventID
expression: body.taskRun.metadata.labels['tekton.dev/source-event-id'].truncate(13)
- key: repoName
expression: body.taskRun.metadata.annotations['tekton.dev/gitURL'].parseURL().path.substring(1).split('/')[1]
triggerSelector:
namespaceSelector:
matchNames:
Expand Down
6 changes: 6 additions & 0 deletions tekton/resources/ci/bindings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ spec:
value: success
- name: gitHubCheckDescription
value: "Job Successful."
- name: gitHubCheckIsSuccess
value: "true"
---
apiVersion: triggers.tekton.dev/v1alpha1
kind: TriggerBinding
Expand All @@ -49,6 +51,8 @@ spec:
value: failure
- name: gitHubCheckDescription
value: "Job Failed."
- name: gitHubCheckIsSuccess
value: "false"
---
apiVersion: triggers.tekton.dev/v1alpha1
kind: TriggerBinding
Expand All @@ -73,3 +77,5 @@ spec:
value: $(extensions.shortSourceEventID)
- name: gitHubRepoUnderscore
value: $(extensions.repoUnderscore)
- name: gitHubRepoName
value: $(extensions.repoName)
44 changes: 34 additions & 10 deletions tekton/resources/ci/github-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ spec:
description: A truncated version of the sourceEventId
- name: gitHubRepo
description: The gitHubRepo (org/repo)
- name: gitHubRepoName
description: The gitHubRepo's name (repo)
- name: gitHubRepoUnderscore
description: The gitHubRepoUnderscore (org_repo)
- name: gitRevision
Expand All @@ -105,7 +107,7 @@ spec:
default: ""
resourcetemplates:
- apiVersion: tekton.dev/v1beta1
kind: TaskRun
kind: PipelineRun
metadata:
name: $(tt.params.shortSourceEventID)-$(tt.params.checkName)-$(tt.params.gitHubCheckStatus)
namespace: tekton-ci
Expand All @@ -115,15 +117,17 @@ spec:
ci.tekton.dev/source-taskrun-name: $(tt.params.taskRunName)
tekton.dev/pr-number: $(tt.params.pullRequestNumber)
spec:
serviceAccountName: tekton-ci-jobs
podTemplate:
securityContext:
runAsNonRoot: true
runAsUser: 1001
taskRef:
name: github-set-status
bundle: gcr.io/tekton-releases/catalog/upstream/github-set-status:0.2
params:
tasks:
- name: set-status
serviceAccountName: tekton-ci-jobs
podTemplate:
securityContext:
runAsNonRoot: true
runAsUser: 1001
taskRef:
name: github-set-status
bundle: gcr.io/tekton-releases/catalog/upstream/github-set-status:0.2
params:
- name: REPO_FULL_NAME
value: $(tt.params.gitHubRepo)
- name: SHA
Expand All @@ -140,3 +144,23 @@ spec:
value: bot-token-github
- name: GITHUB_TOKEN_SECRET_KEY
value: bot-token
- name: comment-on-pr
taskRef:
apiVersion: custom.tekton.dev/v0
kind: PRCommenter
params:
- name: repo
value: $(tt.params.gitHubRepoName)
- name: prNumber
value: $(tt.params.pullRequestNumber)
- name: sha
value: $(tt.params.gitRevision)
- name: jobName
value: $(tt.params.checkName)
- name: isSuccess
value: $(tt.params.gitHubCheckIsSuccess)
- name: isOptional
value: "false"
- name: logURL
value: https://prow.tekton.dev/view/gs/tekton-prow/pr-logs/pull/$(tt.params.gitHubRepoUnderscore)/$(tt.params.pullRequestNumber)/$(tt.params.checkName)/$(tt.params.buildUUID)

0 comments on commit 5840e44

Please sign in to comment.