|
| 1 | +// This module is included in the following assembly: |
| 2 | +// |
| 3 | +// *cicd/pipelines/creating-applications-with-cicd-pipelines.adoc |
| 4 | + |
| 5 | +:_content-type: PROCEDURE |
| 6 | +[id="op-validating-pull-requests-using-GitHub-interceptors_{context}"] |
| 7 | += Validating pull requests using GitHub Interceptors |
| 8 | + |
| 9 | +You can use GitHub Interceptor to validate the processing of pull requests based on the GitHub owners configured for a repository. This validation helps you to prevent unnecessary execution of a `PipelineRun` or `TaskRun` object. |
| 10 | +GitHub Interceptor processes a pull request only if the user name is listed as an owner or if a configurable comment is issued by an owner of the repository. For example, when you comment `/ok-to-test` on a pull request as an owner, a `PipelineRun` or `TaskRun` is triggered. |
| 11 | + |
| 12 | +[NOTE] |
| 13 | +==== |
| 14 | +Owners are configured in an `OWNERS` file at the root of the repository. |
| 15 | +==== |
| 16 | + |
| 17 | +.Prerequisites |
| 18 | +* You have installed the {pipelines-title} Operator. |
| 19 | +
|
| 20 | +.Procedure |
| 21 | +. Create a secret string value. |
| 22 | +. Configure the GitHub webhook with that value. |
| 23 | +. Create a Kubernetes secret named `secretRef` that contains your secret value. |
| 24 | +. Pass the Kubernetes secret as a reference to your GitHub Interceptor. |
| 25 | +. Create an `owners` file and add the list of approvers into the `approvers` section. |
| 26 | +. Perform one of the following steps: |
| 27 | +* For a public GitHub repository, set the value of the `githubOwners` parameter to `true` in the YAML configuration file shown below: |
| 28 | ++ |
| 29 | +[source,yaml] |
| 30 | +---- |
| 31 | +apiVersion: triggers.tekton.dev/v1beta1 |
| 32 | +kind: EventListener |
| 33 | +metadata: |
| 34 | + name: github-owners-listener |
| 35 | +spec: |
| 36 | + triggers: |
| 37 | + - name: github-listener |
| 38 | + interceptors: |
| 39 | + - ref: |
| 40 | + name: "github" |
| 41 | + kind: ClusterInterceptor |
| 42 | + apiVersion: triggers.tekton.dev |
| 43 | + params: |
| 44 | + - name: "secretRef" |
| 45 | + value: |
| 46 | + secretName: github-secret |
| 47 | + secretKey: secretToken |
| 48 | + - name: "eventTypes" |
| 49 | + value: ["pull_request", "issue_comment"] |
| 50 | + - name: "githubOwners" |
| 51 | + value: |
| 52 | + enabled: true |
| 53 | + checkType: none |
| 54 | +... |
| 55 | +---- |
| 56 | + |
| 57 | +* For a private GitHub repository, set the value of the `githubOwners` parameter to `true` and provide the access token details, `secretName` and `secretKey` in the YAML configuration file shown below: |
| 58 | ++ |
| 59 | +[source,yaml] |
| 60 | +---- |
| 61 | +apiVersion: triggers.tekton.dev/v1beta1 |
| 62 | +kind: EventListener |
| 63 | +metadata: |
| 64 | + name: github-owners-listener |
| 65 | +spec: |
| 66 | + triggers: |
| 67 | + - name: github-listener |
| 68 | + interceptors: |
| 69 | + - ref: |
| 70 | + name: "github" |
| 71 | + kind: ClusterInterceptor |
| 72 | + apiVersion: triggers.tekton.dev |
| 73 | + params: |
| 74 | + - name: "secretRef" |
| 75 | + value: |
| 76 | + secretName: github-secret |
| 77 | + secretKey: secretToken |
| 78 | + - name: "eventTypes" |
| 79 | + value: ["pull_request", "issue_comment"] |
| 80 | + - name: "githubOwners" |
| 81 | + value: |
| 82 | + enabled: true |
| 83 | + personalAccessToken: |
| 84 | + secretName: github-token |
| 85 | + secretKey: secretToken |
| 86 | + checkType: all |
| 87 | +... |
| 88 | +---- |
| 89 | ++ |
| 90 | +[NOTE] |
| 91 | +==== |
| 92 | +The `checkType` parameter is used to specify the GitHub owners who need authentication. You can set its value to `orgMembers`, `repoMembers`, or `all`. |
| 93 | +==== |
| 94 | +
|
| 95 | +. Save the configuration file. |
0 commit comments