Skip to content

Commit f44c11e

Browse files
authored
Merge pull request #349 from actions/ncalteen/events
2 parents 77cbbd9 + f598f67 commit f44c11e

6 files changed

Lines changed: 15 additions & 48 deletions

File tree

__tests__/main.test.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ describe('main.ts', () => {
4949
describe('run()', () => {
5050
it('Skips invalid events', async () => {
5151
github.context.eventName = 'push'
52+
github.context.payload = {} as any
5253

5354
await main.run()
5455

@@ -73,17 +74,6 @@ describe('main.ts', () => {
7374
)
7475
})
7576

76-
it('Fails if neither PR nor issue are provided', async () => {
77-
github.context.payload.issue = undefined as any
78-
github.context.payload.pull_request = undefined as any
79-
80-
await main.run()
81-
82-
expect(core.setFailed).toHaveBeenCalledWith(
83-
'Internal Error...No Issue or PR Provided by GitHub'
84-
)
85-
})
86-
8777
it('Fails if both PR and issue are provided', async () => {
8878
github.context.payload.issue = {
8979
number: 20

dist/index.js

Lines changed: 4 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 3 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "first-interaction-action",
33
"description": "An action for greeting first time contributors.",
4-
"version": "3.0.0",
4+
"version": "3.1.0",
55
"author": "GitHub",
66
"type": "module",
77
"private": true,

src/main.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import { Octokit } from '@octokit/rest'
55
export async function run() {
66
core.info('Running actions/first-interaction!')
77

8+
// Check if this is an issue or PR event.
9+
const isIssue = github.context.payload.issue !== undefined
10+
const isPullRequest = github.context.payload.pull_request !== undefined
11+
812
// Skip if this is not an issue or PR event.
9-
if (
10-
github.context.eventName !== 'issues' &&
11-
github.context.eventName !== 'pull_request'
12-
)
13+
if (!isIssue && !isPullRequest)
1314
return core.info('Skipping...Not an Issue/PR Event')
1415

1516
// Skip if this is not an issue/PR open event.
@@ -20,13 +21,7 @@ export async function run() {
2021
if (!github.context.payload.sender)
2122
return core.setFailed('Internal Error...No Sender Provided by GitHub')
2223

23-
// Check if this is an issue or PR event.
24-
const isIssue = github.context.payload.issue !== undefined
25-
const isPullRequest = github.context.payload.pull_request !== undefined
26-
2724
// Confirm that only one of the two is present.
28-
if (!isIssue && !isPullRequest)
29-
return core.setFailed('Internal Error...No Issue or PR Provided by GitHub')
3025
if (isIssue && isPullRequest)
3126
return core.setFailed(
3227
'Internal Error...Both Issue and PR Provided by GitHub'

0 commit comments

Comments
 (0)