Skip to content

Commit

Permalink
Add set labels to console output
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju committed Sep 12, 2024
1 parent 3bbf3a2 commit ed42764
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 0 additions & 2 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
27 changes: 27 additions & 0 deletions src/action.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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}`);

Check warning on line 41 in src/action.ts

View check run for this annotation

Codecov / codecov/patch

src/action.ts#L40-L41

Added lines #L40 - L41 were not covered by tests

let labels: string[] = [];

Check warning on line 43 in src/action.ts

View check run for this annotation

Codecov / codecov/patch

src/action.ts#L43

Added line #L43 was not covered by tests

switch (eventName) {
case 'pull_request':
const payload = github.context.payload as PullRequestOpenedEvent | PullRequestReopenedEvent | PullRequestClosedEvent | PullRequestLabeledEvent | PullRequestUnlabeledEvent | PullRequestEditedEvent;

Check failure on line 47 in src/action.ts

View workflow job for this annotation

GitHub Actions / Relabeler Tests

Unexpected lexical declaration in case block
labels = payload.pull_request.labels.map(label => label.name);

Check warning on line 48 in src/action.ts

View check run for this annotation

Codecov / codecov/patch

src/action.ts#L47-L48

Added lines #L47 - L48 were not covered by tests

break;

Check warning on line 50 in src/action.ts

View check run for this annotation

Codecov / codecov/patch

src/action.ts#L50

Added line #L50 was not covered by tests
// Add other event cases if needed
default:
console.log(`Unhandled event: ${eventName}`);

Check warning on line 53 in src/action.ts

View check run for this annotation

Codecov / codecov/patch

src/action.ts#L53

Added line #L53 was not covered by tests
}

console.log(`Collected labels: ${labels.join(', ')}`);

Check warning on line 56 in src/action.ts

View check run for this annotation

Codecov / codecov/patch

src/action.ts#L56

Added line #L56 was not covered by tests
} catch (error) {
if (error instanceof Error) {
if (!error.message.startsWith('Mock')) {
Expand Down

0 comments on commit ed42764

Please sign in to comment.