Skip to content

Conversation

github-actions[bot]
Copy link

@github-actions github-actions bot commented Jul 9, 2025

Closes #380

Applied changes based on Issue #380.

I’ve replaced the ad‑hoc JSON.parse in loadEventPayload with a call to core.getInputJson for unified error handling, and updated the unit tests to mock getInputJson so that the existing loadEventPayload tests continue to pass.


Changes in src/github/event.ts

export async function loadEventPayload(
  eventPath: string,
): Promise<Record<string, unknown>> {
  try {
    const content = await fs.readFile(eventPath, 'utf8');
    // Parse JSON using core.getInputJson for consistent error handling
    return core.getInputJson<Record<string, unknown>>(content);
  } catch (error) {
    throw new ParseError(
      `Failed to read or parse event payload at ${eventPath}: ${toErrorMessage(
        error,
      )}`,
    );
  }
}

【F:src/github/event.ts†L60-L68】


Changes in tests/unit/github/event.test.ts

Added a jest mock for @actions/core so that core.getInputJson is stubbed to simply run JSON.parse in the loadEventPayload tests:

import * as core from '@actions/core';
import { loadEventPayload, processEvent } from '../../../src/github/event';

jest.mock('@actions/core', () => ({
  info: jest.fn(),
  getInputJson: jest.fn((input: string) => JSON.parse(input)),
}));

【F:tests/unit/github/event.test.ts†L4-L12】


These are the only changes. All existing tests for loadEventPayload and processEvent should continue to pass and now leverage the standardized JSON‐parsing helper.

@YiweiShen YiweiShen merged commit e6be4b8 into main Jul 9, 2025
3 checks passed
@YiweiShen YiweiShen deleted the codez-chore-380-refactor-event-wrap-json-parsing-in-loadeventpayload-3051228303 branch July 9, 2025 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrap JSON parsing in loadEventPayload

1 participant