Expand supported event types

This commit is contained in:
Nick Alteen
2025-09-09 14:45:57 -04:00
parent 77cbbd906f
commit 060edb2b27
4 changed files with 10 additions and 40 deletions

View File

@@ -49,6 +49,7 @@ describe('main.ts', () => {
describe('run()', () => {
it('Skips invalid events', async () => {
github.context.eventName = 'push'
github.context.payload = {} as any
await main.run()
@@ -73,17 +74,6 @@ describe('main.ts', () => {
)
})
it('Fails if neither PR nor issue are provided', async () => {
github.context.payload.issue = undefined as any
github.context.payload.pull_request = undefined as any
await main.run()
expect(core.setFailed).toHaveBeenCalledWith(
'Internal Error...No Issue or PR Provided by GitHub'
)
})
it('Fails if both PR and issue are provided', async () => {
github.context.payload.issue = {
number: 20

21
package-lock.json generated
View File

@@ -1,18 +1,17 @@
{
"name": "first-interaction-action",
"version": "3.0.0",
"version": "3.1.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "first-interaction-action",
"version": "3.0.0",
"version": "3.1.0",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.11.1",
"@actions/github": "^6.0.1",
"@octokit/rest": "^22.0.0",
"@rollup/rollup-linux-x64-gnu": "*"
"@octokit/rest": "^22.0.0"
},
"devDependencies": {
"@eslint/compat": "^1.3.2",
@@ -13902,20 +13901,6 @@
"fsevents": "~2.3.2"
}
},
"node_modules/rollup/node_modules/@rollup/rollup-linux-x64-gnu": {
"version": "4.48.1",
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.48.1.tgz",
"integrity": "sha512-90taWXCWxTbClWuMZD0DKYohY1EovA+W5iytpE89oUPmT5O1HFdf8cuuVIylE6vCbrGdIGv85lVRzTcpTRZ+kA==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
]
},
"node_modules/run-parallel": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz",

View File

@@ -1,7 +1,7 @@
{
"name": "first-interaction-action",
"description": "An action for greeting first time contributors.",
"version": "3.0.0",
"version": "3.1.0",
"author": "GitHub",
"type": "module",
"private": true,

View File

@@ -5,11 +5,12 @@ import { Octokit } from '@octokit/rest'
export async function run() {
core.info('Running actions/first-interaction!')
// Check if this is an issue or PR event.
const isIssue = github.context.payload.issue !== undefined
const isPullRequest = github.context.payload.pull_request !== undefined
// Skip if this is not an issue or PR event.
if (
github.context.eventName !== 'issues' &&
github.context.eventName !== 'pull_request'
)
if (!isIssue && !isPullRequest)
return core.info('Skipping...Not an Issue/PR Event')
// Skip if this is not an issue/PR open event.
@@ -20,13 +21,7 @@ export async function run() {
if (!github.context.payload.sender)
return core.setFailed('Internal Error...No Sender Provided by GitHub')
// Check if this is an issue or PR event.
const isIssue = github.context.payload.issue !== undefined
const isPullRequest = github.context.payload.pull_request !== undefined
// Confirm that only one of the two is present.
if (!isIssue && !isPullRequest)
return core.setFailed('Internal Error...No Issue or PR Provided by GitHub')
if (isIssue && isPullRequest)
return core.setFailed(
'Internal Error...Both Issue and PR Provided by GitHub'