Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set threshold #13

Merged
merged 8 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4

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
}
}
Loading