Fix triage workflow when the card already exists in project (#63347)
authorzhouzhuojie <zhouzhuojie@gmail.com>
Mon, 16 Aug 2021 20:32:40 +0000 (13:32 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Mon, 16 Aug 2021 20:33:58 +0000 (13:33 -0700)
Summary:
Fixes issues like https://github.com/pytorch/pytorch/runs/3336787242

```
RequestError [HttpError]: Validation Failed: {"resource":"ProjectCard","code":"unprocessable","field":"data","message":"Project already has the associated issue"}
Error: Unhandled error: HttpError: Validation Failed: {"resource":"ProjectCard","code":"unprocessable","field":"data","message":"Project already has the associated issue"}
    at /home/runner/work/_actions/actions/github-script/v2/dist/index.js:7531:23
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async eval (eval at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v2/dist/index.js:7985:56), <anonymous>:63:1)
    at async main (/home/runner/work/_actions/actions/github-script/v2/dist/index.js:8011:20) {
  name: 'HttpError',
  status: 422,

...
```

The card may already exist, thus no need to handle `422` status code. Anything else will re-throw the err.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/63347

Reviewed By: malfet

Differential Revision: D30348529

Pulled By: zhouzhuojie

fbshipit-source-id: 36647837bfccad43ce01eb5dfe6642e685615037

.github/workflows/triage.yml

index f4466c4..23b2f14 100644 (file)
@@ -83,8 +83,15 @@ jobs:
             const columnId = filteredColumns[0].id;
 
             // Create a project card for this new issue.
-            await github.projects.createCard({
-              column_id: columnId,
-              content_id: issue.data.id,
-              content_type: "Issue",
-            })
+            try {
+              await github.projects.createCard({
+                column_id: columnId,
+                content_id: issue.data.id,
+                content_type: "Issue",
+              })
+            } catch (err) {
+              if (err.status !== 422) {
+                throw err;
+              }
+              console.log("Unable to create card: already exists");
+            }