Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 102 additions & 2 deletions __tests__/only-issue-types.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(() => {});

Comment thread
chiranjib-swain marked this conversation as resolved.
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: ''
Expand Down Expand Up @@ -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(
Expand All @@ -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'
]);
});
});
4 changes: 4 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 4 additions & 0 deletions src/classes/issues-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Loading