Add DELETE option to github-add-comment
Changes
This will be used as part of https://github.com/tektoncd/plumbing/issues/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:
- [x] Follows the authoring recommendations
- [x] Includes [docs][docs] (if user facing)
- [x] Includes [tests][tests] (for new tasks or changed functionality)
- See the [end-to-end testing documentation][e2e] for guidance and CI details.
- [x] Meets the [Tekton contributor standards][contributor] (including functionality, content, code)
- [x] Commit messages follow [commit message best practices][commit]
- [x] Has a kind label. You can add one by adding a comment on this PR that
contains
/kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tep - [x] Complies with Catalog Organization TEP, see example. Note An issue has been filed to automate this validation
-
[x] File path follows
<kind>/<name>/<version>/name.yaml -
[x] Has
README.mdat<kind>/<name>/<version>/README.md -
[x] Has mandatory
metadata.labels-app.kubernetes.io/versionthe same as the<version>of the resource -
[x] Has mandatory
metadata.annotationstekton.dev/pipelines.minVersion -
[x] mandatory
spec.descriptionfollows the convention``` spec: description: >- one line summary of the resource Paragraph(s) to describe the resource. ```
-
See 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
Diff between version 0.7 and 0.8
diff --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
FILE: task/github-add-comment/0.8/github-add-comment.yaml
WARN : Step "post-comment" uses secret to populate env "GITHUBTOKEN". Prefer using secrets as files over secrets as environment variables
WARN : Step "post-comment" references "$(params.AUTH_TYPE)" directly from its script block. For reliability and security, consider putting the param into an environment variable of the Step and accessing that environment variable in your script instead.
Catlin script lint Output
WARN : step: github-add-comment is not using #!/usr/bin/env
ERROR: /usr/bin/pylint, [-dC0103] failed:
************* Module catlin-script-linter733289601
github-add-comment-post-comment:71:10: E0001: invalid syntax (<unknown>, line 71) (syntax-error)
Diff between version 0.7 and 0.8
diff --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
FILE: task/github-add-comment/0.8/github-add-comment.yaml
WARN : Step "post-comment" uses secret to populate env "GITHUBTOKEN". Prefer using secrets as files over secrets as environment variables
WARN : Step "post-comment" references "$(params.AUTH_TYPE)" directly from its script block. For reliability and security, consider putting the param into an environment variable of the Step and accessing that environment variable in your script instead.
Catlin script lint Output
WARN : step: github-add-comment is not using #!/usr/bin/env
ERROR: /usr/bin/pylint, [-dC0103] failed:
************* Module catlin-script-linter2458712458
github-add-comment-post-comment:71:10: E0001: invalid syntax (<unknown>, line 71) (syntax-error)
Diff between version 0.7 and 0.8
diff --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
FILE: task/github-add-comment/0.8/github-add-comment.yaml
WARN : Step "post-comment" uses secret to populate env "GITHUBTOKEN". Prefer using secrets as files over secrets as environment variables
WARN : Step "post-comment" references "$(params.AUTH_TYPE)" directly from its script block. For reliability and security, consider putting the param into an environment variable of the Step and accessing that environment variable in your script instead.
Catlin script lint Output
WARN : step: github-add-comment is not using #!/usr/bin/env
ERROR: /usr/bin/pylint, [-dC0103] failed:
************* Module catlin-script-linter3114652467
github-add-comment-post-comment:22:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:26:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:34:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:36:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:41:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:42:0: W0311: Bad indentation. Found 4 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:43:0: W0311: Bad indentation. Found 4 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:44:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:52:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:53:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:54:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:55:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:56:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:57:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:59:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:60:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:62:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:63:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:64:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:65:0: W0311: Bad indentation. Found 8 spaces, expected 12 (bad-indentation)
github-add-comment-post-comment:66:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:97:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:1:0: C0114: Missing module docstring (missing-module-docstring)
github-add-comment-post-comment:15:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:21:3: R1727: Boolean condition ''$(workspaces.comment-file.bound)' == 'true' and os.path.exists(commentParamValue)' will always evaluate to ''$(workspaces.comment-file.bound)' == 'true'' (condition-evals-to-constant)
github-add-comment-post-comment:21:3: R0133: Comparison between constants: '$(workspaces.comment-file.bound) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:22:22: R1732: Consider using 'with' for resource-allocating operations (consider-using-with)
github-add-comment-post-comment:22:22: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
github-add-comment-post-comment:25:3: W0125: Using a conditional statement with a constant value (using-constant-test)
github-add-comment-post-comment:26:23: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:40:3: R1727: Boolean condition ''$(params.REPLACE)' == 'true' or '$(params.DELETE)' == 'true'' will always evaluate to 'False' (condition-evals-to-constant)
github-add-comment-post-comment:40:3: R0133: Comparison between constants: '$(params.REPLACE) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:40:36: R0133: Comparison between constants: '$(params.DELETE) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:44:2: E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)
github-add-comment-post-comment:54:12: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:64:11: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
github-add-comment-post-comment:69:7: R0133: Comparison between constants: '$(params.REPLACE) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:71:9: R0133: Comparison between constants: '$(params.DELETE) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:80:6: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:82:0: E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)
github-add-comment-post-comment:92:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:98:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
-----------------------------------
Your code has been rated at 1.07/10
Diff between version 0.7 and 0.8
diff --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
FILE: task/github-add-comment/0.8/github-add-comment.yaml
WARN : Step "post-comment" uses secret to populate env "GITHUBTOKEN". Prefer using secrets as files over secrets as environment variables
WARN : Step "post-comment" references "$(params.AUTH_TYPE)" directly from its script block. For reliability and security, consider putting the param into an environment variable of the Step and accessing that environment variable in your script instead.
Catlin script lint Output
WARN : step: github-add-comment is not using #!/usr/bin/env
ERROR: /usr/bin/pylint, [-dC0103] failed:
************* Module catlin-script-linter3160899991
github-add-comment-post-comment:22:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:26:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:34:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:36:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:41:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:42:0: W0311: Bad indentation. Found 4 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:43:0: W0311: Bad indentation. Found 4 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:44:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:52:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:53:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:54:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:55:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:56:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:57:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:59:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:60:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:62:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:63:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:64:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:65:0: W0311: Bad indentation. Found 8 spaces, expected 12 (bad-indentation)
github-add-comment-post-comment:66:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:106:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:1:0: C0114: Missing module docstring (missing-module-docstring)
github-add-comment-post-comment:15:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:21:3: R1727: Boolean condition ''$(workspaces.comment-file.bound)' == 'true' and os.path.exists(commentParamValue)' will always evaluate to ''$(workspaces.comment-file.bound)' == 'true'' (condition-evals-to-constant)
github-add-comment-post-comment:21:3: R0133: Comparison between constants: '$(workspaces.comment-file.bound) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:22:22: R1732: Consider using 'with' for resource-allocating operations (consider-using-with)
github-add-comment-post-comment:22:22: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
github-add-comment-post-comment:25:3: W0125: Using a conditional statement with a constant value (using-constant-test)
github-add-comment-post-comment:26:23: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:40:3: R1727: Boolean condition ''$(params.REPLACE)' == 'true' or '$(params.DELETE)' == 'true'' will always evaluate to 'False' (condition-evals-to-constant)
github-add-comment-post-comment:40:3: R0133: Comparison between constants: '$(params.REPLACE) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:40:36: R0133: Comparison between constants: '$(params.DELETE) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:44:2: E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)
github-add-comment-post-comment:54:12: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:64:11: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
github-add-comment-post-comment:69:7: R0133: Comparison between constants: '$(params.REPLACE) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:71:9: R0133: Comparison between constants: '$(params.DELETE) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:79:3: R0133: Comparison between constants: '$(params.DELETE) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:81:4: E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)
github-add-comment-post-comment:89:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:91:4: E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)
github-add-comment-post-comment:101:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:107:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
-----------------------------------
Your code has been rated at 0.34/10
...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.8
diff --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
Catlin Output
FILE: task/github-add-comment/0.8/github-add-comment.yaml
WARN : Step "post-comment" uses secret to populate env "GITHUBTOKEN". Prefer using secrets as files over secrets as environment variables
WARN : Step "post-comment" references "$(params.AUTH_TYPE)" directly from its script block. For reliability and security, consider putting the param into an environment variable of the Step and accessing that environment variable in your script instead.
Catlin script lint Output
WARN : step: github-add-comment is not using #!/usr/bin/env
ERROR: /usr/bin/pylint, [-dC0103] failed:
************* Module catlin-script-linter2721896146
github-add-comment-post-comment:22:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:26:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:34:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:36:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:41:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:42:0: W0311: Bad indentation. Found 4 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:43:0: W0311: Bad indentation. Found 4 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:44:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:52:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:53:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:54:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:55:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:56:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:57:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:59:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:60:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:62:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:63:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:64:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:65:0: W0311: Bad indentation. Found 8 spaces, expected 12 (bad-indentation)
github-add-comment-post-comment:66:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:106:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:1:0: C0114: Missing module docstring (missing-module-docstring)
github-add-comment-post-comment:15:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:21:3: R1727: Boolean condition ''$(workspaces.comment-file.bound)' == 'true' and os.path.exists(commentParamValue)' will always evaluate to ''$(workspaces.comment-file.bound)' == 'true'' (condition-evals-to-constant)
github-add-comment-post-comment:21:3: R0133: Comparison between constants: '$(workspaces.comment-file.bound) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:22:22: R1732: Consider using 'with' for resource-allocating operations (consider-using-with)
github-add-comment-post-comment:22:22: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
github-add-comment-post-comment:25:3: W0125: Using a conditional statement with a constant value (using-constant-test)
github-add-comment-post-comment:26:23: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:40:3: R1727: Boolean condition ''$(params.REPLACE)' == 'true' or '$(params.DELETE)' == 'true'' will always evaluate to 'False' (condition-evals-to-constant)
github-add-comment-post-comment:40:3: R0133: Comparison between constants: '$(params.REPLACE) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:40:36: R0133: Comparison between constants: '$(params.DELETE) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:44:2: E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)
github-add-comment-post-comment:54:12: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:64:11: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
github-add-comment-post-comment:69:7: R0133: Comparison between constants: '$(params.DELETE) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:79:3: R0133: Comparison between constants: '$(params.DELETE) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:81:4: E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)
github-add-comment-post-comment:89:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:91:4: E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)
github-add-comment-post-comment:101:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:107:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
-----------------------------------
Your code has been rated at 0.35/10
Diff between version 0.7 and 0.8
diff --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
FILE: task/github-add-comment/0.8/github-add-comment.yaml
WARN : Step "post-comment" uses secret to populate env "GITHUBTOKEN". Prefer using secrets as files over secrets as environment variables
WARN : Step "post-comment" references "$(params.AUTH_TYPE)" directly from its script block. For reliability and security, consider putting the param into an environment variable of the Step and accessing that environment variable in your script instead.
Catlin script lint Output
WARN : step: github-add-comment is not using #!/usr/bin/env
ERROR: /usr/bin/pylint, [-dC0103] failed:
************* Module catlin-script-linter1892341408
github-add-comment-post-comment:22:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:26:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:34:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:36:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:41:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:42:0: W0311: Bad indentation. Found 4 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:43:0: W0311: Bad indentation. Found 4 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:44:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:52:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:53:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:54:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:55:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:56:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:57:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:59:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:60:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:62:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:63:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:64:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:65:0: W0311: Bad indentation. Found 8 spaces, expected 12 (bad-indentation)
github-add-comment-post-comment:66:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:106:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:1:0: C0114: Missing module docstring (missing-module-docstring)
github-add-comment-post-comment:15:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:21:3: R1727: Boolean condition ''$(workspaces.comment-file.bound)' == 'true' and os.path.exists(commentParamValue)' will always evaluate to ''$(workspaces.comment-file.bound)' == 'true'' (condition-evals-to-constant)
github-add-comment-post-comment:21:3: R0133: Comparison between constants: '$(workspaces.comment-file.bound) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:22:22: R1732: Consider using 'with' for resource-allocating operations (consider-using-with)
github-add-comment-post-comment:22:22: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
github-add-comment-post-comment:25:3: W0125: Using a conditional statement with a constant value (using-constant-test)
github-add-comment-post-comment:26:23: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:40:3: R1727: Boolean condition ''$(params.REPLACE)' == 'true' or '$(params.DELETE)' == 'true'' will always evaluate to 'False' (condition-evals-to-constant)
github-add-comment-post-comment:40:3: R0133: Comparison between constants: '$(params.REPLACE) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:40:36: R0133: Comparison between constants: '$(params.DELETE) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:44:2: E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)
github-add-comment-post-comment:54:12: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:64:11: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
github-add-comment-post-comment:69:7: R0133: Comparison between constants: '$(params.DELETE) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:79:3: R0133: Comparison between constants: '$(params.DELETE) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:81:4: E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)
github-add-comment-post-comment:89:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:91:4: E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)
github-add-comment-post-comment:101:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:107:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
-----------------------------------
Your code has been rated at 0.35/10
Catlin Output
FILE: task/github-add-comment/0.8/github-add-comment.yaml
WARN : Step "post-comment" uses secret to populate env "GITHUBTOKEN". Prefer using secrets as files over secrets as environment variables
WARN : Step "post-comment" references "$(params.AUTH_TYPE)" directly from its script block. For reliability and security, consider putting the param into an environment variable of the Step and accessing that environment variable in your script instead.
Catlin script lint Output
WARN : step: github-add-comment is not using #!/usr/bin/env
ERROR: /usr/bin/pylint, [-dC0103] failed:
************* Module catlin-script-linter3051395037
github-add-comment-post-comment:22:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:26:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:34:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:36:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:41:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:42:0: W0311: Bad indentation. Found 4 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:43:0: W0311: Bad indentation. Found 4 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:44:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:52:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:53:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:54:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:55:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:56:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:57:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:59:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:60:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:62:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:63:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:64:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:65:0: W0311: Bad indentation. Found 8 spaces, expected 12 (bad-indentation)
github-add-comment-post-comment:66:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:106:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:1:0: C0114: Missing module docstring (missing-module-docstring)
github-add-comment-post-comment:15:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:21:3: R1727: Boolean condition ''$(workspaces.comment-file.bound)' == 'true' and os.path.exists(commentParamValue)' will always evaluate to ''$(workspaces.comment-file.bound)' == 'true'' (condition-evals-to-constant)
github-add-comment-post-comment:21:3: R0133: Comparison between constants: '$(workspaces.comment-file.bound) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:22:22: R1732: Consider using 'with' for resource-allocating operations (consider-using-with)
github-add-comment-post-comment:22:22: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
github-add-comment-post-comment:25:3: W0125: Using a conditional statement with a constant value (using-constant-test)
github-add-comment-post-comment:26:23: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:40:3: R1727: Boolean condition ''$(params.REPLACE)' == 'true' or '$(params.DELETE)' == 'true'' will always evaluate to 'False' (condition-evals-to-constant)
github-add-comment-post-comment:40:3: R0133: Comparison between constants: '$(params.REPLACE) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:40:36: R0133: Comparison between constants: '$(params.DELETE) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:44:2: E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)
github-add-comment-post-comment:54:12: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:64:11: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
github-add-comment-post-comment:69:7: R0133: Comparison between constants: '$(params.DELETE) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:80:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:81:4: E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)
github-add-comment-post-comment:89:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:91:4: E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)
github-add-comment-post-comment:101:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:107:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
-----------------------------------
Your code has been rated at 0.35/10
Diff between version 0.7 and 0.8
diff --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
Diff between version 0.7 and 0.8
diff --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
FILE: task/github-add-comment/0.8/github-add-comment.yaml
WARN : Step "post-comment" uses secret to populate env "GITHUBTOKEN". Prefer using secrets as files over secrets as environment variables
WARN : Step "post-comment" references "$(params.AUTH_TYPE)" directly from its script block. For reliability and security, consider putting the param into an environment variable of the Step and accessing that environment variable in your script instead.
Catlin script lint Output
WARN : step: github-add-comment is not using #!/usr/bin/env
ERROR: /usr/bin/pylint, [-dC0103] failed:
************* Module catlin-script-linter3188784439
github-add-comment-post-comment:104:24: E0001: EOL while scanning string literal (<unknown>, line 104) (syntax-error)
Catlin Output
FILE: task/github-add-comment/0.8/github-add-comment.yaml
WARN : Step "post-comment" uses secret to populate env "GITHUBTOKEN". Prefer using secrets as files over secrets as environment variables
WARN : Step "post-comment" references "$(params.AUTH_TYPE)" directly from its script block. For reliability and security, consider putting the param into an environment variable of the Step and accessing that environment variable in your script instead.
Catlin script lint Output
WARN : step: github-add-comment is not using #!/usr/bin/env
ERROR: /usr/bin/pylint, [-dC0103] failed:
************* Module catlin-script-linter889046211
github-add-comment-post-comment:22:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:26:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:34:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:36:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:41:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:42:0: W0311: Bad indentation. Found 4 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:43:0: W0311: Bad indentation. Found 4 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:44:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:52:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:53:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:54:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:55:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:56:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:57:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:59:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:60:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:62:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:63:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
github-add-comment-post-comment:64:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:65:0: W0311: Bad indentation. Found 8 spaces, expected 12 (bad-indentation)
github-add-comment-post-comment:66:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:106:0: W0311: Bad indentation. Found 6 spaces, expected 8 (bad-indentation)
github-add-comment-post-comment:1:0: C0114: Missing module docstring (missing-module-docstring)
github-add-comment-post-comment:15:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:21:3: R1727: Boolean condition ''$(workspaces.comment-file.bound)' == 'true' and os.path.exists(commentParamValue)' will always evaluate to ''$(workspaces.comment-file.bound)' == 'true'' (condition-evals-to-constant)
github-add-comment-post-comment:21:3: R0133: Comparison between constants: '$(workspaces.comment-file.bound) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:22:22: R1732: Consider using 'with' for resource-allocating operations (consider-using-with)
github-add-comment-post-comment:22:22: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
github-add-comment-post-comment:25:3: W0125: Using a conditional statement with a constant value (using-constant-test)
github-add-comment-post-comment:26:23: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:40:3: R1727: Boolean condition ''$(params.REPLACE)' == 'true' or '$(params.DELETE)' == 'true'' will always evaluate to 'False' (condition-evals-to-constant)
github-add-comment-post-comment:40:3: R0133: Comparison between constants: '$(params.REPLACE) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:40:36: R0133: Comparison between constants: '$(params.DELETE) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:44:2: E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)
github-add-comment-post-comment:54:12: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:64:11: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
github-add-comment-post-comment:69:7: R0133: Comparison between constants: '$(params.DELETE) == true' has a constant value (comparison-of-constants)
github-add-comment-post-comment:80:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:81:4: E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)
github-add-comment-post-comment:89:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:91:4: E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)
github-add-comment-post-comment:101:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
github-add-comment-post-comment:107:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
-----------------------------------
Your code has been rated at 0.52/10
Diff between version 0.7 and 0.8
diff --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
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: dibyom
To complete the pull request process, please assign kimsterv after the PR has been reviewed.
You can assign the PR to them by writing /assign @kimsterv in a comment when ready.
The full list of commands accepted by this bot can be found here.
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
/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. =)
Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale with a justification.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close with a justification.
If this issue should be exempted, mark the issue as frozen with /lifecycle frozen with a justification.
/lifecycle stale
Send feedback to tektoncd/plumbing.
Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten with a justification.
Rotten issues close after an additional 30d of inactivity.
If this issue is safe to close now please do so with /close with a justification.
If this issue should be exempted, mark the issue as frozen with /lifecycle frozen with a justification.
/lifecycle rotten
Send feedback to tektoncd/plumbing.
Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen with a justification.
Mark the issue as fresh with /remove-lifecycle rotten with a justification.
If this issue should be exempted, mark the issue as frozen with /lifecycle frozen with a justification.
/close
Send feedback to tektoncd/plumbing.
@tekton-robot: Closed this PR.
In response to this:
Rotten issues close after 30d of inactivity. Reopen the issue with
/reopenwith a justification. Mark the issue as fresh with/remove-lifecycle rottenwith a justification. If this issue should be exempted, mark the issue as frozen with/lifecycle frozenwith a justification./close
Send feedback to tektoncd/plumbing.
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.