Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
56 changes: 55 additions & 1 deletion __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('main.ts', () => {
)
})

it('Skips adding a message if this is not the first contribution', async () => {
it('Skips a message if the sender has prior issues and PRs', async () => {
Comment thread
t-hamano marked this conversation as resolved.
Outdated
mocktokit.paginate
// Issues
.mockResolvedValueOnce([
Expand All @@ -115,6 +115,60 @@ describe('main.ts', () => {
expect(mocktokit.rest.issues.createComment).not.toHaveBeenCalled()
})

it('Skips an issue message if the sender has prior issues but no PRs', async () => {
github.context.payload.issue = {
number: 10
}
github.context.payload.pull_request = undefined as any

mocktokit.paginate
// Issues
.mockResolvedValueOnce([
{
number: 10
},
{
number: 5
}
])
// PRs
.mockResolvedValueOnce([])

await main.run()

expect(core.info).toHaveBeenCalledWith(
'Skipping...Not First Contribution'
)
expect(mocktokit.rest.issues.createComment).not.toHaveBeenCalled()
})
Comment thread
t-hamano marked this conversation as resolved.

it('Skips a PR message if the sender has prior PRs but no issues', async () => {
github.context.payload.issue = undefined as any
github.context.payload.pull_request = {
number: 10
}

mocktokit.paginate
// PRs
.mockResolvedValueOnce([
{
number: 10
},
{
number: 5
}
])
// Issues
.mockResolvedValueOnce([])
Comment thread
t-hamano marked this conversation as resolved.
Outdated

await main.run()

expect(core.info).toHaveBeenCalledWith(
'Skipping...Not First Contribution'
)
expect(mocktokit.rest.issues.createComment).not.toHaveBeenCalled()
Comment thread
t-hamano marked this conversation as resolved.
})
Comment thread
t-hamano marked this conversation as resolved.

it('Adds an issue message if this is the first contribution', async () => {
github.context.payload.issue = {
number: 10
Expand Down
5 changes: 4 additions & 1 deletion dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ export async function run() {
})

// Check if this is the user's first contribution.
if (!(await isFirstIssue(octokit)) && !(await isFirstPullRequest(octokit)))
const isFirstContribution = isIssue
? await isFirstIssue(octokit)
: await isFirstPullRequest(octokit)

if (!isFirstContribution)
return core.info('Skipping...Not First Contribution')

core.info(`Adding Message to #${github.context.issue.number}`)
Expand Down