The github-add-comment task let you add a comment to a pull request or an
issue.
kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/main/task/github-add-comment/0.8/github-add-comment.yaml
This Task requires access to a GitHub token set via a Kubernetes Secret. By default, the name of this Secret should be github and the secret key should be token, but you can configure this via the GITHUB_TOKEN_SECRET_NAME and GITHUB_TOKEN_SECRET_KEY parameters described below.
To create such a Secret via kubectl:
kubectl create secret generic github --from-literal token="MY_TOKEN"
Check this to get personal access token for Github.
See GitHub's documentation on Understanding scopes for OAuth Apps to figure out what scopes you need to give to this token to add comment to an issue or a pull request.
- GITHUB_HOST_URL:: The GitHub host domain (default:
api.github.com) - API_PATH_PREFIX:: The GitHub Enterprise has a prefix for the API path. e.g:
/api/v3 - REQUEST_URL:: The GitHub pull request or issue url, e.g:
https://github.com/tektoncd/catalog/issues/46 - COMMENT_OR_FILE:: The actual comment to add or the filename inside the
optional workspace
comment-filecontaining comment to post. e.g:don't forget to eat your vegetables before commiting.orinput.txt - COMMENT_TAG:: An invisible tag to be added into the comment. The tag is
made invisible by embedding in an an HTML comment. The tag allows
for later retrieval of the comment, and it allows replacing an existing comment. e.g.
myservice.[commit-sha]. (default:""). - REPLACE:: When a tag is specified, and
REPLACEistrue, look for a comment with a matching tag and replace it with the new comment. (default:false). - GITHUB_TOKEN_SECRET_NAME: The name of the Kubernetes Secret that
contains the GitHub token. (default:
github). - GITHUB_TOKEN_SECRET_KEY: The key within the Kubernetes Secret that contains the GitHub token. (default:
token).
- COMMENT_ID:: The numeric id of the comment that was added or updated.
- COMMENT_URL:: The
html_urlof the comment that was added or updated.
Note: In versions
0.4–0.7the results (OLD_COMMENT/NEW_COMMENT) contained the full GitHub API response object, which frequently exceeded the 4096 byte task result (termination message) limit and caused the TaskRun to fail. Starting with0.8only small, bounded values are written to results.
- comment-file: The optional workspace containing comment file to be posted.
The Task can be run on linux/amd64, linux/s390x and linux/ppc64le platforms.
This TaskRun add a comment to an issue.
---
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
labels:
tekton.dev/task: github-add-comment
name: github-add-comment-to-pr-22
spec:
taskRef:
kind: Task
name: github-add-comment
params:
- name: REQUEST_URL
value: https://github.com/chmouel/scratchpad/pull/46
- name: COMMENT_OR_FILE
value: |
The cat went here and there
And the moon spun round like a top,
And the nearest kin of the moon,
The creeping cat, looked up.
Black Minnaloushe stared at the moon,
For, wander and wail as he would,
The pure cold light in the sky
Troubled his animal blood.apiVersion: v1
kind: ConfigMap
metadata:
name: comment-cm
data:
input.txt: |
This is the sample input comment via file.
---
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
labels:
tekton.dev/task: github-add-comment
name: github-add-comment-to-pr-22
spec:
taskRef:
kind: Task
name: github-add-comment
workspace:
- name: comment-file
configMap:
name: comment-cm
params:
- name: REQUEST_URL
value: https://github.com/chmouel/scratchpad/pull/46
- name: COMMENT_OR_FILE
value: "input.txt"---
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: github-add-comment-to-pr-22
spec:
taskRef:
kind: Task
name: github-add-comment
params:
- name: REQUEST_URL
value: https://github.com/chmouel/scratchpad/pull/46
- name: COMMENT_TAG
value: catalog-sha123abc
- name: REPLACE
value: "true"
- name: COMMENT_OR_FILE
value: |
The cat went here and there
And the moon spun round like a top,
And the nearest kin of the moon,
The creeping cat, looked up.
Black Minnaloushe stared at the moon,
For, wander and wail as he would,
The pure cold light in the sky
Troubled his animal blood.