From ed42764755c1405baaab8a382ab8cc3f6f085b18 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 10 Sep 2024 18:28:40 +0000 Subject: [PATCH] Add set labels to console output --- package-lock.json | 2 -- package.json | 1 - src/action.ts | 27 +++++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1ea2b27..a0bf8e0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,6 @@ "devDependencies": { "@eslint/create-config": "^1.3.1", "@eslint/js": "^8.55.0", - "@octokit/webhooks-types": "^7.3.1", "@types/axios": "^0.14.0", "@types/jest": "^29.5.11", "@types/js-yaml": "^4.0.5", @@ -1432,7 +1431,6 @@ "version": "7.5.1", "resolved": "https://registry.npmjs.org/@octokit/webhooks-types/-/webhooks-types-7.5.1.tgz", "integrity": "sha512-1dozxWEP8lKGbtEu7HkRbK1F/nIPuJXNfT0gd96y6d3LcHZTtRtlf8xz3nicSJfesADxJyDh+mWBOsdLkqgzYw==", - "dev": true, "license": "MIT" }, "node_modules/@sinclair/typebox": { diff --git a/package.json b/package.json index 5b2bf84..6430a74 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,6 @@ "ts-jest": "^29.1.1", "@types/jest": "^29.5.11", "@types/axios": "^0.14.0", - "@octokit/webhooks-types": "^7.3.1", "eslint": "^8.55.0", "@typescript-eslint/parser": "^6.14.0", "@typescript-eslint/eslint-plugin": "^6.14.0", diff --git a/src/action.ts b/src/action.ts index 46e9b3f..747e78e 100644 --- a/src/action.ts +++ b/src/action.ts @@ -1,6 +1,7 @@ import * as core from '@actions/core'; import * as github from '@actions/github'; import { loadConfig } from './config'; +import { PullRequestOpenedEvent, PullRequestReopenedEvent, PullRequestClosedEvent, PullRequestLabeledEvent, PullRequestUnlabeledEvent, PullRequestEditedEvent } from '@octokit/webhooks-types'; export async function run() { try { @@ -27,6 +28,32 @@ export async function run() { const time = (new Date()).toTimeString(); console.log(`Setting output time: ${time}`); core.setOutput('time', time); + + let eventType: string = ''; + + const eventName = github.context.eventName; + + if ('action' in github.context.payload) { + eventType = github.context.payload.action ?? ''; + } + + console.log(`Event name: ${eventName}`); + console.log(`Event type: ${eventType}`); + + let labels: string[] = []; + + switch (eventName) { + case 'pull_request': + const payload = github.context.payload as PullRequestOpenedEvent | PullRequestReopenedEvent | PullRequestClosedEvent | PullRequestLabeledEvent | PullRequestUnlabeledEvent | PullRequestEditedEvent; + labels = payload.pull_request.labels.map(label => label.name); + + break; + // Add other event cases if needed + default: + console.log(`Unhandled event: ${eventName}`); + } + + console.log(`Collected labels: ${labels.join(', ')}`); } catch (error) { if (error instanceof Error) { if (!error.message.startsWith('Mock')) {