From e093f83ff2ed8bf82d451a9abdc03887a30d964f Mon Sep 17 00:00:00 2001 From: Mathieu Veber Date: Tue, 1 Oct 2024 12:23:13 +0200 Subject: [PATCH 01/17] fix(pull-request): Only assign team if PR has not been reviewed --- .github/workflows/pull-request.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index fc7c2c9..ba6f5f5 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -57,6 +57,7 @@ jobs: await github.rest.issues.addAssignees({ owner, repo, issue_number, assignees }); - if: > + github.event.pull_request.comments == 0 && github.event.pull_request.draft == false && github.event.pull_request.requested_reviewers[0] == null && github.event.pull_request.requested_teams[0] == null From cb0f53150673bbbc36a1de89dc46e63387eacd69 Mon Sep 17 00:00:00 2001 From: Mathieu Veber Date: Tue, 1 Oct 2024 13:20:13 +0200 Subject: [PATCH 02/17] feat(pull-request): remove team request - on converted to draft - on other reviewer requested - on other reviewer reviewed --- .github/workflows/pull-request.yml | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index ba6f5f5..424b411 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -57,10 +57,10 @@ jobs: await github.rest.issues.addAssignees({ owner, repo, issue_number, assignees }); - if: > - github.event.pull_request.comments == 0 && github.event.pull_request.draft == false && github.event.pull_request.requested_reviewers[0] == null && - github.event.pull_request.requested_teams[0] == null + github.event.pull_request.requested_teams[0] == null && + github.event.pull_request.review_comments == 0 name: Request Reviewers uses: actions/github-script@v7 with: @@ -76,6 +76,32 @@ jobs: await github.rest.pulls.requestReviewers({ owner, repo, pull_number, reviewers, team_reviewers }); + - if: > + ( + github.event.pull_request.draft == true && + github.event.pull_request.requested_teams[0] != null + ) || ( + github.event.pull_request.requested_reviewers[0] != null && + github.event.pull_request.requested_teams[0] != null + ) || ( + github.event.pull_request.requested_teams[0] != null && + github.event.pull_request.review_comments > 0 + ) + name: Remove Team Request + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.HEDIA_BOT_GITHUB_PAT }} + script: | + const owner = "${{ github.repository_owner }}"; + const repo = "${{ github.event.repository.name }}"; + const pull_number = ${{ github.event.pull_request.number }}; + const reviewers = []; + const team_reviewers = "${{ github.event.inputs.team-reviewers }}".split(',').filter((reviewer) => reviewer); + + console.log(`@${owner}/${repo}#${pull_number}: Removing review from ${reviewers.concat(team_reviewers)}`); + + await github.rest.pulls.removeRequestedReviewers({ owner, repo, pull_number, reviewers, team_reviewers }); + - name: Set Labels uses: hedia-team/.github/.github/actions/set-labels@main with: From f321adea57e9bb27f570ca911b0c866525137bf2 Mon Sep 17 00:00:00 2001 From: Mathieu Veber Date: Tue, 1 Oct 2024 14:16:15 +0200 Subject: [PATCH 03/17] ci(pull-request): trigger on same events as in other repos --- .github/workflows/pull-request.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 424b411..d5d157e 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -3,10 +3,12 @@ name: Pull Request on: pull_request: types: + - converted_to_draft - edited - opened - ready_for_review - reopened + - synchronize workflow_call: inputs: From dd0dca71abdbfdd3112e59ddd4384a07b2bb8919 Mon Sep 17 00:00:00 2001 From: Mathieu Veber Date: Tue, 1 Oct 2024 14:21:57 +0200 Subject: [PATCH 04/17] fix(pull-request): try another property --- .github/workflows/pull-request.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index d5d157e..430d3b6 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -71,8 +71,8 @@ jobs: const owner = "${{ github.repository_owner }}"; const repo = "${{ github.event.repository.name }}"; const pull_number = ${{ github.event.pull_request.number }}; - const reviewers = "${{ github.event.inputs.reviewers || inputs.reviewers }}".split(',').filter((reviewer) => reviewer); - const team_reviewers = "${{ github.event.inputs.team-reviewers || inputs.team-reviewers }}".split(',').filter((reviewer) => reviewer); + const reviewers = "${{ github.event.pull_request.requested_reviewers || inputs.reviewers }}".split(',').filter((reviewer) => reviewer); + const team_reviewers = "${{ github.event.pull_request.requested_teams || inputs.team-reviewers }}".split(',').filter((reviewer) => reviewer); console.log(`@${owner}/${repo}#${pull_number}: Requesting review from ${reviewers.concat(team_reviewers)}`); @@ -98,7 +98,7 @@ jobs: const repo = "${{ github.event.repository.name }}"; const pull_number = ${{ github.event.pull_request.number }}; const reviewers = []; - const team_reviewers = "${{ github.event.inputs.team-reviewers }}".split(',').filter((reviewer) => reviewer); + const team_reviewers = "${{ github.event.pull_request.requested_teams }}".split(',').filter((reviewer) => reviewer); console.log(`@${owner}/${repo}#${pull_number}: Removing review from ${reviewers.concat(team_reviewers)}`); From eab7a82a9b50d37cbf1dd0f1afb2f97748ed4e91 Mon Sep 17 00:00:00 2001 From: Mathieu Veber Date: Tue, 1 Oct 2024 14:47:25 +0200 Subject: [PATCH 05/17] 1 --- .github/workflows/pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 430d3b6..5fa67db 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -98,7 +98,7 @@ jobs: const repo = "${{ github.event.repository.name }}"; const pull_number = ${{ github.event.pull_request.number }}; const reviewers = []; - const team_reviewers = "${{ github.event.pull_request.requested_teams }}".split(',').filter((reviewer) => reviewer); + const team_reviewers = "${{ github.event.pull_request.requested_teams.length }}".split(',').filter((reviewer) => reviewer); console.log(`@${owner}/${repo}#${pull_number}: Removing review from ${reviewers.concat(team_reviewers)}`); From 398dbae835ed37cdeac9eb11a10999fe49bacd1b Mon Sep 17 00:00:00 2001 From: Mathieu Veber Date: Wed, 2 Oct 2024 13:48:02 +0200 Subject: [PATCH 06/17] 3 --- .github/workflows/pull-request.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 5fa67db..1c9d678 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -71,9 +71,8 @@ jobs: const owner = "${{ github.repository_owner }}"; const repo = "${{ github.event.repository.name }}"; const pull_number = ${{ github.event.pull_request.number }}; - const reviewers = "${{ github.event.pull_request.requested_reviewers || inputs.reviewers }}".split(',').filter((reviewer) => reviewer); - const team_reviewers = "${{ github.event.pull_request.requested_teams || inputs.team-reviewers }}".split(',').filter((reviewer) => reviewer); - + const reviewers = "${{ github.event.inputs.reviewers || inputs.reviewers }}".split(',').filter((reviewer) => reviewer); + const team_reviewers = "${{ github.event.inputs.team-reviewers || inputs.team-reviewers }}".split(',').filter((reviewer) => reviewer); console.log(`@${owner}/${repo}#${pull_number}: Requesting review from ${reviewers.concat(team_reviewers)}`); await github.rest.pulls.requestReviewers({ owner, repo, pull_number, reviewers, team_reviewers }); @@ -98,7 +97,7 @@ jobs: const repo = "${{ github.event.repository.name }}"; const pull_number = ${{ github.event.pull_request.number }}; const reviewers = []; - const team_reviewers = "${{ github.event.pull_request.requested_teams.length }}".split(',').filter((reviewer) => reviewer); + const team_reviewers = ["${{ github.event.pull_request.requested_teams[0] }}"]; console.log(`@${owner}/${repo}#${pull_number}: Removing review from ${reviewers.concat(team_reviewers)}`); From da7851c74ecf3d43d45df5673d9fdaf92f690d3e Mon Sep 17 00:00:00 2001 From: Mathieu Veber Date: Wed, 2 Oct 2024 13:50:16 +0200 Subject: [PATCH 07/17] crossing fingers --- .github/workflows/pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 1c9d678..c959da0 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -97,7 +97,7 @@ jobs: const repo = "${{ github.event.repository.name }}"; const pull_number = ${{ github.event.pull_request.number }}; const reviewers = []; - const team_reviewers = ["${{ github.event.pull_request.requested_teams[0] }}"]; + const team_reviewers = ["${{ github.event.pull_request.requested_teams[0].name }}"]; console.log(`@${owner}/${repo}#${pull_number}: Removing review from ${reviewers.concat(team_reviewers)}`); From 7495ffdc381af922bc92fab3a3a15da5205b07b3 Mon Sep 17 00:00:00 2001 From: Mathieu Veber Date: Wed, 2 Oct 2024 13:53:35 +0200 Subject: [PATCH 08/17] come on! --- .github/workflows/pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index c959da0..2ee746a 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -97,7 +97,7 @@ jobs: const repo = "${{ github.event.repository.name }}"; const pull_number = ${{ github.event.pull_request.number }}; const reviewers = []; - const team_reviewers = ["${{ github.event.pull_request.requested_teams[0].name }}"]; + const team_reviewers = ["${{ github.event.pull_request.requested_teams[0].slug }}"]; console.log(`@${owner}/${repo}#${pull_number}: Removing review from ${reviewers.concat(team_reviewers)}`); From c9d98793a80dc2940f298cffee908c7f85ca2c50 Mon Sep 17 00:00:00 2001 From: Mathieu Veber Date: Wed, 2 Oct 2024 15:56:30 +0200 Subject: [PATCH 09/17] sure --- .github/workflows/pull-request.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 2ee746a..6430cd8 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -61,18 +61,20 @@ jobs: - if: > github.event.pull_request.draft == false && github.event.pull_request.requested_reviewers[0] == null && - github.event.pull_request.requested_teams[0] == null && - github.event.pull_request.review_comments == 0 + github.event.pull_request.requested_teams[0] == null name: Request Reviewers uses: actions/github-script@v7 with: github-token: ${{ secrets.HEDIA_BOT_GITHUB_PAT }} script: | + console.log('->', ${{ github.event.pull_request.review_comments }}) + const owner = "${{ github.repository_owner }}"; const repo = "${{ github.event.repository.name }}"; const pull_number = ${{ github.event.pull_request.number }}; const reviewers = "${{ github.event.inputs.reviewers || inputs.reviewers }}".split(',').filter((reviewer) => reviewer); const team_reviewers = "${{ github.event.inputs.team-reviewers || inputs.team-reviewers }}".split(',').filter((reviewer) => reviewer); + console.log(`@${owner}/${repo}#${pull_number}: Requesting review from ${reviewers.concat(team_reviewers)}`); await github.rest.pulls.requestReviewers({ owner, repo, pull_number, reviewers, team_reviewers }); From 18403c6caecbb3f6f1a0e10b9dbfd0dbda0bdcd3 Mon Sep 17 00:00:00 2001 From: Mathieu Veber Date: Wed, 2 Oct 2024 16:05:39 +0200 Subject: [PATCH 10/17] progress --- .github/workflows/pull-request.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 6430cd8..058d98d 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -8,6 +8,7 @@ on: - opened - ready_for_review - reopened + - review_requested - synchronize workflow_call: @@ -86,9 +87,6 @@ jobs: ) || ( github.event.pull_request.requested_reviewers[0] != null && github.event.pull_request.requested_teams[0] != null - ) || ( - github.event.pull_request.requested_teams[0] != null && - github.event.pull_request.review_comments > 0 ) name: Remove Team Request uses: actions/github-script@v7 From d2bf9f0a519e09515f9567e4281a104f92b42906 Mon Sep 17 00:00:00 2001 From: Mathieu Veber Date: Wed, 2 Oct 2024 16:14:16 +0200 Subject: [PATCH 11/17] test --- .github/workflows/pull-request.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 058d98d..ac42c36 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -68,14 +68,16 @@ jobs: with: github-token: ${{ secrets.HEDIA_BOT_GITHUB_PAT }} script: | - console.log('->', ${{ github.event.pull_request.review_comments }}) - const owner = "${{ github.repository_owner }}"; const repo = "${{ github.event.repository.name }}"; const pull_number = ${{ github.event.pull_request.number }}; const reviewers = "${{ github.event.inputs.reviewers || inputs.reviewers }}".split(',').filter((reviewer) => reviewer); const team_reviewers = "${{ github.event.inputs.team-reviewers || inputs.team-reviewers }}".split(',').filter((reviewer) => reviewer); + const foo = await github octokit.rest.pulls.listReviewComments({ owner, repo, pull_number }); + + console.log(JSON.stringify(foo)); + console.log(`@${owner}/${repo}#${pull_number}: Requesting review from ${reviewers.concat(team_reviewers)}`); await github.rest.pulls.requestReviewers({ owner, repo, pull_number, reviewers, team_reviewers }); From 634cb1aa892a779a041c1dc430aad23cfd10140b Mon Sep 17 00:00:00 2001 From: Mathieu Veber Date: Wed, 2 Oct 2024 16:15:32 +0200 Subject: [PATCH 12/17] oops --- .github/workflows/pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index ac42c36..29311f6 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -74,7 +74,7 @@ jobs: const reviewers = "${{ github.event.inputs.reviewers || inputs.reviewers }}".split(',').filter((reviewer) => reviewer); const team_reviewers = "${{ github.event.inputs.team-reviewers || inputs.team-reviewers }}".split(',').filter((reviewer) => reviewer); - const foo = await github octokit.rest.pulls.listReviewComments({ owner, repo, pull_number }); + const foo = await github.rest.pulls.listReviewComments({ owner, repo, pull_number }); console.log(JSON.stringify(foo)); From 22bc474bab0624ca61add2d0f1e769bd9dc4c550 Mon Sep 17 00:00:00 2001 From: Mathieu Veber Date: Wed, 2 Oct 2024 16:21:19 +0200 Subject: [PATCH 13/17] qqq --- .github/workflows/pull-request.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 29311f6..c60bd29 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -74,12 +74,11 @@ jobs: const reviewers = "${{ github.event.inputs.reviewers || inputs.reviewers }}".split(',').filter((reviewer) => reviewer); const team_reviewers = "${{ github.event.inputs.team-reviewers || inputs.team-reviewers }}".split(',').filter((reviewer) => reviewer); - const foo = await github.rest.pulls.listReviewComments({ owner, repo, pull_number }); - - console.log(JSON.stringify(foo)); - console.log(`@${owner}/${repo}#${pull_number}: Requesting review from ${reviewers.concat(team_reviewers)}`); + const { data } = await github.rest.pulls.get({ owner, repo, pull_number }); + console.log(data); + await github.rest.pulls.requestReviewers({ owner, repo, pull_number, reviewers, team_reviewers }); - if: > From 0c0b05b3cfefa17a0f2fbb4fadc033a5961d98af Mon Sep 17 00:00:00 2001 From: Mathieu Veber Date: Wed, 2 Oct 2024 16:55:45 +0200 Subject: [PATCH 14/17] ddd --- .github/workflows/pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index c60bd29..505de17 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -76,7 +76,7 @@ jobs: console.log(`@${owner}/${repo}#${pull_number}: Requesting review from ${reviewers.concat(team_reviewers)}`); - const { data } = await github.rest.pulls.get({ owner, repo, pull_number }); + const { data } = await github.rest.pulls.listReviews({ owner, repo, pull_number }); console.log(data); await github.rest.pulls.requestReviewers({ owner, repo, pull_number, reviewers, team_reviewers }); From 6e68a3d3fd10a9d4567a655fa6d1db9fbfb8ec4f Mon Sep 17 00:00:00 2001 From: Mathieu Veber Date: Wed, 2 Oct 2024 17:03:05 +0200 Subject: [PATCH 15/17] finally --- .github/workflows/pull-request.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 505de17..764bbc4 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -74,10 +74,16 @@ jobs: const reviewers = "${{ github.event.inputs.reviewers || inputs.reviewers }}".split(',').filter((reviewer) => reviewer); const team_reviewers = "${{ github.event.inputs.team-reviewers || inputs.team-reviewers }}".split(',').filter((reviewer) => reviewer); - console.log(`@${owner}/${repo}#${pull_number}: Requesting review from ${reviewers.concat(team_reviewers)}`); + console.log(`@${owner}/${repo}#${pull_number}: Retrieving reviews`); const { data } = await github.rest.pulls.listReviews({ owner, repo, pull_number }); - console.log(data); + + if (data.length === 0) { + console.log(`@${owner}/${repo}#${pull_number}: Skipping request review as there are already reviews`); + return; + } + + console.log(`@${owner}/${repo}#${pull_number}: Requesting review from ${reviewers.concat(team_reviewers)}`); await github.rest.pulls.requestReviewers({ owner, repo, pull_number, reviewers, team_reviewers }); From 628e3fa93935eda4396e0a476de41abe72a0768b Mon Sep 17 00:00:00 2001 From: Mathieu Veber Date: Wed, 2 Oct 2024 17:04:11 +0200 Subject: [PATCH 16/17] oops --- .github/workflows/pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 764bbc4..f0f7213 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -78,7 +78,7 @@ jobs: const { data } = await github.rest.pulls.listReviews({ owner, repo, pull_number }); - if (data.length === 0) { + if (data.length > 0) { console.log(`@${owner}/${repo}#${pull_number}: Skipping request review as there are already reviews`); return; } From 009fac7267734c1fefef19c0a8dd568ff9ef17c9 Mon Sep 17 00:00:00 2001 From: Mathieu Veber Date: Wed, 2 Oct 2024 17:05:22 +0200 Subject: [PATCH 17/17] sure --- .github/workflows/pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index f0f7213..1f818cc 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -79,7 +79,7 @@ jobs: const { data } = await github.rest.pulls.listReviews({ owner, repo, pull_number }); if (data.length > 0) { - console.log(`@${owner}/${repo}#${pull_number}: Skipping request review as there are already reviews`); + console.log(`@${owner}/${repo}#${pull_number}: Skipping request review as there are already ${data.length} reviews`); return; }