From a3b49b41ac630ffe9dcde5539221b390ba952146 Mon Sep 17 00:00:00 2001 From: Sam Huang Date: Sat, 19 Feb 2022 16:02:38 -0800 Subject: [PATCH 01/13] Support marking as WIP and initial review --- .../label-prs-as-ready-for-review.yml | 16 +++++ .../label-prs-as-work-in-progress.yml | 16 +++++ .../workflows/move-ready-for-review-prs.yml | 69 ++++++++++++++++++ .../workflows/move-work-in-progress-prs.yml | 70 +++++++++++++++++++ 4 files changed, 171 insertions(+) create mode 100644 .github/workflows/label-prs-as-ready-for-review.yml create mode 100644 .github/workflows/label-prs-as-work-in-progress.yml create mode 100644 .github/workflows/move-ready-for-review-prs.yml create mode 100644 .github/workflows/move-work-in-progress-prs.yml diff --git a/.github/workflows/label-prs-as-ready-for-review.yml b/.github/workflows/label-prs-as-ready-for-review.yml new file mode 100644 index 00000000000..695fdc29ada --- /dev/null +++ b/.github/workflows/label-prs-as-ready-for-review.yml @@ -0,0 +1,16 @@ +name: Label PR As Ready For Review +on: + issue_comment: + types: [created] + branch: + - main +jobs: + label-pr-as-ready-for-review: + if: github.event.issue.pull_request + runs-on: ubuntu-latest + steps: + - name: Add Work In Progress To PR + if: github.event.comment.body == '/pr mark ready' + uses: actions-ecosystem/action-remove-labels@v1 + with: + labels: "work in progress" diff --git a/.github/workflows/label-prs-as-work-in-progress.yml b/.github/workflows/label-prs-as-work-in-progress.yml new file mode 100644 index 00000000000..09999c46354 --- /dev/null +++ b/.github/workflows/label-prs-as-work-in-progress.yml @@ -0,0 +1,16 @@ +name: Label PR As Work In Progress +on: + issue_comment: + types: [created] + branch: + - main +jobs: + label-pr-as-wip: + if: github.event.issue.pull_request + runs-on: ubuntu-latest + steps: + - name: Add Work In Progress To PR + if: github.event.comment.body == '/pr mark wip' + uses: actions-ecosystem/action-add-labels@v1 + with: + labels: "work in progress" diff --git a/.github/workflows/move-ready-for-review-prs.yml b/.github/workflows/move-ready-for-review-prs.yml new file mode 100644 index 00000000000..d620bdfc3d1 --- /dev/null +++ b/.github/workflows/move-ready-for-review-prs.yml @@ -0,0 +1,69 @@ +name: Move PR To Initial Review +on: + issue_comment: + types: [created] + branch: + - main +jobs: + move-pr-to-initial-review: + if: github.event.comment.body == '/pr mark ready' && github.event.issue.pull_request + runs-on: ubuntu-latest + steps: + - name: Move To Initial Review + uses: actions/github-script@v6 + with: + script: | + // Find "Code Reviews" project manually by name matching + // This avoids hardcoding the project ID + const projects = await github.rest.projects.listForRepo({ + owner: context.repo.owner, + repo: context.repo.repo, + }) + const code_reviews = projects.data.find(project => { + return project.name === 'Code Reviews'; + }) + if (code_reviews === undefined) { + return + } + + // Find "Initial Review" column manually by name matching + // Also find the card of the PR in all columns + // This avoids hardcoding the column ID and card ID + const columns = await github.rest.projects.listColumns({ + project_id: code_reviews.id, + }); + + let work_in_progress = null + let pr_card = null + // FIXME forEach is needed instead of a for loop, otherwise it doesn't work + // FIXME find out why + + // Since .then is asynchronous, cannot guarantee work_in_progress is set before + // the PR card is found. Just loop through the columns again + columns.data.forEach(column => { + if (column.name === 'Initial Review') { + work_in_progress = column.id + } + }) + + // FIXME figure out best way to handle error + columns.data.forEach(column => { + github.rest.projects.listCards({ + column_id: column.id, + }).then(cards => { + cards.data.forEach(card => { + if (card.content_url === context.payload.issue.url) { + pr_card = card.id // TODO break out early somehow, avoid extra work + + if (work_in_progress !== null) { + github.rest.projects.moveCard({ + card_id: pr_card, + position: 'bottom', + column_id: work_in_progress, + }).catch(error => {}) + } + } + }) + }) + .catch(error => {}) + }) diff --git a/.github/workflows/move-work-in-progress-prs.yml b/.github/workflows/move-work-in-progress-prs.yml new file mode 100644 index 00000000000..0a6c9c96689 --- /dev/null +++ b/.github/workflows/move-work-in-progress-prs.yml @@ -0,0 +1,70 @@ +name: Move PR To Work In Progress +on: + issue_comment: + types: [created] + branch: + - main + +jobs: + move-pr-to-wip: + if: github.event.comment.body == '/pr mark wip' && github.event.issue.pull_request + runs-on: ubuntu-latest + steps: + - name: Move To Initial Review + uses: actions/github-script@v6 + with: + script: | + // Find "Code Reviews" project manually by name matching + // This avoids hardcoding the project ID + const projects = await github.rest.projects.listForRepo({ + owner: context.repo.owner, + repo: context.repo.repo, + }) + const code_reviews = projects.data.find(project => { + return project.name === 'Code Reviews'; + }) + if (code_reviews === undefined) { + return + } + + // Find "Work In Progress" column manually by name matching + // Also find the card of the PR in all columns + // This avoids hardcoding the column ID and card ID + const columns = await github.rest.projects.listColumns({ + project_id: code_reviews.id, + }); + + let work_in_progress = null + let pr_card = null + // FIXME forEach is needed instead of a for loop, otherwise it doesn't work + // FIXME find out why + + // Since .then is asynchronous, we cannot guarantee work_in_progress is set before + // the PR card is found if we were to process them in the same loop + columns.data.forEach(column => { + if (column.name === 'Work In Progress') { + work_in_progress = column.id + } + }) + + // FIXME figure out best way to handle error + columns.data.forEach(column => { + github.rest.projects.listCards({ + column_id: column.id, + }).then(cards => { + cards.data.forEach(card => { + if (card.content_url === context.payload.issue.url) { + pr_card = card.id // TODO break out early somehow, avoid extra work + + if (work_in_progress !== null) { + github.rest.projects.moveCard({ + card_id: pr_card, + position: 'bottom', + column_id: work_in_progress, + }).catch(error => {}) + } + } + }) + }) + .catch(error => {}) + }) From dac0f76c4cd425840d4db4250b546b1be58e2441 Mon Sep 17 00:00:00 2001 From: Sam Huang Date: Sat, 19 Feb 2022 16:44:34 -0800 Subject: [PATCH 02/13] Add copyright --- .github/workflows/label-prs-as-ready-for-review.yml | 3 +++ .github/workflows/label-prs-as-work-in-progress.yml | 3 +++ .github/workflows/move-ready-for-review-prs.yml | 5 ++++- .github/workflows/move-work-in-progress-prs.yml | 5 ++++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/label-prs-as-ready-for-review.yml b/.github/workflows/label-prs-as-ready-for-review.yml index 695fdc29ada..23a966c88ac 100644 --- a/.github/workflows/label-prs-as-ready-for-review.yml +++ b/.github/workflows/label-prs-as-ready-for-review.yml @@ -1,3 +1,6 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + name: Label PR As Ready For Review on: issue_comment: diff --git a/.github/workflows/label-prs-as-work-in-progress.yml b/.github/workflows/label-prs-as-work-in-progress.yml index 09999c46354..7d1a630047e 100644 --- a/.github/workflows/label-prs-as-work-in-progress.yml +++ b/.github/workflows/label-prs-as-work-in-progress.yml @@ -1,3 +1,6 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + name: Label PR As Work In Progress on: issue_comment: diff --git a/.github/workflows/move-ready-for-review-prs.yml b/.github/workflows/move-ready-for-review-prs.yml index d620bdfc3d1..b788b7762dd 100644 --- a/.github/workflows/move-ready-for-review-prs.yml +++ b/.github/workflows/move-ready-for-review-prs.yml @@ -1,3 +1,6 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + name: Move PR To Initial Review on: issue_comment: @@ -54,7 +57,7 @@ jobs: cards.data.forEach(card => { if (card.content_url === context.payload.issue.url) { pr_card = card.id // TODO break out early somehow, avoid extra work - + if (work_in_progress !== null) { github.rest.projects.moveCard({ card_id: pr_card, diff --git a/.github/workflows/move-work-in-progress-prs.yml b/.github/workflows/move-work-in-progress-prs.yml index 0a6c9c96689..9c9e69977ef 100644 --- a/.github/workflows/move-work-in-progress-prs.yml +++ b/.github/workflows/move-work-in-progress-prs.yml @@ -1,3 +1,6 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + name: Move PR To Work In Progress on: issue_comment: @@ -55,7 +58,7 @@ jobs: cards.data.forEach(card => { if (card.content_url === context.payload.issue.url) { pr_card = card.id // TODO break out early somehow, avoid extra work - + if (work_in_progress !== null) { github.rest.projects.moveCard({ card_id: pr_card, From e9794be308a8217a716b68fa7a9d2641250a25f5 Mon Sep 17 00:00:00 2001 From: Sam Huang Date: Sun, 20 Feb 2022 07:27:24 -0800 Subject: [PATCH 03/13] Review comments + cleanups --- .../label-prs-as-ready-for-review.yml | 4 +- .../label-prs-as-work-in-progress.yml | 4 +- .../workflows/move-ready-for-review-prs.yml | 57 +++++++------------ .../workflows/move-work-in-progress-prs.yml | 39 ++++++------- 4 files changed, 42 insertions(+), 62 deletions(-) diff --git a/.github/workflows/label-prs-as-ready-for-review.yml b/.github/workflows/label-prs-as-ready-for-review.yml index 23a966c88ac..90d85f53b5f 100644 --- a/.github/workflows/label-prs-as-ready-for-review.yml +++ b/.github/workflows/label-prs-as-ready-for-review.yml @@ -7,13 +7,13 @@ on: types: [created] branch: - main + jobs: label-pr-as-ready-for-review: - if: github.event.issue.pull_request + if: github.event.comment.body == '/pr mark ready' && github.event.issue.pull_request runs-on: ubuntu-latest steps: - name: Add Work In Progress To PR - if: github.event.comment.body == '/pr mark ready' uses: actions-ecosystem/action-remove-labels@v1 with: labels: "work in progress" diff --git a/.github/workflows/label-prs-as-work-in-progress.yml b/.github/workflows/label-prs-as-work-in-progress.yml index 7d1a630047e..c7276673407 100644 --- a/.github/workflows/label-prs-as-work-in-progress.yml +++ b/.github/workflows/label-prs-as-work-in-progress.yml @@ -7,13 +7,13 @@ on: types: [created] branch: - main + jobs: label-pr-as-wip: - if: github.event.issue.pull_request + if: github.event.comment.body == '/pr mark wip' && github.event.issue.pull_request runs-on: ubuntu-latest steps: - name: Add Work In Progress To PR - if: github.event.comment.body == '/pr mark wip' uses: actions-ecosystem/action-add-labels@v1 with: labels: "work in progress" diff --git a/.github/workflows/move-ready-for-review-prs.yml b/.github/workflows/move-ready-for-review-prs.yml index b788b7762dd..ef7318179be 100644 --- a/.github/workflows/move-ready-for-review-prs.yml +++ b/.github/workflows/move-ready-for-review-prs.yml @@ -7,6 +7,7 @@ on: types: [created] branch: - main + jobs: move-pr-to-initial-review: if: github.event.comment.body == '/pr mark ready' && github.event.issue.pull_request @@ -25,48 +26,34 @@ jobs: const code_reviews = projects.data.find(project => { return project.name === 'Code Reviews'; }) - if (code_reviews === undefined) { - return - } // Find "Initial Review" column manually by name matching - // Also find the card of the PR in all columns + // This assumes the card is in "Work In Progress" column // This avoids hardcoding the column ID and card ID const columns = await github.rest.projects.listColumns({ project_id: code_reviews.id, }); - let work_in_progress = null - let pr_card = null - // FIXME forEach is needed instead of a for loop, otherwise it doesn't work - // FIXME find out why - - // Since .then is asynchronous, cannot guarantee work_in_progress is set before - // the PR card is found. Just loop through the columns again - columns.data.forEach(column => { - if (column.name === 'Initial Review') { - work_in_progress = column.id - } - }) + const work_in_progress = columns.data.find(column => column.name === 'Work In Progress') + if (!work_in_progress) { + return + } - // FIXME figure out best way to handle error - columns.data.forEach(column => { - github.rest.projects.listCards({ - column_id: column.id, - }).then(cards => { - cards.data.forEach(card => { - if (card.content_url === context.payload.issue.url) { - pr_card = card.id // TODO break out early somehow, avoid extra work + const initial_review = columns.data.find(column => column.name === 'Initial Review') + if (!initial_review) { + return + } - if (work_in_progress !== null) { - github.rest.projects.moveCard({ - card_id: pr_card, - position: 'bottom', - column_id: work_in_progress, - }).catch(error => {}) - } - } - }) - }) - .catch(error => {}) + const work_in_progress_cards = await github.rest.projects.listCards({ + column_id: work_in_progress.id, }) + const pr_card = work_in_progress_cards.data.find(card => card.content_url === context.payload.issue.url) + if (!pr_card) { + return + } + + github.rest.projects.moveCard({ + card_id: pr_card.id, + position: 'bottom', + column_id: initial_review.id, + }).catch(error => {}) // FIXME figure out best way to handle error diff --git a/.github/workflows/move-work-in-progress-prs.yml b/.github/workflows/move-work-in-progress-prs.yml index 9c9e69977ef..a56282c5b37 100644 --- a/.github/workflows/move-work-in-progress-prs.yml +++ b/.github/workflows/move-work-in-progress-prs.yml @@ -13,7 +13,7 @@ jobs: if: github.event.comment.body == '/pr mark wip' && github.event.issue.pull_request runs-on: ubuntu-latest steps: - - name: Move To Initial Review + - name: Move To Work In Progress uses: actions/github-script@v6 with: script: | @@ -26,48 +26,41 @@ jobs: const code_reviews = projects.data.find(project => { return project.name === 'Code Reviews'; }) - if (code_reviews === undefined) { + if (!code_reviews) { return } // Find "Work In Progress" column manually by name matching - // Also find the card of the PR in all columns + // Also find the card of the PR in either "Initial Review" or "Final Review" // This avoids hardcoding the column ID and card ID const columns = await github.rest.projects.listColumns({ project_id: code_reviews.id, }); - let work_in_progress = null - let pr_card = null - // FIXME forEach is needed instead of a for loop, otherwise it doesn't work - // FIXME find out why + const work_in_progress = columns.data.find(column => column.name === 'Work In Progress') + if (!work_in_progress) { + return + } - // Since .then is asynchronous, we cannot guarantee work_in_progress is set before - // the PR card is found if we were to process them in the same loop columns.data.forEach(column => { - if (column.name === 'Work In Progress') { - work_in_progress = column.id + if (column.name !== 'Initial Review' && column.name !== 'Final Review') { + return // no reason to search through other columns and avoids unnecessary API calls } - }) - // FIXME figure out best way to handle error - columns.data.forEach(column => { github.rest.projects.listCards({ column_id: column.id, }).then(cards => { cards.data.forEach(card => { if (card.content_url === context.payload.issue.url) { - pr_card = card.id // TODO break out early somehow, avoid extra work + // card is the PR card - if (work_in_progress !== null) { - github.rest.projects.moveCard({ - card_id: pr_card, - position: 'bottom', - column_id: work_in_progress, - }).catch(error => {}) - } + github.rest.projects.moveCard({ + card_id: card.id, + position: 'bottom', + column_id: work_in_progress.id, + }).catch(error => {}) // FIXME figure out best way to handle error } }) }) - .catch(error => {}) + .catch(error => {}) // FIXME figure out best way to handle error }) From 31647fc953d1fb4f0ffd86038cdf9a33241b5325 Mon Sep 17 00:00:00 2001 From: Sam Huang Date: Thu, 24 Feb 2022 07:10:22 -0800 Subject: [PATCH 04/13] Remove "work in progress" label automations --- .../label-prs-as-ready-for-review.yml | 19 ------------------- .../label-prs-as-work-in-progress.yml | 19 ------------------- 2 files changed, 38 deletions(-) delete mode 100644 .github/workflows/label-prs-as-ready-for-review.yml delete mode 100644 .github/workflows/label-prs-as-work-in-progress.yml diff --git a/.github/workflows/label-prs-as-ready-for-review.yml b/.github/workflows/label-prs-as-ready-for-review.yml deleted file mode 100644 index 90d85f53b5f..00000000000 --- a/.github/workflows/label-prs-as-ready-for-review.yml +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) Microsoft Corporation. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -name: Label PR As Ready For Review -on: - issue_comment: - types: [created] - branch: - - main - -jobs: - label-pr-as-ready-for-review: - if: github.event.comment.body == '/pr mark ready' && github.event.issue.pull_request - runs-on: ubuntu-latest - steps: - - name: Add Work In Progress To PR - uses: actions-ecosystem/action-remove-labels@v1 - with: - labels: "work in progress" diff --git a/.github/workflows/label-prs-as-work-in-progress.yml b/.github/workflows/label-prs-as-work-in-progress.yml deleted file mode 100644 index c7276673407..00000000000 --- a/.github/workflows/label-prs-as-work-in-progress.yml +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) Microsoft Corporation. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -name: Label PR As Work In Progress -on: - issue_comment: - types: [created] - branch: - - main - -jobs: - label-pr-as-wip: - if: github.event.comment.body == '/pr mark wip' && github.event.issue.pull_request - runs-on: ubuntu-latest - steps: - - name: Add Work In Progress To PR - uses: actions-ecosystem/action-add-labels@v1 - with: - labels: "work in progress" From 6c64a78bcd1d450d311d9bf1f0cd0f26e59330ac Mon Sep 17 00:00:00 2001 From: Sam Huang Date: Fri, 25 Feb 2022 20:23:04 -0800 Subject: [PATCH 05/13] Print error to console --- .github/workflows/move-ready-for-review-prs.yml | 4 +++- .github/workflows/move-work-in-progress-prs.yml | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/move-ready-for-review-prs.yml b/.github/workflows/move-ready-for-review-prs.yml index ef7318179be..b5c24656275 100644 --- a/.github/workflows/move-ready-for-review-prs.yml +++ b/.github/workflows/move-ready-for-review-prs.yml @@ -56,4 +56,6 @@ jobs: card_id: pr_card.id, position: 'bottom', column_id: initial_review.id, - }).catch(error => {}) // FIXME figure out best way to handle error + }).catch(error => { + console.error("Error occured while moving card to Initial Review!") + }) diff --git a/.github/workflows/move-work-in-progress-prs.yml b/.github/workflows/move-work-in-progress-prs.yml index a56282c5b37..6fa9ad80282 100644 --- a/.github/workflows/move-work-in-progress-prs.yml +++ b/.github/workflows/move-work-in-progress-prs.yml @@ -58,9 +58,13 @@ jobs: card_id: card.id, position: 'bottom', column_id: work_in_progress.id, - }).catch(error => {}) // FIXME figure out best way to handle error + }).catch(error => { + console.error("Error occured while moving card to Work In Progress!") + }) } }) }) - .catch(error => {}) // FIXME figure out best way to handle error + .catch(error => { + console.error("Error while fetching cards from column ID " + column.id) + }) }) From ad3f7d89e233cf41a21c24c524aaae745558c395 Mon Sep 17 00:00:00 2001 From: Sam Huang Date: Sat, 26 Feb 2022 10:41:29 -0800 Subject: [PATCH 06/13] Missed handling of non-existing "Code Reviews" --- .github/workflows/move-ready-for-review-prs.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/move-ready-for-review-prs.yml b/.github/workflows/move-ready-for-review-prs.yml index b5c24656275..a653d57fef2 100644 --- a/.github/workflows/move-ready-for-review-prs.yml +++ b/.github/workflows/move-ready-for-review-prs.yml @@ -26,6 +26,9 @@ jobs: const code_reviews = projects.data.find(project => { return project.name === 'Code Reviews'; }) + if (!code_reviews) { + return + } // Find "Initial Review" column manually by name matching // This assumes the card is in "Work In Progress" column From 2d7d0a78ba082cf1eef48672504d78e605920a95 Mon Sep 17 00:00:00 2001 From: Sam Huang Date: Sat, 27 Aug 2022 10:55:45 -0700 Subject: [PATCH 07/13] Log error message if corresponding columns aren't found --- .github/workflows/move-ready-for-review-prs.yml | 6 +++++- .github/workflows/move-work-in-progress-prs.yml | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/move-ready-for-review-prs.yml b/.github/workflows/move-ready-for-review-prs.yml index a653d57fef2..3f144f43362 100644 --- a/.github/workflows/move-ready-for-review-prs.yml +++ b/.github/workflows/move-ready-for-review-prs.yml @@ -27,6 +27,7 @@ jobs: return project.name === 'Code Reviews'; }) if (!code_reviews) { + console.error("'Code Reviews' project not found!") return } @@ -39,11 +40,13 @@ jobs: const work_in_progress = columns.data.find(column => column.name === 'Work In Progress') if (!work_in_progress) { + console.error("'Work In Progress' column not found!") return } const initial_review = columns.data.find(column => column.name === 'Initial Review') if (!initial_review) { + console.error("'Initial Review' column not found!") return } @@ -52,6 +55,7 @@ jobs: }) const pr_card = work_in_progress_cards.data.find(card => card.content_url === context.payload.issue.url) if (!pr_card) { + console.error("Corresponding card for PR not found!") return } @@ -60,5 +64,5 @@ jobs: position: 'bottom', column_id: initial_review.id, }).catch(error => { - console.error("Error occured while moving card to Initial Review!") + console.error("Error occured while moving card to 'Initial Review'!") }) diff --git a/.github/workflows/move-work-in-progress-prs.yml b/.github/workflows/move-work-in-progress-prs.yml index 6fa9ad80282..94523b02473 100644 --- a/.github/workflows/move-work-in-progress-prs.yml +++ b/.github/workflows/move-work-in-progress-prs.yml @@ -27,6 +27,7 @@ jobs: return project.name === 'Code Reviews'; }) if (!code_reviews) { + console.error("'Code Reviews' project not found!") return } @@ -39,6 +40,7 @@ jobs: const work_in_progress = columns.data.find(column => column.name === 'Work In Progress') if (!work_in_progress) { + console.error("'Work In Progress' column not found!") return } From b248159f4a5aaf68b2cb3b631b3e915256ef7b1b Mon Sep 17 00:00:00 2001 From: Sam Huang Date: Mon, 29 Aug 2022 16:27:26 -0700 Subject: [PATCH 08/13] Apply most comments --- .github/workflows/move-ready-for-review-prs.yml | 8 +++----- .github/workflows/move-work-in-progress-prs.yml | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/.github/workflows/move-ready-for-review-prs.yml b/.github/workflows/move-ready-for-review-prs.yml index 3f144f43362..acc3879b056 100644 --- a/.github/workflows/move-ready-for-review-prs.yml +++ b/.github/workflows/move-ready-for-review-prs.yml @@ -10,7 +10,7 @@ on: jobs: move-pr-to-initial-review: - if: github.event.comment.body == '/pr mark ready' && github.event.issue.pull_request + if: contains(github.event.comment.body, '/pr mark ready') && github.event.issue.pull_request runs-on: ubuntu-latest steps: - name: Move To Initial Review @@ -23,9 +23,7 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, }) - const code_reviews = projects.data.find(project => { - return project.name === 'Code Reviews'; - }) + const code_reviews = projects.data.find(project => project.name === 'Code Reviews'); if (!code_reviews) { console.error("'Code Reviews' project not found!") return @@ -64,5 +62,5 @@ jobs: position: 'bottom', column_id: initial_review.id, }).catch(error => { - console.error("Error occured while moving card to 'Initial Review'!") + console.error("Error occured while moving card to 'Initial Review': {error}") }) diff --git a/.github/workflows/move-work-in-progress-prs.yml b/.github/workflows/move-work-in-progress-prs.yml index 94523b02473..ba4fff41bf4 100644 --- a/.github/workflows/move-work-in-progress-prs.yml +++ b/.github/workflows/move-work-in-progress-prs.yml @@ -10,7 +10,7 @@ on: jobs: move-pr-to-wip: - if: github.event.comment.body == '/pr mark wip' && github.event.issue.pull_request + if: contains(github.event.comment.body, '/pr mark wip') && github.event.issue.pull_request runs-on: ubuntu-latest steps: - name: Move To Work In Progress @@ -23,9 +23,7 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, }) - const code_reviews = projects.data.find(project => { - return project.name === 'Code Reviews'; - }) + const code_reviews = projects.data.find(project => project.name === 'Code Reviews'); if (!code_reviews) { console.error("'Code Reviews' project not found!") return @@ -61,7 +59,7 @@ jobs: position: 'bottom', column_id: work_in_progress.id, }).catch(error => { - console.error("Error occured while moving card to Work In Progress!") + console.error("Error occured while moving card to 'Work In Progress': {error}") }) } }) From 17121c3bdb8e5abb553f55a3a2fca9a28e62ef43 Mon Sep 17 00:00:00 2001 From: Sam Huang Date: Mon, 29 Aug 2022 16:49:29 -0700 Subject: [PATCH 09/13] Properly use template literals --- .github/workflows/move-ready-for-review-prs.yml | 2 +- .github/workflows/move-work-in-progress-prs.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/move-ready-for-review-prs.yml b/.github/workflows/move-ready-for-review-prs.yml index acc3879b056..3890d0415ba 100644 --- a/.github/workflows/move-ready-for-review-prs.yml +++ b/.github/workflows/move-ready-for-review-prs.yml @@ -62,5 +62,5 @@ jobs: position: 'bottom', column_id: initial_review.id, }).catch(error => { - console.error("Error occured while moving card to 'Initial Review': {error}") + console.error(`Error occured while moving card to 'Initial Review': ${error}`) }) diff --git a/.github/workflows/move-work-in-progress-prs.yml b/.github/workflows/move-work-in-progress-prs.yml index ba4fff41bf4..7cb59806195 100644 --- a/.github/workflows/move-work-in-progress-prs.yml +++ b/.github/workflows/move-work-in-progress-prs.yml @@ -59,7 +59,7 @@ jobs: position: 'bottom', column_id: work_in_progress.id, }).catch(error => { - console.error("Error occured while moving card to 'Work In Progress': {error}") + console.error(`Error occured while moving card to 'Work In Progress': ${error}`) }) } }) From 4bab90a80f51054fd9965dcc90c9e78db8748786 Mon Sep 17 00:00:00 2001 From: Sam Huang Date: Mon, 29 Aug 2022 18:22:55 -0700 Subject: [PATCH 10/13] Use pagination instead of `list*` methods --- .../workflows/move-ready-for-review-prs.yml | 15 +++--- .../workflows/move-work-in-progress-prs.yml | 50 +++++++++---------- 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/.github/workflows/move-ready-for-review-prs.yml b/.github/workflows/move-ready-for-review-prs.yml index 3890d0415ba..ba232969383 100644 --- a/.github/workflows/move-ready-for-review-prs.yml +++ b/.github/workflows/move-ready-for-review-prs.yml @@ -19,11 +19,11 @@ jobs: script: | // Find "Code Reviews" project manually by name matching // This avoids hardcoding the project ID - const projects = await github.rest.projects.listForRepo({ + const projects = await github.paginate(github.rest.projects.listForRepo, { owner: context.repo.owner, repo: context.repo.repo, }) - const code_reviews = projects.data.find(project => project.name === 'Code Reviews'); + const code_reviews = projects.find(project => project.name === 'Code Reviews'); if (!code_reviews) { console.error("'Code Reviews' project not found!") return @@ -32,26 +32,25 @@ jobs: // Find "Initial Review" column manually by name matching // This assumes the card is in "Work In Progress" column // This avoids hardcoding the column ID and card ID - const columns = await github.rest.projects.listColumns({ + const columns = await github.paginate(github.rest.projects.listColumns, { project_id: code_reviews.id, }); - const work_in_progress = columns.data.find(column => column.name === 'Work In Progress') + const work_in_progress = columns.find(column => column.name === 'Work In Progress') if (!work_in_progress) { console.error("'Work In Progress' column not found!") return } - const initial_review = columns.data.find(column => column.name === 'Initial Review') + const initial_review = columns.find(column => column.name === 'Initial Review') if (!initial_review) { console.error("'Initial Review' column not found!") return } - const work_in_progress_cards = await github.rest.projects.listCards({ + const pr_card = await github.paginate(github.rest.projects.listCards, { column_id: work_in_progress.id, - }) - const pr_card = work_in_progress_cards.data.find(card => card.content_url === context.payload.issue.url) + }).then(cards => cards.find(card => card.content_url === context.payload.issue.url)) if (!pr_card) { console.error("Corresponding card for PR not found!") return diff --git a/.github/workflows/move-work-in-progress-prs.yml b/.github/workflows/move-work-in-progress-prs.yml index 7cb59806195..bca33a175b9 100644 --- a/.github/workflows/move-work-in-progress-prs.yml +++ b/.github/workflows/move-work-in-progress-prs.yml @@ -19,11 +19,11 @@ jobs: script: | // Find "Code Reviews" project manually by name matching // This avoids hardcoding the project ID - const projects = await github.rest.projects.listForRepo({ + const projects = await github.paginate(github.rest.projects.listForRepo, { owner: context.repo.owner, repo: context.repo.repo, }) - const code_reviews = projects.data.find(project => project.name === 'Code Reviews'); + const code_reviews = projects.find(project => project.name === 'Code Reviews'); if (!code_reviews) { console.error("'Code Reviews' project not found!") return @@ -32,39 +32,39 @@ jobs: // Find "Work In Progress" column manually by name matching // Also find the card of the PR in either "Initial Review" or "Final Review" // This avoids hardcoding the column ID and card ID - const columns = await github.rest.projects.listColumns({ + const columns = await github.paginate(github.rest.projects.listColumns, { project_id: code_reviews.id, }); - const work_in_progress = columns.data.find(column => column.name === 'Work In Progress') + const work_in_progress = columns.find(column => column.name === 'Work In Progress') if (!work_in_progress) { console.error("'Work In Progress' column not found!") return } - columns.data.forEach(column => { + const move_card_in_column = async (column) => { + const cards = await github.paginate(github.rest.projects.listCards, { + column_id: column.id, + }) + + const pr_card = cards.find(card => card.content_url === context.payload.issue.url) + if (!pr_card) { + return // the PR card is not in this column + } + + await github.rest.projects.moveCard({ + card_id: pr_card.id, + position: 'bottom', + column_id: work_in_progress.id, + }) + } + + columns.forEach(column => { if (column.name !== 'Initial Review' && column.name !== 'Final Review') { return // no reason to search through other columns and avoids unnecessary API calls } - github.rest.projects.listCards({ - column_id: column.id, - }).then(cards => { - cards.data.forEach(card => { - if (card.content_url === context.payload.issue.url) { - // card is the PR card - - github.rest.projects.moveCard({ - card_id: card.id, - position: 'bottom', - column_id: work_in_progress.id, - }).catch(error => { - console.error(`Error occured while moving card to 'Work In Progress': ${error}`) - }) - } - }) - }) - .catch(error => { - console.error("Error while fetching cards from column ID " + column.id) - }) + move_card_in_column(column).catch(error => { + console.error(`Error occured while moving card to 'Work In Progress': ${error}`) + }) }) From 95ca181c9acc9110822560ea16dc71cc98a61f22 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 25 Oct 2022 13:54:51 -0700 Subject: [PATCH 11/13] Fix typos. --- .github/workflows/move-ready-for-review-prs.yml | 2 +- .github/workflows/move-work-in-progress-prs.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/move-ready-for-review-prs.yml b/.github/workflows/move-ready-for-review-prs.yml index ba232969383..481e4b630e3 100644 --- a/.github/workflows/move-ready-for-review-prs.yml +++ b/.github/workflows/move-ready-for-review-prs.yml @@ -61,5 +61,5 @@ jobs: position: 'bottom', column_id: initial_review.id, }).catch(error => { - console.error(`Error occured while moving card to 'Initial Review': ${error}`) + console.error(`Error occurred while moving card to 'Initial Review': ${error}`) }) diff --git a/.github/workflows/move-work-in-progress-prs.yml b/.github/workflows/move-work-in-progress-prs.yml index bca33a175b9..3fc523aa075 100644 --- a/.github/workflows/move-work-in-progress-prs.yml +++ b/.github/workflows/move-work-in-progress-prs.yml @@ -65,6 +65,6 @@ jobs: } move_card_in_column(column).catch(error => { - console.error(`Error occured while moving card to 'Work In Progress': ${error}`) + console.error(`Error occurred while moving card to 'Work In Progress': ${error}`) }) }) From 9d28f64ad7576f9ecbd43b11ed1897d40bdf1120 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 25 Oct 2022 14:15:21 -0700 Subject: [PATCH 12/13] Add semicolons. --- .../workflows/move-ready-for-review-prs.yml | 28 ++++++++--------- .../workflows/move-work-in-progress-prs.yml | 30 +++++++++---------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/.github/workflows/move-ready-for-review-prs.yml b/.github/workflows/move-ready-for-review-prs.yml index 481e4b630e3..c8b29784221 100644 --- a/.github/workflows/move-ready-for-review-prs.yml +++ b/.github/workflows/move-ready-for-review-prs.yml @@ -22,11 +22,11 @@ jobs: const projects = await github.paginate(github.rest.projects.listForRepo, { owner: context.repo.owner, repo: context.repo.repo, - }) + }); const code_reviews = projects.find(project => project.name === 'Code Reviews'); if (!code_reviews) { - console.error("'Code Reviews' project not found!") - return + console.error("'Code Reviews' project not found!"); + return; } // Find "Initial Review" column manually by name matching @@ -36,24 +36,24 @@ jobs: project_id: code_reviews.id, }); - const work_in_progress = columns.find(column => column.name === 'Work In Progress') + const work_in_progress = columns.find(column => column.name === 'Work In Progress'); if (!work_in_progress) { - console.error("'Work In Progress' column not found!") - return + console.error("'Work In Progress' column not found!"); + return; } - const initial_review = columns.find(column => column.name === 'Initial Review') + const initial_review = columns.find(column => column.name === 'Initial Review'); if (!initial_review) { - console.error("'Initial Review' column not found!") - return + console.error("'Initial Review' column not found!"); + return; } const pr_card = await github.paginate(github.rest.projects.listCards, { column_id: work_in_progress.id, - }).then(cards => cards.find(card => card.content_url === context.payload.issue.url)) + }).then(cards => cards.find(card => card.content_url === context.payload.issue.url)); if (!pr_card) { - console.error("Corresponding card for PR not found!") - return + console.error("Corresponding card for PR not found!"); + return; } github.rest.projects.moveCard({ @@ -61,5 +61,5 @@ jobs: position: 'bottom', column_id: initial_review.id, }).catch(error => { - console.error(`Error occurred while moving card to 'Initial Review': ${error}`) - }) + console.error(`Error occurred while moving card to 'Initial Review': ${error}`); + }); diff --git a/.github/workflows/move-work-in-progress-prs.yml b/.github/workflows/move-work-in-progress-prs.yml index 3fc523aa075..7ab6ab66013 100644 --- a/.github/workflows/move-work-in-progress-prs.yml +++ b/.github/workflows/move-work-in-progress-prs.yml @@ -22,11 +22,11 @@ jobs: const projects = await github.paginate(github.rest.projects.listForRepo, { owner: context.repo.owner, repo: context.repo.repo, - }) + }); const code_reviews = projects.find(project => project.name === 'Code Reviews'); if (!code_reviews) { - console.error("'Code Reviews' project not found!") - return + console.error("'Code Reviews' project not found!"); + return; } // Find "Work In Progress" column manually by name matching @@ -36,35 +36,35 @@ jobs: project_id: code_reviews.id, }); - const work_in_progress = columns.find(column => column.name === 'Work In Progress') + const work_in_progress = columns.find(column => column.name === 'Work In Progress'); if (!work_in_progress) { - console.error("'Work In Progress' column not found!") - return + console.error("'Work In Progress' column not found!"); + return; } const move_card_in_column = async (column) => { const cards = await github.paginate(github.rest.projects.listCards, { column_id: column.id, - }) + }); - const pr_card = cards.find(card => card.content_url === context.payload.issue.url) + const pr_card = cards.find(card => card.content_url === context.payload.issue.url); if (!pr_card) { - return // the PR card is not in this column + return; // the PR card is not in this column } await github.rest.projects.moveCard({ card_id: pr_card.id, position: 'bottom', column_id: work_in_progress.id, - }) - } + }); + }; columns.forEach(column => { if (column.name !== 'Initial Review' && column.name !== 'Final Review') { - return // no reason to search through other columns and avoids unnecessary API calls + return; // no reason to search through other columns and avoids unnecessary API calls } move_card_in_column(column).catch(error => { - console.error(`Error occurred while moving card to 'Work In Progress': ${error}`) - }) - }) + console.error(`Error occurred while moving card to 'Work In Progress': ${error}`); + }); + }); From d9074df798cff372b94234b9c97a47766b06e2ca Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 25 Oct 2022 15:24:06 -0700 Subject: [PATCH 13/13] Check PR first, author second, substring third. Shorten commands. --- .github/workflows/move-ready-for-review-prs.yml | 5 ++++- .github/workflows/move-work-in-progress-prs.yml | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/move-ready-for-review-prs.yml b/.github/workflows/move-ready-for-review-prs.yml index c8b29784221..2c9c0f52998 100644 --- a/.github/workflows/move-ready-for-review-prs.yml +++ b/.github/workflows/move-ready-for-review-prs.yml @@ -10,7 +10,10 @@ on: jobs: move-pr-to-initial-review: - if: contains(github.event.comment.body, '/pr mark ready') && github.event.issue.pull_request + if: > + github.event.issue.pull_request + && github.event.comment.user.login == github.event.issue.user.login + && contains(github.event.comment.body, '/pr review') runs-on: ubuntu-latest steps: - name: Move To Initial Review diff --git a/.github/workflows/move-work-in-progress-prs.yml b/.github/workflows/move-work-in-progress-prs.yml index 7ab6ab66013..11813607d31 100644 --- a/.github/workflows/move-work-in-progress-prs.yml +++ b/.github/workflows/move-work-in-progress-prs.yml @@ -10,7 +10,10 @@ on: jobs: move-pr-to-wip: - if: contains(github.event.comment.body, '/pr mark wip') && github.event.issue.pull_request + if: > + github.event.issue.pull_request + && github.event.comment.user.login == github.event.issue.user.login + && contains(github.event.comment.body, '/pr wip') runs-on: ubuntu-latest steps: - name: Move To Work In Progress