Skip to content

Commit

Permalink
set threshold (#13)
Browse files Browse the repository at this point in the history
* set threshold and send message if the number of comment exceeds it for the first time

* set concurrency not to send a lot of comments when users comment on review

* debug

* run bundle

* set default threshold to 25 and set small number for the test workflow

* update check

* move threshold to options
  • Loading branch information
tnyo43 committed Mar 7, 2024
1 parent 408beaf commit df4e69d
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
issue_comment:
types: [created]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

Expand All @@ -22,6 +26,8 @@ jobs:
- name: Test Local Action
id: test-action
uses: ./
with:
threshold: 4

- name: Print Output
id: output
Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 15 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const uniqueStringArray = (texts: string[]): string[] => {
*/
export async function run(): Promise<void> {
try {
const { token, prNumber } = getOption()
const { token, prNumber, threshold } = getOption()

const octokit = getOctokit(token)
const owner = context.repo.owner
Expand All @@ -47,6 +47,18 @@ export async function run(): Promise<void> {
})
).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)
Expand All @@ -62,7 +74,8 @@ export async function run(): Promise<void> {
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) {
Expand Down
6 changes: 5 additions & 1 deletion src/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { context } from '@actions/github'
type Option = {
token: string
prNumber: number
threshold: number
}

function getPrNumber(): number {
Expand All @@ -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
}
}

0 comments on commit df4e69d

Please sign in to comment.