Skip to content

Commit 2c66ef0

Browse files
fix(get_changed_files): return empty list when not a PR event (#128)
1 parent 72feb47 commit 2c66ef0

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

actions/get_changed_files/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ steps:
3939
- The action uses pagination to retrieve all changed files, so it works correctly for PRs with many files.
4040
- Changed files are returned as a newline-separated string in the `changed_files` output, which safely handles
4141
filenames containing spaces.
42-
- If no `pr_number` is provided and the action is not running in a `pull_request` event context, the action will fail.
42+
- If no `pr_number` is provided and the action is not running in a `pull_request` event context,
43+
an empty string will be returned.

actions/get_changed_files/get_changed_files.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ async function getChangedFilesAction({ github, context, core }) {
3131
const prNumber = process.env.INPUT_PR_NUMBER || context.payload?.pull_request?.number;
3232

3333
if (!prNumber) {
34-
core.setFailed('No pull request number provided. Set the pr_number input or run this action in a pull_request event.');
34+
console.log('Not a pull request event. Returning empty list of changed files.');
35+
core.setOutput('CHANGED_FILES', '');
3536
return;
3637
}
3738

tests/get_changed_files/get_changed_files.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ describe('getChangedFilesAction', () => {
160160
expect(mockCore.setOutput).toHaveBeenCalledWith('CHANGED_FILES', 'changed.js');
161161
});
162162

163-
test('should fail when no PR number is available', async () => {
163+
test('should return empty list when no PR number is available (non-PR event)', async () => {
164164
const mockGithub = createMockGithub();
165165
const mockContext = {
166166
...createMockContext(),
@@ -170,9 +170,9 @@ describe('getChangedFilesAction', () => {
170170

171171
await getChangedFilesAction({ github: mockGithub, context: mockContext, core: mockCore });
172172

173-
expect(mockCore.setFailed).toHaveBeenCalledWith(
174-
expect.stringContaining('No pull request number provided')
175-
);
173+
expect(mockCore.setFailed).not.toHaveBeenCalled();
174+
expect(mockCore.setOutput).toHaveBeenCalledWith('CHANGED_FILES', '');
175+
expect(consoleOutput.some(line => line.includes('Not a pull request event'))).toBe(true);
176176
});
177177

178178
test('should fail when API throws an error', async () => {

0 commit comments

Comments
 (0)