Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

abayer
Copy link
Contributor

@abayer abayer commented Aug 19, 2022

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:

  • Follows the authoring recommendations
  • Includes [docs][docs] (if user facing)
  • Includes [tests][tests] (for new tasks or changed functionality)
    • See the [end-to-end testing documentation][e2e] for guidance and CI details.
  • Meets the [Tekton contributor standards][contributor] (including functionality, content, code)
  • Commit messages follow [commit message best practices][commit]
  • 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
  • Complies with Catalog Organization TEP, see example. Note An issue has been filed to automate this validation
    • 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 resource

    • Has mandatory metadata.annotations tekton.dev/pipelines.minVersion

    • mandatory spec.description follows 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

@tekton-robot tekton-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Aug 19, 2022
@tekton-robot tekton-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Aug 19, 2022
@tekton-robot
Copy link

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

@tekton-robot
Copy link

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)

@abayer abayer force-pushed the delete-comment-option branch from 748b4c1 to 347b1cd Compare August 19, 2022 18:21
@tekton-robot
Copy link

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

@tekton-robot
Copy link

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)

@abayer abayer force-pushed the delete-comment-option branch from 347b1cd to c711042 Compare August 19, 2022 18:25
@tekton-robot
Copy link

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

@tekton-robot
Copy link

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


@abayer abayer force-pushed the delete-comment-option branch from c711042 to bf6c4c7 Compare August 19, 2022 18:54
@tekton-robot
Copy link

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

@tekton-robot
Copy link

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


@abayer abayer force-pushed the delete-comment-option branch from bf6c4c7 to edf353a Compare August 19, 2022 19:10
@abayer
Copy link
Contributor Author

abayer commented Aug 19, 2022

...you may notice that I don't know python at all well, so I'm not sure what's breaking. =)

@tekton-robot
Copy link

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

@abayer abayer force-pushed the delete-comment-option branch from edf353a to 894df2b Compare August 19, 2022 19:11
@tekton-robot
Copy link

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


@tekton-robot
Copy link

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

@tekton-robot
Copy link

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


@abayer abayer force-pushed the delete-comment-option branch from 894df2b to 40362e0 Compare August 22, 2022 13:11
@tekton-robot
Copy link

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


@tekton-robot
Copy link

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

@abayer abayer force-pushed the delete-comment-option branch from 40362e0 to 71d9c82 Compare August 22, 2022 13:26
@tekton-robot
Copy link

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

@tekton-robot
Copy link

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)

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]>
@abayer abayer force-pushed the delete-comment-option branch from 71d9c82 to 81c1c05 Compare August 22, 2022 13:43
@tekton-robot
Copy link

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


@tekton-robot
Copy link

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

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)"""
Copy link
Member

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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XD

@tekton-robot
Copy link

[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.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@abayer
Copy link
Contributor Author

abayer commented Aug 22, 2022

/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. =)

@tekton-robot tekton-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 22, 2022
abayer added a commit to abayer/plumbing that referenced this pull request Aug 22, 2022
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]>
abayer added a commit to abayer/plumbing that referenced this pull request Aug 23, 2022
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]>
abayer added a commit to abayer/plumbing that referenced this pull request Aug 23, 2022
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]>
abayer added a commit to abayer/plumbing that referenced this pull request Aug 30, 2022
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]>
abayer added a commit to abayer/plumbing that referenced this pull request Sep 6, 2022
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]>
tekton-robot pushed a commit to tektoncd/plumbing that referenced this pull request Sep 7, 2022
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]>
@tekton-robot
Copy link

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.

@tekton-robot tekton-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Nov 20, 2022
@tekton-robot
Copy link

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.

@tekton-robot tekton-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Dec 20, 2022
@tekton-robot
Copy link

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
Copy link

@tekton-robot: Closed this PR.

In response to this:

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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/feature Categorizes issue or PR as related to a new feature. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants