From 4f2148328ae77ac7198e540c4306ddcdffcc415d Mon Sep 17 00:00:00 2001 From: Tomoya Kashifuku Date: Mon, 4 Mar 2024 09:04:30 +0900 Subject: [PATCH 1/7] set threshold and send message if the number of comment exceeds it for the first time --- action.yml | 6 ++++++ src/main.ts | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/action.yml b/action.yml index 166443d..e5ffca9 100644 --- a/action.yml +++ b/action.yml @@ -17,6 +17,12 @@ inputs: description: 'a target pr number. This is set for events triggered by issue_comment' required: false + threshold: + description: + 'a threshold at which a message is sent when the number of comments + exceeds this' + required: true + default: 4 # Define your outputs here. outputs: diff --git a/src/main.ts b/src/main.ts index b0ea662..46de3f8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -53,6 +53,18 @@ export async function run(): Promise { }) ).data.filter(c => c.user.type !== 'Bot') + const hasMessageSent = comments.some( + comment => + comment.user?.type === 'Bot' && + comment.body?.includes('It seems the discussion is dragging on.') + ) + const threshold = Number(core.getInput('threshold', { required: true })) + const commentCount = comments.length + reviewComments.length + if (commentCount < threshold || hasMessageSent) { + core.debug('a message has been sent') + return + } + const userLogins = uniqueStringArray( comments .map(comment => comment.user?.login) From faa8a4ceb6ed67881d21d4744fc96ab384a703a4 Mon Sep 17 00:00:00 2001 From: Tomoya Kashifuku Date: Mon, 4 Mar 2024 09:04:59 +0900 Subject: [PATCH 2/7] set concurrency not to send a lot of comments when users comment on review --- .github/workflows/test-action.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test-action.yml b/.github/workflows/test-action.yml index af1848a..8b16ca5 100644 --- a/.github/workflows/test-action.yml +++ b/.github/workflows/test-action.yml @@ -4,6 +4,10 @@ on: issue_comment: types: [created] +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + permissions: contents: read From 98500555ddf6f3738f3aefaa21d3145ef15b3ac2 Mon Sep 17 00:00:00 2001 From: Tomoya Kashifuku Date: Mon, 4 Mar 2024 09:08:39 +0900 Subject: [PATCH 3/7] debug --- src/main.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index 46de3f8..d450470 100644 --- a/src/main.ts +++ b/src/main.ts @@ -60,7 +60,10 @@ export async function run(): Promise { ) const threshold = Number(core.getInput('threshold', { required: true })) const commentCount = comments.length + reviewComments.length - if (commentCount < threshold || hasMessageSent) { + if (commentCount < threshold) { + return + } + if (hasMessageSent) { core.debug('a message has been sent') return } @@ -80,7 +83,8 @@ export async function run(): Promise { It seems the discussion is dragging on. Perhaps instead of text communication, you could try having a conversation via face-to-face or video call, or even try mob programming? -the number of the comments is ${comments.length} and the review comments is ${reviewComments.length}` +the number of the comments is ${comments.length} and the review comments is ${reviewComments.length} +threshold: ${threshold}, commentCount: ${commentCount}` }) core.debug(`Commented on PR #${prNumber}`) } catch (error) { From 7b8abccd9e520bc38d2bed16cc61084a63697ebe Mon Sep 17 00:00:00 2001 From: Tomoya Kashifuku Date: Mon, 4 Mar 2024 09:09:35 +0900 Subject: [PATCH 4/7] run bundle --- dist/index.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index b2f2639..f2d8749 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29047,6 +29047,17 @@ async function run() { repo, pull_number: prNumber })).data.filter(c => c.user.type !== 'Bot'); + const hasMessageSent = comments.some(comment => comment.user?.type === 'Bot' && + comment.body?.includes('It seems the discussion is dragging on.')); + const threshold = Number(core.getInput('threshold', { required: true })); + const commentCount = comments.length + reviewComments.length; + if (commentCount < threshold) { + return; + } + if (hasMessageSent) { + core.debug('a message has been sent'); + return; + } const userLogins = uniqueStringArray(comments .map(comment => comment.user?.login) .concat(reviewComments.map(comment => comment.user.login)) @@ -29059,7 +29070,8 @@ async function run() { It seems the discussion is dragging on. Perhaps instead of text communication, you could try having a conversation via face-to-face or video call, or even try mob programming? -the number of the comments is ${comments.length} and the review comments is ${reviewComments.length}` +the number of the comments is ${comments.length} and the review comments is ${reviewComments.length} +threshold: ${threshold}, commentCount: ${commentCount}` }); core.debug(`Commented on PR #${prNumber}`); } From 565b8aafdf746f4e091dbdae4780d1b2eeb8410c Mon Sep 17 00:00:00 2001 From: Tomoya Kashifuku Date: Mon, 4 Mar 2024 09:18:04 +0900 Subject: [PATCH 5/7] set default threshold to 25 and set small number for the test workflow --- .github/workflows/test-action.yml | 1 + action.yml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-action.yml b/.github/workflows/test-action.yml index 8b16ca5..f064ec4 100644 --- a/.github/workflows/test-action.yml +++ b/.github/workflows/test-action.yml @@ -38,6 +38,7 @@ jobs: uses: ./ with: pr_number: ${{ steps.get-pr-number.outputs.pr-number }} + threshold: 4 - name: Print Output id: output diff --git a/action.yml b/action.yml index e5ffca9..35576f6 100644 --- a/action.yml +++ b/action.yml @@ -22,7 +22,7 @@ inputs: 'a threshold at which a message is sent when the number of comments exceeds this' required: true - default: 4 + default: 25 # Define your outputs here. outputs: From 832648b9e4620fb3ed873da0e2872077583ac103 Mon Sep 17 00:00:00 2001 From: Tomoya Kashifuku Date: Mon, 4 Mar 2024 09:18:50 +0900 Subject: [PATCH 6/7] update check --- dist/index.js | 3 +-- src/main.ts | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/dist/index.js b/dist/index.js index f2d8749..4734fb2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29047,8 +29047,7 @@ async function run() { repo, pull_number: prNumber })).data.filter(c => c.user.type !== 'Bot'); - const hasMessageSent = comments.some(comment => comment.user?.type === 'Bot' && - comment.body?.includes('It seems the discussion is dragging on.')); + const hasMessageSent = comments.some(comment => comment.body?.includes('It seems the discussion is dragging on.')); const threshold = Number(core.getInput('threshold', { required: true })); const commentCount = comments.length + reviewComments.length; if (commentCount < threshold) { diff --git a/src/main.ts b/src/main.ts index d450470..e3f82ed 100644 --- a/src/main.ts +++ b/src/main.ts @@ -53,10 +53,8 @@ export async function run(): Promise { }) ).data.filter(c => c.user.type !== 'Bot') - const hasMessageSent = comments.some( - comment => - comment.user?.type === 'Bot' && - comment.body?.includes('It seems the discussion is dragging on.') + const hasMessageSent = comments.some(comment => + comment.body?.includes('It seems the discussion is dragging on.') ) const threshold = Number(core.getInput('threshold', { required: true })) const commentCount = comments.length + reviewComments.length From 80e7ea9acc6c0b9e9cd1da02be7ba47257d6c28d Mon Sep 17 00:00:00 2001 From: Tomoya Kashifuku Date: Wed, 6 Mar 2024 00:00:39 +0900 Subject: [PATCH 7/7] move threshold to options --- dist/index.js | 7 ++++--- src/main.ts | 3 +-- src/option.ts | 6 +++++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/dist/index.js b/dist/index.js index 503592d..a81902c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29027,7 +29027,7 @@ const uniqueStringArray = (texts) => { */ async function run() { try { - const { token, prNumber } = (0, option_1.getOption)(); + const { token, prNumber, threshold } = (0, option_1.getOption)(); const octokit = (0, github_1.getOctokit)(token); const owner = github_1.context.repo.owner; const repo = github_1.context.repo.repo; @@ -29043,7 +29043,6 @@ async function run() { pull_number: prNumber })).data.filter(c => c.user.type !== 'Bot'); const hasMessageSent = comments.some(comment => comment.body?.includes('It seems the discussion is dragging on.')); - const threshold = Number(core.getInput('threshold', { required: true })); const commentCount = comments.length + reviewComments.length; if (commentCount < threshold) { return; @@ -29103,9 +29102,11 @@ function getOption() { if (isNaN(prNumber) || prNumber === 0) { (0, core_1.setFailed)('pr number is not set properly'); } + const threshold = Number((0, core_1.getInput)('threshold', { required: true })); return { token, - prNumber + prNumber, + threshold }; } exports.getOption = getOption; diff --git a/src/main.ts b/src/main.ts index 449323f..aa4a362 100644 --- a/src/main.ts +++ b/src/main.ts @@ -23,7 +23,7 @@ const uniqueStringArray = (texts: string[]): string[] => { */ export async function run(): Promise { try { - const { token, prNumber } = getOption() + const { token, prNumber, threshold } = getOption() const octokit = getOctokit(token) const owner = context.repo.owner @@ -50,7 +50,6 @@ export async function run(): Promise { const hasMessageSent = comments.some(comment => comment.body?.includes('It seems the discussion is dragging on.') ) - const threshold = Number(core.getInput('threshold', { required: true })) const commentCount = comments.length + reviewComments.length if (commentCount < threshold) { return diff --git a/src/option.ts b/src/option.ts index 6042850..ddf5073 100644 --- a/src/option.ts +++ b/src/option.ts @@ -4,6 +4,7 @@ import { context } from '@actions/github' type Option = { token: string prNumber: number + threshold: number } function getPrNumber(): number { @@ -24,8 +25,11 @@ export function getOption(): Option { setFailed('pr number is not set properly') } + const threshold = Number(getInput('threshold', { required: true })) + return { token, - prNumber + prNumber, + threshold } }