diff --git a/__tests__/only-issue-types.spec.ts b/__tests__/only-issue-types.spec.ts index c91d56582..e20322a5a 100644 --- a/__tests__/only-issue-types.spec.ts +++ b/__tests__/only-issue-types.spec.ts @@ -4,8 +4,13 @@ import {IssuesProcessorMock} from './classes/issues-processor-mock'; import {DefaultProcessorOptions} from './constants/default-processor-options'; import {generateIssue} from './functions/generate-issue'; import {alwaysFalseStateMock} from './classes/state-mock'; +import * as core from '@actions/core'; describe('only-issue-types option', () => { + afterEach(() => { + jest.restoreAllMocks(); + }); + test('should only process issues with allowed type', async () => { const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, @@ -71,8 +76,87 @@ describe('only-issue-types option', () => { 'A question' ]); }); + test('should process allowed issue types and skip PRs without logs', async () => { + const infoSpy = jest.spyOn(core, 'info').mockImplementation(() => {}); + const groupSpy = jest + .spyOn(core, 'group') + .mockImplementation(async (_name, fn) => fn()); + const warningSpy = jest.spyOn(core, 'warning').mockImplementation(() => {}); + + const opts: IIssuesProcessorOptions = { + ...DefaultProcessorOptions, + onlyIssueTypes: 'bug' + }; + const TestIssueList: Issue[] = [ + generateIssue( + opts, + 1, + 'A bug issue', + '2020-01-01T17:00:00Z', + '2020-01-01T17:00:00Z', + false, + false, + [], + false, + false, + undefined, + [], + 'bug' + ), + generateIssue( + opts, + 2, + 'A feature issue', + '2020-01-01T17:00:00Z', + '2020-01-01T17:00:00Z', + false, + false, + [], + false, + false, + undefined, + [], + 'feature' + ), + generateIssue( + opts, + 3, + 'A pull request', + '2020-01-01T17:00:00Z', + '2020-01-01T17:00:00Z', + false, + true, + [], + false, + false, + undefined, + [], + 'feature' + ) + ]; + const processor = new IssuesProcessorMock( + opts, + alwaysFalseStateMock, + async p => (p === 1 ? TestIssueList : []), + async () => [], + async () => new Date().toDateString() + ); + await processor.processIssues(1); + + // Only the bug issue is processed + expect(processor.staleIssues.map(i => i.title)).toEqual(['A bug issue']); + + // PR is silently skipped — no logs should mention it across all logging methods + const infoLogs = infoSpy.mock.calls.map(c => c[0]).join('\n'); + const warningLogs = warningSpy.mock.calls.map(c => c[0]).join('\n'); + const groupLogs = groupSpy.mock.calls.map(c => c[0]).join('\n'); + const allLogs = [infoLogs, warningLogs, groupLogs].join('\n'); + + // Case-insensitive regex handles variations and ANSI codes + expect(allLogs).not.toMatch(/pull request/i); + }); - test('should process all issues if onlyIssueTypes is unset', async () => { + test('should process all issues and PRs if onlyIssueTypes is unset', async () => { const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, onlyIssueTypes: '' @@ -107,6 +191,21 @@ describe('only-issue-types option', () => { undefined, [], 'feature' + ), + generateIssue( + opts, + 3, + 'A pull request', + '2020-01-01T17:00:00Z', + '2020-01-01T17:00:00Z', + false, + true, + [], + false, + false, + undefined, + [], + 'feature' ) ]; const processor = new IssuesProcessorMock( @@ -119,7 +218,8 @@ describe('only-issue-types option', () => { await processor.processIssues(1); expect(processor.staleIssues.map(i => i.title)).toEqual([ 'A bug', - 'A feature' + 'A feature', + 'A pull request' ]); }); }); diff --git a/dist/index.js b/dist/index.js index 40ec38401..bf0d45ed5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -452,6 +452,10 @@ class IssuesProcessor { if (!this.operations.hasRemainingOperations()) { break; } + // Skip PRs silently when onlyIssueTypes is set + if (this.options.onlyIssueTypes && issue.isPullRequest) { + continue; + } const issueLogger = new issue_logger_1.IssueLogger(issue); if (this.state.isIssueProcessed(issue)) { issueLogger.info(' $$type skipped due being processed during the previous run'); diff --git a/src/classes/issues-processor.ts b/src/classes/issues-processor.ts index c4e444fdc..177887d5d 100644 --- a/src/classes/issues-processor.ts +++ b/src/classes/issues-processor.ts @@ -148,6 +148,10 @@ export class IssuesProcessor { if (!this.operations.hasRemainingOperations()) { break; } + // Skip PRs silently when onlyIssueTypes is set + if (this.options.onlyIssueTypes && issue.isPullRequest) { + continue; + } const issueLogger: IssueLogger = new IssueLogger(issue); if (this.state.isIssueProcessed(issue)) {