-
Notifications
You must be signed in to change notification settings - Fork 582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DELETE option to github-add-comment #1051
Conversation
Diff between version 0.7 and 0.8diff --git a/task/github-add-comment/0.7/README.md b/task/github-add-comment/0.8/README.md
index f3951b9..94c183f 100644
--- a/task/github-add-comment/0.7/README.md
+++ b/task/github-add-comment/0.8/README.md
@@ -36,6 +36,8 @@ See GitHub's documentation on [Understanding scopes for OAuth Apps](https://deve
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 `REPLACE` is `true`, look for a
comment with a matching tag and replace it with the new comment. (_default:_ `false`).
+- **DELETE:**: When a tag is specified and `DELETE` is true, look for a comment
+ with a matching tag and delete it, instead of adding a 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`).
@@ -144,4 +146,4 @@ spec:
Black Minnaloushe stared at the moon,
For, wander and wail as he would,
The pure cold light in the sky
- Troubled his animal blood.
\ No newline at end of file
+ Troubled his animal blood.
diff --git a/task/github-add-comment/0.7/github-add-comment.yaml b/task/github-add-comment/0.8/github-add-comment.yaml
index 82683d8..980afcf 100644
--- a/task/github-add-comment/0.7/github-add-comment.yaml
+++ b/task/github-add-comment/0.8/github-add-comment.yaml
@@ -4,7 +4,7 @@ kind: Task
metadata:
name: github-add-comment
labels:
- app.kubernetes.io/version: "0.7"
+ app.kubernetes.io/version: "0.8"
annotations:
tekton.dev/categories: Git
tekton.dev/pipelines.minVersion: "0.17.0"
@@ -87,6 +87,13 @@ spec:
type: string
default: "false" # Alternative value: "true"
+ - name: DELETE
+ description: |
+ When a tag is specified, and `DELETE` is `true`, look for a comment
+ with a matching tag and delete it instead of adding a new comment.
+ type: string
+ default: "false" # Alternative value: "true"
+
steps:
- name: post-comment
workingDir: $(workspaces.comment-file.path)
@@ -138,9 +145,9 @@ spec:
# If REPLACE is true, we need to search for comments first
matching_comment = ""
- if "$(params.REPLACE)" == "true":
+ if "$(params.REPLACE)" == "true" or "$(params.DELETE)" == "true":
if not "$(params.COMMENT_TAG)":
- print("REPLACE requested but no COMMENT_TAG specified")
+ print("REPLACE or DELETE requested but no COMMENT_TAG specified")
sys.exit(1)
r = conn.request(
"GET",
@@ -167,7 +174,12 @@ spec:
matching_comment = matching_comment[0]['url']
if matching_comment:
- method = "PATCH"
+ if "$(params.REPLACE)" == "true":
+ method = "PATCH"
+ else if "$(params.DELETE)" == "true":
+ # if DELETE is true, don't send any data.
+ method = "DELETE"
+ data = {}
target_url = urllib.parse.urlparse(matching_comment).path
else:
method = "POST"
diff --git a/task/github-add-comment/0.7/tests/fixtures/github-post-comment.yaml b/task/github-add-comment/0.8/tests/fixtures/github-post-comment.yaml
index bdc851a..ec7978e 100644
--- a/task/github-add-comment/0.7/tests/fixtures/github-post-comment.yaml
+++ b/task/github-add-comment/0.8/tests/fixtures/github-post-comment.yaml
@@ -15,6 +15,14 @@ response:
status: 200
content-type: text/json
file: /fixtures/list-comment-response.json
+---
+headers:
+ method: DELETE
+ path: /repos/{repo:[^/]+/[^/]+}/issues/comments/{comment:[0-9]+}
+response:
+ status: 204
+ output: '{"status": 204}'
+ content-type: text/json
# GitHub Enterprise Server
---
@@ -32,4 +40,12 @@ headers:
response:
status: 200
content-type: text/json
- file: /fixtures/list-comment-response-ghe.json
\ No newline at end of file
+ file: /fixtures/list-comment-response-ghe.json
+---
+headers:
+ method: DELETE
+ path: /api/v3/repos/{repo:[^/]+/[^/]+}/issues/comments/{comment:[0-9]+}
+response:
+ status: 204
+ output: '{"status": 204}'
+ content-type: text/json
diff --git a/task/github-add-comment/0.7/tests/run.yaml b/task/github-add-comment/0.8/tests/run.yaml
index 788bcd5..eec57fc 100644
--- a/task/github-add-comment/0.7/tests/run.yaml
+++ b/task/github-add-comment/0.8/tests/run.yaml
@@ -54,6 +54,20 @@ spec:
#!/usr/libexec/platform-python
assert "$(params.EXPECTED_OLD_COMMENT)" in "$(params.ACTUAL_OLD_COMMENT)"
+ - name: delete-comment
+ taskRef:
+ name: github-add-comment
+ params:
+ - name: GITHUB_HOST_URL
+ value: http://127.0.0.1:8080
+ - name: API_PATH_PREFIX
+ value: $(params.API_PATH_PREFIX)
+ - name: REQUEST_URL
+ value: https://github.com/tektoncd/catalog/issues/1
+ - name: DELETE
+ value: "true"
+ - name: COMMENT_TAG
+ value: TEST_TAG123
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun |
Catlin Output
Catlin script lint Output
|
748b4c1
to
347b1cd
Compare
Diff between version 0.7 and 0.8diff --git a/task/github-add-comment/0.7/README.md b/task/github-add-comment/0.8/README.md
index f3951b9..94c183f 100644
--- a/task/github-add-comment/0.7/README.md
+++ b/task/github-add-comment/0.8/README.md
@@ -36,6 +36,8 @@ See GitHub's documentation on [Understanding scopes for OAuth Apps](https://deve
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 `REPLACE` is `true`, look for a
comment with a matching tag and replace it with the new comment. (_default:_ `false`).
+- **DELETE:**: When a tag is specified and `DELETE` is true, look for a comment
+ with a matching tag and delete it, instead of adding a 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`).
@@ -144,4 +146,4 @@ spec:
Black Minnaloushe stared at the moon,
For, wander and wail as he would,
The pure cold light in the sky
- Troubled his animal blood.
\ No newline at end of file
+ Troubled his animal blood.
diff --git a/task/github-add-comment/0.7/github-add-comment.yaml b/task/github-add-comment/0.8/github-add-comment.yaml
index 82683d8..980afcf 100644
--- a/task/github-add-comment/0.7/github-add-comment.yaml
+++ b/task/github-add-comment/0.8/github-add-comment.yaml
@@ -4,7 +4,7 @@ kind: Task
metadata:
name: github-add-comment
labels:
- app.kubernetes.io/version: "0.7"
+ app.kubernetes.io/version: "0.8"
annotations:
tekton.dev/categories: Git
tekton.dev/pipelines.minVersion: "0.17.0"
@@ -87,6 +87,13 @@ spec:
type: string
default: "false" # Alternative value: "true"
+ - name: DELETE
+ description: |
+ When a tag is specified, and `DELETE` is `true`, look for a comment
+ with a matching tag and delete it instead of adding a new comment.
+ type: string
+ default: "false" # Alternative value: "true"
+
steps:
- name: post-comment
workingDir: $(workspaces.comment-file.path)
@@ -138,9 +145,9 @@ spec:
# If REPLACE is true, we need to search for comments first
matching_comment = ""
- if "$(params.REPLACE)" == "true":
+ if "$(params.REPLACE)" == "true" or "$(params.DELETE)" == "true":
if not "$(params.COMMENT_TAG)":
- print("REPLACE requested but no COMMENT_TAG specified")
+ print("REPLACE or DELETE requested but no COMMENT_TAG specified")
sys.exit(1)
r = conn.request(
"GET",
@@ -167,7 +174,12 @@ spec:
matching_comment = matching_comment[0]['url']
if matching_comment:
- method = "PATCH"
+ if "$(params.REPLACE)" == "true":
+ method = "PATCH"
+ else if "$(params.DELETE)" == "true":
+ # if DELETE is true, don't send any data.
+ method = "DELETE"
+ data = {}
target_url = urllib.parse.urlparse(matching_comment).path
else:
method = "POST"
diff --git a/task/github-add-comment/0.7/tests/fixtures/github-post-comment.yaml b/task/github-add-comment/0.8/tests/fixtures/github-post-comment.yaml
index bdc851a..ec7978e 100644
--- a/task/github-add-comment/0.7/tests/fixtures/github-post-comment.yaml
+++ b/task/github-add-comment/0.8/tests/fixtures/github-post-comment.yaml
@@ -15,6 +15,14 @@ response:
status: 200
content-type: text/json
file: /fixtures/list-comment-response.json
+---
+headers:
+ method: DELETE
+ path: /repos/{repo:[^/]+/[^/]+}/issues/comments/{comment:[0-9]+}
+response:
+ status: 204
+ output: '{"status": 204}'
+ content-type: text/json
# GitHub Enterprise Server
---
@@ -32,4 +40,12 @@ headers:
response:
status: 200
content-type: text/json
- file: /fixtures/list-comment-response-ghe.json
\ No newline at end of file
+ file: /fixtures/list-comment-response-ghe.json
+---
+headers:
+ method: DELETE
+ path: /api/v3/repos/{repo:[^/]+/[^/]+}/issues/comments/{comment:[0-9]+}
+response:
+ status: 204
+ output: '{"status": 204}'
+ content-type: text/json
diff --git a/task/github-add-comment/0.7/tests/run.yaml b/task/github-add-comment/0.8/tests/run.yaml
index 788bcd5..5a3ff6f 100644
--- a/task/github-add-comment/0.7/tests/run.yaml
+++ b/task/github-add-comment/0.8/tests/run.yaml
@@ -54,6 +54,22 @@ spec:
#!/usr/libexec/platform-python
assert "$(params.EXPECTED_OLD_COMMENT)" in "$(params.ACTUAL_OLD_COMMENT)"
+ - name: delete-comment
+ taskRef:
+ name: github-add-comment
+ params:
+ - name: GITHUB_HOST_URL
+ value: http://127.0.0.1:8080
+ - name: API_PATH_PREFIX
+ value: $(params.API_PATH_PREFIX)
+ - name: COMMENT_OR_FILE
+ value: ""
+ - name: REQUEST_URL
+ value: https://github.com/tektoncd/catalog/issues/1
+ - name: DELETE
+ value: "true"
+ - name: COMMENT_TAG
+ value: TEST_TAG123
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun |
Catlin Output
Catlin script lint Output
|
347b1cd
to
c711042
Compare
Diff between version 0.7 and 0.8diff --git a/task/github-add-comment/0.7/README.md b/task/github-add-comment/0.8/README.md
index f3951b9..94c183f 100644
--- a/task/github-add-comment/0.7/README.md
+++ b/task/github-add-comment/0.8/README.md
@@ -36,6 +36,8 @@ See GitHub's documentation on [Understanding scopes for OAuth Apps](https://deve
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 `REPLACE` is `true`, look for a
comment with a matching tag and replace it with the new comment. (_default:_ `false`).
+- **DELETE:**: When a tag is specified and `DELETE` is true, look for a comment
+ with a matching tag and delete it, instead of adding a 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`).
@@ -144,4 +146,4 @@ spec:
Black Minnaloushe stared at the moon,
For, wander and wail as he would,
The pure cold light in the sky
- Troubled his animal blood.
\ No newline at end of file
+ Troubled his animal blood.
diff --git a/task/github-add-comment/0.7/github-add-comment.yaml b/task/github-add-comment/0.8/github-add-comment.yaml
index 82683d8..d07234a 100644
--- a/task/github-add-comment/0.7/github-add-comment.yaml
+++ b/task/github-add-comment/0.8/github-add-comment.yaml
@@ -4,7 +4,7 @@ kind: Task
metadata:
name: github-add-comment
labels:
- app.kubernetes.io/version: "0.7"
+ app.kubernetes.io/version: "0.8"
annotations:
tekton.dev/categories: Git
tekton.dev/pipelines.minVersion: "0.17.0"
@@ -87,6 +87,13 @@ spec:
type: string
default: "false" # Alternative value: "true"
+ - name: DELETE
+ description: |
+ When a tag is specified, and `DELETE` is `true`, look for a comment
+ with a matching tag and delete it instead of adding a new comment.
+ type: string
+ default: "false" # Alternative value: "true"
+
steps:
- name: post-comment
workingDir: $(workspaces.comment-file.path)
@@ -138,9 +145,9 @@ spec:
# If REPLACE is true, we need to search for comments first
matching_comment = ""
- if "$(params.REPLACE)" == "true":
+ if "$(params.REPLACE)" == "true" or "$(params.DELETE)" == "true":
if not "$(params.COMMENT_TAG)":
- print("REPLACE requested but no COMMENT_TAG specified")
+ print("REPLACE or DELETE requested but no COMMENT_TAG specified")
sys.exit(1)
r = conn.request(
"GET",
@@ -167,7 +174,12 @@ spec:
matching_comment = matching_comment[0]['url']
if matching_comment:
- method = "PATCH"
+ if "$(params.REPLACE)" == "true":
+ method = "PATCH"
+ elif "$(params.DELETE)" == "true":
+ # if DELETE is true, don't send any data.
+ method = "DELETE"
+ data = {}
target_url = urllib.parse.urlparse(matching_comment).path
else:
method = "POST"
diff --git a/task/github-add-comment/0.7/tests/fixtures/github-post-comment.yaml b/task/github-add-comment/0.8/tests/fixtures/github-post-comment.yaml
index bdc851a..ec7978e 100644
--- a/task/github-add-comment/0.7/tests/fixtures/github-post-comment.yaml
+++ b/task/github-add-comment/0.8/tests/fixtures/github-post-comment.yaml
@@ -15,6 +15,14 @@ response:
status: 200
content-type: text/json
file: /fixtures/list-comment-response.json
+---
+headers:
+ method: DELETE
+ path: /repos/{repo:[^/]+/[^/]+}/issues/comments/{comment:[0-9]+}
+response:
+ status: 204
+ output: '{"status": 204}'
+ content-type: text/json
# GitHub Enterprise Server
---
@@ -32,4 +40,12 @@ headers:
response:
status: 200
content-type: text/json
- file: /fixtures/list-comment-response-ghe.json
\ No newline at end of file
+ file: /fixtures/list-comment-response-ghe.json
+---
+headers:
+ method: DELETE
+ path: /api/v3/repos/{repo:[^/]+/[^/]+}/issues/comments/{comment:[0-9]+}
+response:
+ status: 204
+ output: '{"status": 204}'
+ content-type: text/json
diff --git a/task/github-add-comment/0.7/tests/run.yaml b/task/github-add-comment/0.8/tests/run.yaml
index 788bcd5..5a3ff6f 100644
--- a/task/github-add-comment/0.7/tests/run.yaml
+++ b/task/github-add-comment/0.8/tests/run.yaml
@@ -54,6 +54,22 @@ spec:
#!/usr/libexec/platform-python
assert "$(params.EXPECTED_OLD_COMMENT)" in "$(params.ACTUAL_OLD_COMMENT)"
+ - name: delete-comment
+ taskRef:
+ name: github-add-comment
+ params:
+ - name: GITHUB_HOST_URL
+ value: http://127.0.0.1:8080
+ - name: API_PATH_PREFIX
+ value: $(params.API_PATH_PREFIX)
+ - name: COMMENT_OR_FILE
+ value: ""
+ - name: REQUEST_URL
+ value: https://github.com/tektoncd/catalog/issues/1
+ - name: DELETE
+ value: "true"
+ - name: COMMENT_TAG
+ value: TEST_TAG123
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun |
Catlin Output
Catlin script lint Output
|
c711042
to
bf6c4c7
Compare
Diff between version 0.7 and 0.8diff --git a/task/github-add-comment/0.7/README.md b/task/github-add-comment/0.8/README.md
index f3951b9..94c183f 100644
--- a/task/github-add-comment/0.7/README.md
+++ b/task/github-add-comment/0.8/README.md
@@ -36,6 +36,8 @@ See GitHub's documentation on [Understanding scopes for OAuth Apps](https://deve
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 `REPLACE` is `true`, look for a
comment with a matching tag and replace it with the new comment. (_default:_ `false`).
+- **DELETE:**: When a tag is specified and `DELETE` is true, look for a comment
+ with a matching tag and delete it, instead of adding a 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`).
@@ -144,4 +146,4 @@ spec:
Black Minnaloushe stared at the moon,
For, wander and wail as he would,
The pure cold light in the sky
- Troubled his animal blood.
\ No newline at end of file
+ Troubled his animal blood.
diff --git a/task/github-add-comment/0.7/github-add-comment.yaml b/task/github-add-comment/0.8/github-add-comment.yaml
index 82683d8..324a485 100644
--- a/task/github-add-comment/0.7/github-add-comment.yaml
+++ b/task/github-add-comment/0.8/github-add-comment.yaml
@@ -4,7 +4,7 @@ kind: Task
metadata:
name: github-add-comment
labels:
- app.kubernetes.io/version: "0.7"
+ app.kubernetes.io/version: "0.8"
annotations:
tekton.dev/categories: Git
tekton.dev/pipelines.minVersion: "0.17.0"
@@ -87,6 +87,13 @@ spec:
type: string
default: "false" # Alternative value: "true"
+ - name: DELETE
+ description: |
+ When a tag is specified, and `DELETE` is `true`, look for a comment
+ with a matching tag and delete it instead of adding a new comment.
+ type: string
+ default: "false" # Alternative value: "true"
+
steps:
- name: post-comment
workingDir: $(workspaces.comment-file.path)
@@ -138,9 +145,9 @@ spec:
# If REPLACE is true, we need to search for comments first
matching_comment = ""
- if "$(params.REPLACE)" == "true":
+ if "$(params.REPLACE)" == "true" or "$(params.DELETE)" == "true":
if not "$(params.COMMENT_TAG)":
- print("REPLACE requested but no COMMENT_TAG specified")
+ print("REPLACE or DELETE requested but no COMMENT_TAG specified")
sys.exit(1)
r = conn.request(
"GET",
@@ -167,22 +174,36 @@ spec:
matching_comment = matching_comment[0]['url']
if matching_comment:
- method = "PATCH"
+ if "$(params.REPLACE)" == "true":
+ method = "PATCH"
+ elif "$(params.DELETE)" == "true":
+ method = "DELETE"
target_url = urllib.parse.urlparse(matching_comment).path
else:
method = "POST"
target_url = api_url + "/comments"
- print("Sending this data to GitHub with {}: ".format(method))
- print(data)
- r = conn.request(
- method,
- target_url,
- body=json.dumps(data),
- headers={
- "User-Agent": "TektonCD, the peaceful cat",
- "Authorization": authHeader,
- })
+ # if DELETE is true, don't send any data.
+ if "$(params.DELETE)" == "true":
+ print("Deleting comment on GitHub")
+ r = conn.request(
+ method,
+ target_url,
+ headers={
+ "User-Agent": "TektonCD, the peaceful cat",
+ "Authorization": authHeader,
+ })
+ else:
+ print("Sending this data to GitHub with {}: ".format(method))
+ print(data)
+ r = conn.request(
+ method,
+ target_url,
+ body=json.dumps(data),
+ headers={
+ "User-Agent": "TektonCD, the peaceful cat",
+ "Authorization": authHeader,
+ })
resp = conn.getresponse()
if not str(resp.status).startswith("2"):
print("Error: %d" % (resp.status))
diff --git a/task/github-add-comment/0.7/tests/fixtures/github-post-comment.yaml b/task/github-add-comment/0.8/tests/fixtures/github-post-comment.yaml
index bdc851a..ec7978e 100644
--- a/task/github-add-comment/0.7/tests/fixtures/github-post-comment.yaml
+++ b/task/github-add-comment/0.8/tests/fixtures/github-post-comment.yaml
@@ -15,6 +15,14 @@ response:
status: 200
content-type: text/json
file: /fixtures/list-comment-response.json
+---
+headers:
+ method: DELETE
+ path: /repos/{repo:[^/]+/[^/]+}/issues/comments/{comment:[0-9]+}
+response:
+ status: 204
+ output: '{"status": 204}'
+ content-type: text/json
# GitHub Enterprise Server
---
@@ -32,4 +40,12 @@ headers:
response:
status: 200
content-type: text/json
- file: /fixtures/list-comment-response-ghe.json
\ No newline at end of file
+ file: /fixtures/list-comment-response-ghe.json
+---
+headers:
+ method: DELETE
+ path: /api/v3/repos/{repo:[^/]+/[^/]+}/issues/comments/{comment:[0-9]+}
+response:
+ status: 204
+ output: '{"status": 204}'
+ content-type: text/json
diff --git a/task/github-add-comment/0.7/tests/run.yaml b/task/github-add-comment/0.8/tests/run.yaml
index 788bcd5..5a3ff6f 100644
--- a/task/github-add-comment/0.7/tests/run.yaml
+++ b/task/github-add-comment/0.8/tests/run.yaml
@@ -54,6 +54,22 @@ spec:
#!/usr/libexec/platform-python
assert "$(params.EXPECTED_OLD_COMMENT)" in "$(params.ACTUAL_OLD_COMMENT)"
+ - name: delete-comment
+ taskRef:
+ name: github-add-comment
+ params:
+ - name: GITHUB_HOST_URL
+ value: http://127.0.0.1:8080
+ - name: API_PATH_PREFIX
+ value: $(params.API_PATH_PREFIX)
+ - name: COMMENT_OR_FILE
+ value: ""
+ - name: REQUEST_URL
+ value: https://github.com/tektoncd/catalog/issues/1
+ - name: DELETE
+ value: "true"
+ - name: COMMENT_TAG
+ value: TEST_TAG123
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun |
Catlin Output
Catlin script lint Output
|
bf6c4c7
to
edf353a
Compare
...you may notice that I don't know python at all well, so I'm not sure what's breaking. =) |
Diff between version 0.7 and 0.8diff --git a/task/github-add-comment/0.7/README.md b/task/github-add-comment/0.8/README.md
index f3951b9..94c183f 100644
--- a/task/github-add-comment/0.7/README.md
+++ b/task/github-add-comment/0.8/README.md
@@ -36,6 +36,8 @@ See GitHub's documentation on [Understanding scopes for OAuth Apps](https://deve
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 `REPLACE` is `true`, look for a
comment with a matching tag and replace it with the new comment. (_default:_ `false`).
+- **DELETE:**: When a tag is specified and `DELETE` is true, look for a comment
+ with a matching tag and delete it, instead of adding a 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`).
@@ -144,4 +146,4 @@ spec:
Black Minnaloushe stared at the moon,
For, wander and wail as he would,
The pure cold light in the sky
- Troubled his animal blood.
\ No newline at end of file
+ Troubled his animal blood.
diff --git a/task/github-add-comment/0.7/github-add-comment.yaml b/task/github-add-comment/0.8/github-add-comment.yaml
index 82683d8..505a47d 100644
--- a/task/github-add-comment/0.7/github-add-comment.yaml
+++ b/task/github-add-comment/0.8/github-add-comment.yaml
@@ -4,7 +4,7 @@ kind: Task
metadata:
name: github-add-comment
labels:
- app.kubernetes.io/version: "0.7"
+ app.kubernetes.io/version: "0.8"
annotations:
tekton.dev/categories: Git
tekton.dev/pipelines.minVersion: "0.17.0"
@@ -87,6 +87,13 @@ spec:
type: string
default: "false" # Alternative value: "true"
+ - name: DELETE
+ description: |
+ When a tag is specified, and `DELETE` is `true`, look for a comment
+ with a matching tag and delete it instead of adding a new comment.
+ type: string
+ default: "false" # Alternative value: "true"
+
steps:
- name: post-comment
workingDir: $(workspaces.comment-file.path)
@@ -138,9 +145,9 @@ spec:
# If REPLACE is true, we need to search for comments first
matching_comment = ""
- if "$(params.REPLACE)" == "true":
+ if "$(params.REPLACE)" == "true" or "$(params.DELETE)" == "true":
if not "$(params.COMMENT_TAG)":
- print("REPLACE requested but no COMMENT_TAG specified")
+ print("REPLACE or DELETE requested but no COMMENT_TAG specified")
sys.exit(1)
r = conn.request(
"GET",
@@ -167,22 +174,36 @@ spec:
matching_comment = matching_comment[0]['url']
if matching_comment:
- method = "PATCH"
+ if "$(params.DELETE)" == "true":
+ method = "DELETE"
+ else:
+ method = "PATCH"
target_url = urllib.parse.urlparse(matching_comment).path
else:
method = "POST"
target_url = api_url + "/comments"
- print("Sending this data to GitHub with {}: ".format(method))
- print(data)
- r = conn.request(
- method,
- target_url,
- body=json.dumps(data),
- headers={
- "User-Agent": "TektonCD, the peaceful cat",
- "Authorization": authHeader,
- })
+ # if DELETE is true, don't send any data.
+ if "$(params.DELETE)" == "true":
+ print("Deleting comment on GitHub")
+ r = conn.request(
+ method,
+ target_url,
+ headers={
+ "User-Agent": "TektonCD, the peaceful cat",
+ "Authorization": authHeader,
+ })
+ else:
+ print("Sending this data to GitHub with {}: ".format(method))
+ print(data)
+ r = conn.request(
+ method,
+ target_url,
+ body=json.dumps(data),
+ headers={
+ "User-Agent": "TektonCD, the peaceful cat",
+ "Authorization": authHeader,
+ })
resp = conn.getresponse()
if not str(resp.status).startswith("2"):
print("Error: %d" % (resp.status))
diff --git a/task/github-add-comment/0.7/tests/fixtures/github-post-comment.yaml b/task/github-add-comment/0.8/tests/fixtures/github-post-comment.yaml
index bdc851a..ec7978e 100644
--- a/task/github-add-comment/0.7/tests/fixtures/github-post-comment.yaml
+++ b/task/github-add-comment/0.8/tests/fixtures/github-post-comment.yaml
@@ -15,6 +15,14 @@ response:
status: 200
content-type: text/json
file: /fixtures/list-comment-response.json
+---
+headers:
+ method: DELETE
+ path: /repos/{repo:[^/]+/[^/]+}/issues/comments/{comment:[0-9]+}
+response:
+ status: 204
+ output: '{"status": 204}'
+ content-type: text/json
# GitHub Enterprise Server
---
@@ -32,4 +40,12 @@ headers:
response:
status: 200
content-type: text/json
- file: /fixtures/list-comment-response-ghe.json
\ No newline at end of file
+ file: /fixtures/list-comment-response-ghe.json
+---
+headers:
+ method: DELETE
+ path: /api/v3/repos/{repo:[^/]+/[^/]+}/issues/comments/{comment:[0-9]+}
+response:
+ status: 204
+ output: '{"status": 204}'
+ content-type: text/json
diff --git a/task/github-add-comment/0.7/tests/run.yaml b/task/github-add-comment/0.8/tests/run.yaml
index 788bcd5..5a3ff6f 100644
--- a/task/github-add-comment/0.7/tests/run.yaml
+++ b/task/github-add-comment/0.8/tests/run.yaml
@@ -54,6 +54,22 @@ spec:
#!/usr/libexec/platform-python
assert "$(params.EXPECTED_OLD_COMMENT)" in "$(params.ACTUAL_OLD_COMMENT)"
+ - name: delete-comment
+ taskRef:
+ name: github-add-comment
+ params:
+ - name: GITHUB_HOST_URL
+ value: http://127.0.0.1:8080
+ - name: API_PATH_PREFIX
+ value: $(params.API_PATH_PREFIX)
+ - name: COMMENT_OR_FILE
+ value: ""
+ - name: REQUEST_URL
+ value: https://github.com/tektoncd/catalog/issues/1
+ - name: DELETE
+ value: "true"
+ - name: COMMENT_TAG
+ value: TEST_TAG123
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun |
edf353a
to
894df2b
Compare
Catlin Output
Catlin script lint Output
|
Diff between version 0.7 and 0.8diff --git a/task/github-add-comment/0.7/README.md b/task/github-add-comment/0.8/README.md
index f3951b9..94c183f 100644
--- a/task/github-add-comment/0.7/README.md
+++ b/task/github-add-comment/0.8/README.md
@@ -36,6 +36,8 @@ See GitHub's documentation on [Understanding scopes for OAuth Apps](https://deve
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 `REPLACE` is `true`, look for a
comment with a matching tag and replace it with the new comment. (_default:_ `false`).
+- **DELETE:**: When a tag is specified and `DELETE` is true, look for a comment
+ with a matching tag and delete it, instead of adding a 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`).
@@ -144,4 +146,4 @@ spec:
Black Minnaloushe stared at the moon,
For, wander and wail as he would,
The pure cold light in the sky
- Troubled his animal blood.
\ No newline at end of file
+ Troubled his animal blood.
diff --git a/task/github-add-comment/0.7/github-add-comment.yaml b/task/github-add-comment/0.8/github-add-comment.yaml
index 82683d8..505a47d 100644
--- a/task/github-add-comment/0.7/github-add-comment.yaml
+++ b/task/github-add-comment/0.8/github-add-comment.yaml
@@ -4,7 +4,7 @@ kind: Task
metadata:
name: github-add-comment
labels:
- app.kubernetes.io/version: "0.7"
+ app.kubernetes.io/version: "0.8"
annotations:
tekton.dev/categories: Git
tekton.dev/pipelines.minVersion: "0.17.0"
@@ -87,6 +87,13 @@ spec:
type: string
default: "false" # Alternative value: "true"
+ - name: DELETE
+ description: |
+ When a tag is specified, and `DELETE` is `true`, look for a comment
+ with a matching tag and delete it instead of adding a new comment.
+ type: string
+ default: "false" # Alternative value: "true"
+
steps:
- name: post-comment
workingDir: $(workspaces.comment-file.path)
@@ -138,9 +145,9 @@ spec:
# If REPLACE is true, we need to search for comments first
matching_comment = ""
- if "$(params.REPLACE)" == "true":
+ if "$(params.REPLACE)" == "true" or "$(params.DELETE)" == "true":
if not "$(params.COMMENT_TAG)":
- print("REPLACE requested but no COMMENT_TAG specified")
+ print("REPLACE or DELETE requested but no COMMENT_TAG specified")
sys.exit(1)
r = conn.request(
"GET",
@@ -167,22 +174,36 @@ spec:
matching_comment = matching_comment[0]['url']
if matching_comment:
- method = "PATCH"
+ if "$(params.DELETE)" == "true":
+ method = "DELETE"
+ else:
+ method = "PATCH"
target_url = urllib.parse.urlparse(matching_comment).path
else:
method = "POST"
target_url = api_url + "/comments"
- print("Sending this data to GitHub with {}: ".format(method))
- print(data)
- r = conn.request(
- method,
- target_url,
- body=json.dumps(data),
- headers={
- "User-Agent": "TektonCD, the peaceful cat",
- "Authorization": authHeader,
- })
+ # if DELETE is true, don't send any data.
+ if "$(params.DELETE)" == "true":
+ print("Deleting comment on GitHub")
+ r = conn.request(
+ method,
+ target_url,
+ headers={
+ "User-Agent": "TektonCD, the peaceful cat",
+ "Authorization": authHeader,
+ })
+ else:
+ print("Sending this data to GitHub with {}: ".format(method))
+ print(data)
+ r = conn.request(
+ method,
+ target_url,
+ body=json.dumps(data),
+ headers={
+ "User-Agent": "TektonCD, the peaceful cat",
+ "Authorization": authHeader,
+ })
resp = conn.getresponse()
if not str(resp.status).startswith("2"):
print("Error: %d" % (resp.status))
diff --git a/task/github-add-comment/0.7/tests/fixtures/github-post-comment.yaml b/task/github-add-comment/0.8/tests/fixtures/github-post-comment.yaml
index bdc851a..ec7978e 100644
--- a/task/github-add-comment/0.7/tests/fixtures/github-post-comment.yaml
+++ b/task/github-add-comment/0.8/tests/fixtures/github-post-comment.yaml
@@ -15,6 +15,14 @@ response:
status: 200
content-type: text/json
file: /fixtures/list-comment-response.json
+---
+headers:
+ method: DELETE
+ path: /repos/{repo:[^/]+/[^/]+}/issues/comments/{comment:[0-9]+}
+response:
+ status: 204
+ output: '{"status": 204}'
+ content-type: text/json
# GitHub Enterprise Server
---
@@ -32,4 +40,12 @@ headers:
response:
status: 200
content-type: text/json
- file: /fixtures/list-comment-response-ghe.json
\ No newline at end of file
+ file: /fixtures/list-comment-response-ghe.json
+---
+headers:
+ method: DELETE
+ path: /api/v3/repos/{repo:[^/]+/[^/]+}/issues/comments/{comment:[0-9]+}
+response:
+ status: 204
+ output: '{"status": 204}'
+ content-type: text/json
diff --git a/task/github-add-comment/0.7/tests/run.yaml b/task/github-add-comment/0.8/tests/run.yaml
index 788bcd5..2b42c45 100644
--- a/task/github-add-comment/0.7/tests/run.yaml
+++ b/task/github-add-comment/0.8/tests/run.yaml
@@ -54,6 +54,24 @@ spec:
#!/usr/libexec/platform-python
assert "$(params.EXPECTED_OLD_COMMENT)" in "$(params.ACTUAL_OLD_COMMENT)"
+ - name: delete-comment
+ runAfter:
+ - verify-result
+ taskRef:
+ name: github-add-comment
+ params:
+ - name: GITHUB_HOST_URL
+ value: http://127.0.0.1:8080
+ - name: API_PATH_PREFIX
+ value: $(params.API_PATH_PREFIX)
+ - name: COMMENT_OR_FILE
+ value: ""
+ - name: REQUEST_URL
+ value: https://github.com/tektoncd/catalog/issues/1
+ - name: DELETE
+ value: "true"
+ - name: COMMENT_TAG
+ value: TEST_TAG123
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun |
Catlin Output
Catlin script lint Output
|
894df2b
to
40362e0
Compare
Catlin Output
Catlin script lint Output
|
Diff between version 0.7 and 0.8diff --git a/task/github-add-comment/0.7/README.md b/task/github-add-comment/0.8/README.md
index f3951b9..94c183f 100644
--- a/task/github-add-comment/0.7/README.md
+++ b/task/github-add-comment/0.8/README.md
@@ -36,6 +36,8 @@ See GitHub's documentation on [Understanding scopes for OAuth Apps](https://deve
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 `REPLACE` is `true`, look for a
comment with a matching tag and replace it with the new comment. (_default:_ `false`).
+- **DELETE:**: When a tag is specified and `DELETE` is true, look for a comment
+ with a matching tag and delete it, instead of adding a 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`).
@@ -144,4 +146,4 @@ spec:
Black Minnaloushe stared at the moon,
For, wander and wail as he would,
The pure cold light in the sky
- Troubled his animal blood.
\ No newline at end of file
+ Troubled his animal blood.
diff --git a/task/github-add-comment/0.7/github-add-comment.yaml b/task/github-add-comment/0.8/github-add-comment.yaml
index 82683d8..b039f8f 100644
--- a/task/github-add-comment/0.7/github-add-comment.yaml
+++ b/task/github-add-comment/0.8/github-add-comment.yaml
@@ -4,7 +4,7 @@ kind: Task
metadata:
name: github-add-comment
labels:
- app.kubernetes.io/version: "0.7"
+ app.kubernetes.io/version: "0.8"
annotations:
tekton.dev/categories: Git
tekton.dev/pipelines.minVersion: "0.17.0"
@@ -87,6 +87,13 @@ spec:
type: string
default: "false" # Alternative value: "true"
+ - name: DELETE
+ description: |
+ When a tag is specified, and `DELETE` is `true`, look for a comment
+ with a matching tag and delete it instead of adding a new comment.
+ type: string
+ default: "false" # Alternative value: "true"
+
steps:
- name: post-comment
workingDir: $(workspaces.comment-file.path)
@@ -138,9 +145,9 @@ spec:
# If REPLACE is true, we need to search for comments first
matching_comment = ""
- if "$(params.REPLACE)" == "true":
+ if "$(params.REPLACE)" == "true" or "$(params.DELETE)" == "true":
if not "$(params.COMMENT_TAG)":
- print("REPLACE requested but no COMMENT_TAG specified")
+ print("REPLACE or DELETE requested but no COMMENT_TAG specified")
sys.exit(1)
r = conn.request(
"GET",
@@ -167,22 +174,36 @@ spec:
matching_comment = matching_comment[0]['url']
if matching_comment:
- method = "PATCH"
+ if "$(params.DELETE)" == "true":
+ method = "DELETE"
+ else:
+ method = "PATCH"
target_url = urllib.parse.urlparse(matching_comment).path
else:
method = "POST"
target_url = api_url + "/comments"
- print("Sending this data to GitHub with {}: ".format(method))
- print(data)
- r = conn.request(
- method,
- target_url,
- body=json.dumps(data),
- headers={
- "User-Agent": "TektonCD, the peaceful cat",
- "Authorization": authHeader,
- })
+ # if DELETE is true, don't send any data.
+ if method == "DELETE":
+ print("Deleting comment on GitHub at {}".format(target_url))
+ r = conn.request(
+ method,
+ target_url,
+ headers={
+ "User-Agent": "TektonCD, the peaceful cat",
+ "Authorization": authHeader,
+ })
+ else:
+ print("Sending this data to GitHub with {}: ".format(method))
+ print(data)
+ r = conn.request(
+ method,
+ target_url,
+ body=json.dumps(data),
+ headers={
+ "User-Agent": "TektonCD, the peaceful cat",
+ "Authorization": authHeader,
+ })
resp = conn.getresponse()
if not str(resp.status).startswith("2"):
print("Error: %d" % (resp.status))
diff --git a/task/github-add-comment/0.7/tests/fixtures/github-post-comment.yaml b/task/github-add-comment/0.8/tests/fixtures/github-post-comment.yaml
index bdc851a..ec7978e 100644
--- a/task/github-add-comment/0.7/tests/fixtures/github-post-comment.yaml
+++ b/task/github-add-comment/0.8/tests/fixtures/github-post-comment.yaml
@@ -15,6 +15,14 @@ response:
status: 200
content-type: text/json
file: /fixtures/list-comment-response.json
+---
+headers:
+ method: DELETE
+ path: /repos/{repo:[^/]+/[^/]+}/issues/comments/{comment:[0-9]+}
+response:
+ status: 204
+ output: '{"status": 204}'
+ content-type: text/json
# GitHub Enterprise Server
---
@@ -32,4 +40,12 @@ headers:
response:
status: 200
content-type: text/json
- file: /fixtures/list-comment-response-ghe.json
\ No newline at end of file
+ file: /fixtures/list-comment-response-ghe.json
+---
+headers:
+ method: DELETE
+ path: /api/v3/repos/{repo:[^/]+/[^/]+}/issues/comments/{comment:[0-9]+}
+response:
+ status: 204
+ output: '{"status": 204}'
+ content-type: text/json
diff --git a/task/github-add-comment/0.7/tests/run.yaml b/task/github-add-comment/0.8/tests/run.yaml
index 788bcd5..2b42c45 100644
--- a/task/github-add-comment/0.7/tests/run.yaml
+++ b/task/github-add-comment/0.8/tests/run.yaml
@@ -54,6 +54,24 @@ spec:
#!/usr/libexec/platform-python
assert "$(params.EXPECTED_OLD_COMMENT)" in "$(params.ACTUAL_OLD_COMMENT)"
+ - name: delete-comment
+ runAfter:
+ - verify-result
+ taskRef:
+ name: github-add-comment
+ params:
+ - name: GITHUB_HOST_URL
+ value: http://127.0.0.1:8080
+ - name: API_PATH_PREFIX
+ value: $(params.API_PATH_PREFIX)
+ - name: COMMENT_OR_FILE
+ value: ""
+ - name: REQUEST_URL
+ value: https://github.com/tektoncd/catalog/issues/1
+ - name: DELETE
+ value: "true"
+ - name: COMMENT_TAG
+ value: TEST_TAG123
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun |
40362e0
to
71d9c82
Compare
Diff between version 0.7 and 0.8diff --git a/task/github-add-comment/0.7/README.md b/task/github-add-comment/0.8/README.md
index f3951b9..94c183f 100644
--- a/task/github-add-comment/0.7/README.md
+++ b/task/github-add-comment/0.8/README.md
@@ -36,6 +36,8 @@ See GitHub's documentation on [Understanding scopes for OAuth Apps](https://deve
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 `REPLACE` is `true`, look for a
comment with a matching tag and replace it with the new comment. (_default:_ `false`).
+- **DELETE:**: When a tag is specified and `DELETE` is true, look for a comment
+ with a matching tag and delete it, instead of adding a 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`).
@@ -144,4 +146,4 @@ spec:
Black Minnaloushe stared at the moon,
For, wander and wail as he would,
The pure cold light in the sky
- Troubled his animal blood.
\ No newline at end of file
+ Troubled his animal blood.
diff --git a/task/github-add-comment/0.7/github-add-comment.yaml b/task/github-add-comment/0.8/github-add-comment.yaml
index 82683d8..b80e6fa 100644
--- a/task/github-add-comment/0.7/github-add-comment.yaml
+++ b/task/github-add-comment/0.8/github-add-comment.yaml
@@ -4,7 +4,7 @@ kind: Task
metadata:
name: github-add-comment
labels:
- app.kubernetes.io/version: "0.7"
+ app.kubernetes.io/version: "0.8"
annotations:
tekton.dev/categories: Git
tekton.dev/pipelines.minVersion: "0.17.0"
@@ -87,6 +87,13 @@ spec:
type: string
default: "false" # Alternative value: "true"
+ - name: DELETE
+ description: |
+ When a tag is specified, and `DELETE` is `true`, look for a comment
+ with a matching tag and delete it instead of adding a new comment.
+ type: string
+ default: "false" # Alternative value: "true"
+
steps:
- name: post-comment
workingDir: $(workspaces.comment-file.path)
@@ -138,9 +145,9 @@ spec:
# If REPLACE is true, we need to search for comments first
matching_comment = ""
- if "$(params.REPLACE)" == "true":
+ if "$(params.REPLACE)" == "true" or "$(params.DELETE)" == "true":
if not "$(params.COMMENT_TAG)":
- print("REPLACE requested but no COMMENT_TAG specified")
+ print("REPLACE or DELETE requested but no COMMENT_TAG specified")
sys.exit(1)
r = conn.request(
"GET",
@@ -167,28 +174,42 @@ spec:
matching_comment = matching_comment[0]['url']
if matching_comment:
- method = "PATCH"
+ if "$(params.DELETE)" == "true":
+ method = "DELETE"
+ else:
+ method = "PATCH"
target_url = urllib.parse.urlparse(matching_comment).path
else:
method = "POST"
target_url = api_url + "/comments"
- print("Sending this data to GitHub with {}: ".format(method))
- print(data)
- r = conn.request(
- method,
- target_url,
- body=json.dumps(data),
- headers={
- "User-Agent": "TektonCD, the peaceful cat",
- "Authorization": authHeader,
- })
+ # if DELETE is true, don't send any data.
+ if method == "DELETE":
+ print("Deleting comment on GitHub at {}".format(target_url))
+ r = conn.request(
+ method,
+ target_url,
+ headers={
+ "User-Agent": "TektonCD, the peaceful cat",
+ "Authorization": authHeader,
+ })
+ else:
+ print("Sending this data to GitHub with {}: ".format(method))
+ print(data)
+ r = conn.request(
+ method,
+ target_url,
+ body=json.dumps(data),
+ headers={
+ "User-Agent": "TektonCD, the peaceful cat",
+ "Authorization": authHeader,
+ })
resp = conn.getresponse()
if not str(resp.status).startswith("2"):
print("Error: %d" % (resp.status))
print(resp.read())
sys.exit(1)
- else:
+ elif method != "DELETE:
with open("$(results.NEW_COMMENT.path)", "wb") as result_new:
result_new.write(resp.read())
print("a GitHub comment has been {} to $(params.REQUEST_URL)".format(
diff --git a/task/github-add-comment/0.7/tests/fixtures/github-post-comment.yaml b/task/github-add-comment/0.8/tests/fixtures/github-post-comment.yaml
index bdc851a..25d827a 100644
--- a/task/github-add-comment/0.7/tests/fixtures/github-post-comment.yaml
+++ b/task/github-add-comment/0.8/tests/fixtures/github-post-comment.yaml
@@ -15,6 +15,12 @@ response:
status: 200
content-type: text/json
file: /fixtures/list-comment-response.json
+---
+headers:
+ method: DELETE
+ path: /repos/{repo:[^/]+/[^/]+}/issues/comments/{comment:[0-9]+}
+response:
+ status: 204
# GitHub Enterprise Server
---
@@ -32,4 +38,10 @@ headers:
response:
status: 200
content-type: text/json
- file: /fixtures/list-comment-response-ghe.json
\ No newline at end of file
+ file: /fixtures/list-comment-response-ghe.json
+---
+headers:
+ method: DELETE
+ path: /api/v3/repos/{repo:[^/]+/[^/]+}/issues/comments/{comment:[0-9]+}
+response:
+ status: 204
diff --git a/task/github-add-comment/0.7/tests/run.yaml b/task/github-add-comment/0.8/tests/run.yaml
index 788bcd5..2b42c45 100644
--- a/task/github-add-comment/0.7/tests/run.yaml
+++ b/task/github-add-comment/0.8/tests/run.yaml
@@ -54,6 +54,24 @@ spec:
#!/usr/libexec/platform-python
assert "$(params.EXPECTED_OLD_COMMENT)" in "$(params.ACTUAL_OLD_COMMENT)"
+ - name: delete-comment
+ runAfter:
+ - verify-result
+ taskRef:
+ name: github-add-comment
+ params:
+ - name: GITHUB_HOST_URL
+ value: http://127.0.0.1:8080
+ - name: API_PATH_PREFIX
+ value: $(params.API_PATH_PREFIX)
+ - name: COMMENT_OR_FILE
+ value: ""
+ - name: REQUEST_URL
+ value: https://github.com/tektoncd/catalog/issues/1
+ - name: DELETE
+ value: "true"
+ - name: COMMENT_TAG
+ value: TEST_TAG123
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun |
Catlin Output
Catlin script lint Output
|
This will be used as part of tektoncd/plumbing#483 in Tekton's own CI setup, and I think it could be generally useful for replicating behavior such as Prow's job failure comments. Those comments are deleted once the job completes next, with a new comment created for subsequent failures, so that the latest result is always towards the end of the comment list. Signed-off-by: Andrew Bayer <[email protected]>
71d9c82
to
81c1c05
Compare
Catlin Output
Catlin script lint Output
|
Diff between version 0.7 and 0.8diff --git a/task/github-add-comment/0.7/README.md b/task/github-add-comment/0.8/README.md
index f3951b9..94c183f 100644
--- a/task/github-add-comment/0.7/README.md
+++ b/task/github-add-comment/0.8/README.md
@@ -36,6 +36,8 @@ See GitHub's documentation on [Understanding scopes for OAuth Apps](https://deve
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 `REPLACE` is `true`, look for a
comment with a matching tag and replace it with the new comment. (_default:_ `false`).
+- **DELETE:**: When a tag is specified and `DELETE` is true, look for a comment
+ with a matching tag and delete it, instead of adding a 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`).
@@ -144,4 +146,4 @@ spec:
Black Minnaloushe stared at the moon,
For, wander and wail as he would,
The pure cold light in the sky
- Troubled his animal blood.
\ No newline at end of file
+ Troubled his animal blood.
diff --git a/task/github-add-comment/0.7/github-add-comment.yaml b/task/github-add-comment/0.8/github-add-comment.yaml
index 82683d8..60d4f7e 100644
--- a/task/github-add-comment/0.7/github-add-comment.yaml
+++ b/task/github-add-comment/0.8/github-add-comment.yaml
@@ -4,7 +4,7 @@ kind: Task
metadata:
name: github-add-comment
labels:
- app.kubernetes.io/version: "0.7"
+ app.kubernetes.io/version: "0.8"
annotations:
tekton.dev/categories: Git
tekton.dev/pipelines.minVersion: "0.17.0"
@@ -87,6 +87,13 @@ spec:
type: string
default: "false" # Alternative value: "true"
+ - name: DELETE
+ description: |
+ When a tag is specified, and `DELETE` is `true`, look for a comment
+ with a matching tag and delete it instead of adding a new comment.
+ type: string
+ default: "false" # Alternative value: "true"
+
steps:
- name: post-comment
workingDir: $(workspaces.comment-file.path)
@@ -138,9 +145,9 @@ spec:
# If REPLACE is true, we need to search for comments first
matching_comment = ""
- if "$(params.REPLACE)" == "true":
+ if "$(params.REPLACE)" == "true" or "$(params.DELETE)" == "true":
if not "$(params.COMMENT_TAG)":
- print("REPLACE requested but no COMMENT_TAG specified")
+ print("REPLACE or DELETE requested but no COMMENT_TAG specified")
sys.exit(1)
r = conn.request(
"GET",
@@ -167,28 +174,42 @@ spec:
matching_comment = matching_comment[0]['url']
if matching_comment:
- method = "PATCH"
+ if "$(params.DELETE)" == "true":
+ method = "DELETE"
+ else:
+ method = "PATCH"
target_url = urllib.parse.urlparse(matching_comment).path
else:
method = "POST"
target_url = api_url + "/comments"
- print("Sending this data to GitHub with {}: ".format(method))
- print(data)
- r = conn.request(
- method,
- target_url,
- body=json.dumps(data),
- headers={
- "User-Agent": "TektonCD, the peaceful cat",
- "Authorization": authHeader,
- })
+ # if DELETE is true, don't send any data.
+ if method == "DELETE":
+ print("Deleting comment on GitHub at {}".format(target_url))
+ r = conn.request(
+ method,
+ target_url,
+ headers={
+ "User-Agent": "TektonCD, the peaceful cat",
+ "Authorization": authHeader,
+ })
+ else:
+ print("Sending this data to GitHub with {}: ".format(method))
+ print(data)
+ r = conn.request(
+ method,
+ target_url,
+ body=json.dumps(data),
+ headers={
+ "User-Agent": "TektonCD, the peaceful cat",
+ "Authorization": authHeader,
+ })
resp = conn.getresponse()
if not str(resp.status).startswith("2"):
print("Error: %d" % (resp.status))
print(resp.read())
sys.exit(1)
- else:
+ elif method != "DELETE":
with open("$(results.NEW_COMMENT.path)", "wb") as result_new:
result_new.write(resp.read())
print("a GitHub comment has been {} to $(params.REQUEST_URL)".format(
diff --git a/task/github-add-comment/0.7/tests/fixtures/github-post-comment.yaml b/task/github-add-comment/0.8/tests/fixtures/github-post-comment.yaml
index bdc851a..25d827a 100644
--- a/task/github-add-comment/0.7/tests/fixtures/github-post-comment.yaml
+++ b/task/github-add-comment/0.8/tests/fixtures/github-post-comment.yaml
@@ -15,6 +15,12 @@ response:
status: 200
content-type: text/json
file: /fixtures/list-comment-response.json
+---
+headers:
+ method: DELETE
+ path: /repos/{repo:[^/]+/[^/]+}/issues/comments/{comment:[0-9]+}
+response:
+ status: 204
# GitHub Enterprise Server
---
@@ -32,4 +38,10 @@ headers:
response:
status: 200
content-type: text/json
- file: /fixtures/list-comment-response-ghe.json
\ No newline at end of file
+ file: /fixtures/list-comment-response-ghe.json
+---
+headers:
+ method: DELETE
+ path: /api/v3/repos/{repo:[^/]+/[^/]+}/issues/comments/{comment:[0-9]+}
+response:
+ status: 204
diff --git a/task/github-add-comment/0.7/tests/run.yaml b/task/github-add-comment/0.8/tests/run.yaml
index 788bcd5..2b42c45 100644
--- a/task/github-add-comment/0.7/tests/run.yaml
+++ b/task/github-add-comment/0.8/tests/run.yaml
@@ -54,6 +54,24 @@ spec:
#!/usr/libexec/platform-python
assert "$(params.EXPECTED_OLD_COMMENT)" in "$(params.ACTUAL_OLD_COMMENT)"
+ - name: delete-comment
+ runAfter:
+ - verify-result
+ taskRef:
+ name: github-add-comment
+ params:
+ - name: GITHUB_HOST_URL
+ value: http://127.0.0.1:8080
+ - name: API_PATH_PREFIX
+ value: $(params.API_PATH_PREFIX)
+ - name: COMMENT_OR_FILE
+ value: ""
+ - name: REQUEST_URL
+ value: https://github.com/tektoncd/catalog/issues/1
+ - name: DELETE
+ value: "true"
+ - name: COMMENT_TAG
+ value: TEST_TAG123
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun |
api_url = "{base}/repos/{package}/issues/{id}".format( | ||
base="$(params.API_PATH_PREFIX)", package="/".join(split_url[1:3]), id=split_url[-1]) | ||
|
||
commentParamValue = """$(params.COMMENT_OR_FILE)""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the workspace is not bound, will we just end up making a comment with the filename?
"GET", | ||
api_url + "/comments", | ||
headers={ | ||
"User-Agent": "TektonCD, the peaceful cat", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
XD
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: dibyom The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/hold So I don't trust my Python skills enough - I'm working on a custom task specific for the Tekton project's own use cases. =) |
Part of tektoncd#483 This custom task is meant to be used alongside PR status report updates to add/update/delete a comment equivalent to the Prow one listing job failures with links to logs and the command to re-test. I initially made an attempt to update the `github-add-comment` task in the catalog to do this (tektoncd/catalog#1051) but decided that a custom task frankly made a lot more sense. Its behavior is a pretty direct emulation of how Prow and Lighthouse do this, looking for existing comments by the bot user with a given tag in the comment, and updating/deleting that comment if it exists, creating a new comment otherwise. It's a bit simplified, and instead of using `ProwJob`s to know what should still be in the comment and what should be removed, it specifically just adds or removes the specific job it's reporting on while preserving whatever else was there. Signed-off-by: Andrew Bayer <[email protected]>
Part of tektoncd#483 This custom task is meant to be used alongside PR status report updates to add/update/delete a comment equivalent to the Prow one listing job failures with links to logs and the command to re-test. I initially made an attempt to update the `github-add-comment` task in the catalog to do this (tektoncd/catalog#1051) but decided that a custom task frankly made a lot more sense. Its behavior is a pretty direct emulation of how Prow and Lighthouse do this, looking for existing comments by the bot user with a given tag in the comment, and updating/deleting that comment if it exists, creating a new comment otherwise. It's a bit simplified, and instead of using `ProwJob`s to know what should still be in the comment and what should be removed, it specifically just adds or removes the specific job it's reporting on while preserving whatever else was there. Signed-off-by: Andrew Bayer <[email protected]>
Part of tektoncd#483 This custom task is meant to be used alongside PR status report updates to add/update/delete a comment equivalent to the Prow one listing job failures with links to logs and the command to re-test. I initially made an attempt to update the `github-add-comment` task in the catalog to do this (tektoncd/catalog#1051) but decided that a custom task frankly made a lot more sense. Its behavior is a pretty direct emulation of how Prow and Lighthouse do this, looking for existing comments by the bot user with a given tag in the comment, and updating/deleting that comment if it exists, creating a new comment otherwise. It's a bit simplified, and instead of using `ProwJob`s to know what should still be in the comment and what should be removed, it specifically just adds or removes the specific job it's reporting on while preserving whatever else was there. Signed-off-by: Andrew Bayer <[email protected]>
Part of tektoncd#483 This custom task is meant to be used alongside PR status report updates to add/update/delete a comment equivalent to the Prow one listing job failures with links to logs and the command to re-test. I initially made an attempt to update the `github-add-comment` task in the catalog to do this (tektoncd/catalog#1051) but decided that a custom task frankly made a lot more sense. Its behavior is a pretty direct emulation of how Prow and Lighthouse do this, looking for existing comments by the bot user with a given tag in the comment, and updating/deleting that comment if it exists, creating a new comment otherwise. It's a bit simplified, and instead of using `ProwJob`s to know what should still be in the comment and what should be removed, it specifically just adds or removes the specific job it's reporting on while preserving whatever else was there. Signed-off-by: Andrew Bayer <[email protected]>
Part of tektoncd#483 This custom task is meant to be used alongside PR status report updates to add/update/delete a comment equivalent to the Prow one listing job failures with links to logs and the command to re-test. I initially made an attempt to update the `github-add-comment` task in the catalog to do this (tektoncd/catalog#1051) but decided that a custom task frankly made a lot more sense. Its behavior is a pretty direct emulation of how Prow and Lighthouse do this, looking for existing comments by the bot user with a given tag in the comment, and updating/deleting that comment if it exists, creating a new comment otherwise. It's a bit simplified, and instead of using `ProwJob`s to know what should still be in the comment and what should be removed, it specifically just adds or removes the specific job it's reporting on while preserving whatever else was there. Signed-off-by: Andrew Bayer <[email protected]>
Part of #483 This custom task is meant to be used alongside PR status report updates to add/update/delete a comment equivalent to the Prow one listing job failures with links to logs and the command to re-test. I initially made an attempt to update the `github-add-comment` task in the catalog to do this (tektoncd/catalog#1051) but decided that a custom task frankly made a lot more sense. Its behavior is a pretty direct emulation of how Prow and Lighthouse do this, looking for existing comments by the bot user with a given tag in the comment, and updating/deleting that comment if it exists, creating a new comment otherwise. It's a bit simplified, and instead of using `ProwJob`s to know what should still be in the comment and what should be removed, it specifically just adds or removes the specific job it's reporting on while preserving whatever else was there. Signed-off-by: Andrew Bayer <[email protected]>
Issues go stale after 90d of inactivity. /lifecycle stale Send feedback to tektoncd/plumbing. |
Stale issues rot after 30d of inactivity. /lifecycle rotten Send feedback to tektoncd/plumbing. |
Rotten issues close after 30d of inactivity. /close Send feedback to tektoncd/plumbing. |
@tekton-robot: Closed this PR. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Changes
This will be used as part of tektoncd/plumbing#483 in Tekton's own CI setup, and I think it could be generally useful for replicating behavior such as Prow's job failure comments. Those comments are deleted once the job completes next, with a new comment created for subsequent failures, so that the latest result is always towards the end of the comment list.
/kind feature
Submitter Checklist
These are the criteria that every PR should meet, please check them off as you
review them:
contains
/kind <type>
. Valid types are bug, cleanup, design, documentation,feature, flake, misc, question, tep
File path follows
<kind>/<name>/<version>/name.yaml
Has
README.md
at<kind>/<name>/<version>/README.md
Has mandatory
metadata.labels
-app.kubernetes.io/version
the same as the<version>
of the resourceHas mandatory
metadata.annotations
tekton.dev/pipelines.minVersion
mandatory
spec.description
follows the conventionSee the contribution guide
for more details.
[docs] https://github.com/tektoncd/community/blob/master/standards.md#docs
[tests] https://github.com/tektoncd/community/blob/master/standards.md#tests
[e2e] https://github.com/tektoncd/catalog/blob/main/CONTRIBUTING.md#end-to-end-testing
[contributor] https://github.com/tektoncd/community/blob/main/standards.md
[commit] https://github.com/tektoncd/community/blob/master/standards.md#commit-messages