From f50d795af9d505f4de7ee55f259c5e4335a266b2 Mon Sep 17 00:00:00 2001 From: chiranjib-swain Date: Wed, 6 May 2026 16:17:10 +0530 Subject: [PATCH 1/3] Enhancement: skip processing of pull requests when onlyIssueTypes is set --- __tests__/only-issue-types.spec.ts | 102 ++++++++++++++++++++++++++++- dist/index.js | 4 ++ src/classes/issues-processor.ts | 4 ++ 3 files changed, 108 insertions(+), 2 deletions(-) diff --git a/__tests__/only-issue-types.spec.ts b/__tests__/only-issue-types.spec.ts index c91d56582..c08779018 100644 --- a/__tests__/only-issue-types.spec.ts +++ b/__tests__/only-issue-types.spec.ts @@ -4,6 +4,7 @@ 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', () => { test('should only process issues with allowed type', async () => { @@ -71,8 +72,89 @@ 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'); + const groupSpy = jest.spyOn(core, 'group'); + const warningSpy = jest.spyOn(core, 'warning'); - test('should process all issues if onlyIssueTypes is unset', async () => { + 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); + + infoSpy.mockRestore(); + groupSpy.mockRestore(); + warningSpy.mockRestore(); + }); + + test('should process all issues and PRs if onlyIssueTypes is unset', async () => { const opts: IIssuesProcessorOptions = { ...DefaultProcessorOptions, onlyIssueTypes: '' @@ -107,6 +189,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 +216,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)) { From 274ed4bf5a8c63a1e581f0924f61fa0a5857e94b Mon Sep 17 00:00:00 2001 From: chiranjib-swain Date: Thu, 7 May 2026 10:37:29 +0530 Subject: [PATCH 2/3] Enhancement: refactor tests to restore mocks after each test case --- __tests__/only-issue-types.spec.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/__tests__/only-issue-types.spec.ts b/__tests__/only-issue-types.spec.ts index c08779018..8d857a61f 100644 --- a/__tests__/only-issue-types.spec.ts +++ b/__tests__/only-issue-types.spec.ts @@ -7,6 +7,10 @@ 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, @@ -148,10 +152,6 @@ describe('only-issue-types option', () => { // Case-insensitive regex handles variations and ANSI codes expect(allLogs).not.toMatch(/pull request/i); - - infoSpy.mockRestore(); - groupSpy.mockRestore(); - warningSpy.mockRestore(); }); test('should process all issues and PRs if onlyIssueTypes is unset', async () => { From 6e4e3266aa5e350fea007edc780d482925c2a0e0 Mon Sep 17 00:00:00 2001 From: chiranjib-swain Date: Thu, 7 May 2026 10:54:32 +0530 Subject: [PATCH 3/3] Enhancement: mock core logging methods in only-issue-types tests Co-authored-by: Copilot --- __tests__/only-issue-types.spec.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/__tests__/only-issue-types.spec.ts b/__tests__/only-issue-types.spec.ts index 8d857a61f..e20322a5a 100644 --- a/__tests__/only-issue-types.spec.ts +++ b/__tests__/only-issue-types.spec.ts @@ -77,9 +77,11 @@ describe('only-issue-types option', () => { ]); }); test('should process allowed issue types and skip PRs without logs', async () => { - const infoSpy = jest.spyOn(core, 'info'); - const groupSpy = jest.spyOn(core, 'group'); - const warningSpy = jest.spyOn(core, 'warning'); + 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,