diff --git a/.github/workflows/test-action.yml b/.github/workflows/test-action.yml index 667fba0..14e8ca1 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 @@ -22,6 +26,8 @@ jobs: - name: Test Local Action id: test-action uses: ./ + with: + threshold: 4 - name: Print Output id: output diff --git a/action.yml b/action.yml index 0180a42..a79f798 100644 --- a/action.yml +++ b/action.yml @@ -19,6 +19,12 @@ inputs: triggered by "issue_comment" event' required: true default: ${{ github.event.issue.pull_request.url }} + threshold: + description: + 'a threshold at which a message is sent when the number of comments + exceeds this' + required: true + default: 25 # Define your outputs here. outputs: diff --git a/dist/index.js b/dist/index.js index 90a33ae..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; @@ -29042,6 +29042,15 @@ async function run() { repo, 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 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)) @@ -29054,7 +29063,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}`); } @@ -29092,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 28d0ac2..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 @@ -47,6 +47,18 @@ export async function run(): Promise { }) ).data.filter(c => c.user.type !== 'Bot') + const hasMessageSent = comments.some(comment => + comment.body?.includes('It seems the discussion is dragging on.') + ) + 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) @@ -62,7 +74,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) { 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 } }