Add state

This commit is contained in:
Sergey Dolin
2023-06-22 13:20:34 +02:00
parent 51c18470e1
commit 79fe616082
24 changed files with 7306 additions and 44 deletions

View File

@@ -4,6 +4,7 @@ import {IIssuesProcessorOptions} from '../src/interfaces/issues-processor-option
import {IssuesProcessorMock} from './classes/issues-processor-mock';
import {DefaultProcessorOptions} from './constants/default-processor-options';
import {generateIssue} from './functions/generate-issue';
import {StateMock} from './classes/state-mock';
let issuesProcessorBuilder: IssuesProcessorBuilder;
let issuesProcessor: IssuesProcessorMock;
@@ -1102,6 +1103,7 @@ class IssuesProcessorBuilder {
issue.title ?? 'dummy-title',
issue.updated_at ?? new Date().toDateString(),
issue.created_at ?? new Date().toDateString(),
false,
!!issue.pull_request,
issue.labels ? issue.labels.map(label => label.name || '') : []
)
@@ -1139,6 +1141,7 @@ class IssuesProcessorBuilder {
build(): IssuesProcessorMock {
return new IssuesProcessorMock(
this._options,
new StateMock(),
async p => (p === 1 ? this._issues : []),
async () => [],
async () => new Date().toDateString()

View File

@@ -3,6 +3,7 @@ import {IIssuesProcessorOptions} from '../src/interfaces/issues-processor-option
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';
interface ITestData {
id: number;
@@ -35,6 +36,7 @@ describe('assignees options', (): void => {
'My first issue',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
isPullRequest,
undefined,
undefined,
@@ -48,6 +50,7 @@ describe('assignees options', (): void => {
const setProcessor = () => {
processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? testIssueList : []),
async () => [],
async () => new Date().toDateString()

View File

@@ -3,10 +3,12 @@ import {IssuesProcessor} from '../../src/classes/issues-processor';
import {IComment} from '../../src/interfaces/comment';
import {IIssuesProcessorOptions} from '../../src/interfaces/issues-processor-options';
import {IPullRequest} from '../../src/interfaces/pull-request';
import {IState} from '../../src/interfaces/state';
export class IssuesProcessorMock extends IssuesProcessor {
constructor(
options: IIssuesProcessorOptions,
state: IState,
getIssues?: (page: number) => Promise<Issue[]>,
listIssueComments?: (
issue: Issue,
@@ -18,7 +20,7 @@ export class IssuesProcessorMock extends IssuesProcessor {
) => Promise<string | undefined>,
getPullRequest?: (issue: Issue) => Promise<IPullRequest | undefined | void>
) {
super(options);
super(options, state);
if (getIssues) {
this.getIssues = getIssues;

View File

@@ -0,0 +1,24 @@
import {IState} from '../../src/interfaces/state';
import {IIssue} from '../../src/interfaces/issue';
export class StateMock implements IState {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
addIssueToProcessed(issue: IIssue) {}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
isIssueProcessed(issue: IIssue) {
return false;
}
persist(): Promise<void> {
return Promise.resolve(undefined);
}
rehydrate(): Promise<void> {
return Promise.resolve(undefined);
}
reset() {}
}
export const alwaysFalseStateMock = new StateMock();

View File

@@ -5,6 +5,7 @@ import {IPullRequest} from '../src/interfaces/pull-request';
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';
let issuesProcessorBuilder: IssuesProcessorBuilder;
let issuesProcessor: IssuesProcessorMock;
@@ -45,6 +46,7 @@ describe('exempt-draft-pr option', (): void => {
issuesProcessor = issuesProcessorBuilder
.toStalePrs([
{
draft: true,
number: 20
}
])
@@ -84,6 +86,7 @@ class IssuesProcessorBuilder {
issue.title ?? 'dummy-title',
issue.updated_at ?? new Date().toDateString(),
issue.created_at ?? new Date().toDateString(),
!!issue.draft,
!!issue.pull_request,
issue.labels ? issue.labels.map(label => label.name || '') : []
)
@@ -122,6 +125,7 @@ class IssuesProcessorBuilder {
build(): IssuesProcessorMock {
return new IssuesProcessorMock(
this._options,
alwaysFalseStateMock,
async p => (p === 1 ? this._issues : []),
async () => [],
async () => new Date().toDateString(),

View File

@@ -9,6 +9,7 @@ export function generateIIssue(
labels: [],
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
draft: false,
number: Math.round(Math.random() * 5000),
pull_request: null,
title: 'dummy-title',

View File

@@ -9,6 +9,7 @@ export function generateIssue(
title: string,
updatedAt: IsoDateString,
createdAt: IsoDateString = updatedAt,
draft = false,
isPullRequest = false,
labels: string[] = [],
isClosed = false,
@@ -24,6 +25,7 @@ export function generateIssue(
title,
created_at: createdAt,
updated_at: updatedAt,
draft: draft,
pull_request: isPullRequest ? {} : null,
state: isClosed ? 'closed' : 'open',
locked: isLocked,

View File

@@ -5,6 +5,7 @@ import {IIssuesProcessorOptions} from '../src/interfaces/issues-processor-option
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';
test('processing an issue with no label will make it stale and close it, if it is old enough only if days-before-close is set to 0', async () => {
const opts: IIssuesProcessorOptions = {
@@ -16,6 +17,7 @@ test('processing an issue with no label will make it stale and close it, if it i
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -47,6 +49,7 @@ test('processing an issue with no label and a start date as ECMAScript epoch in
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -78,6 +81,7 @@ test('processing an issue with no label and a start date as ECMAScript epoch in
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -109,6 +113,7 @@ test('processing an issue with no label and a start date as ECMAScript epoch in
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -140,6 +145,7 @@ test('processing an issue with no label and a start date as ECMAScript epoch in
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -171,6 +177,7 @@ test('processing an issue with no label and a start date as ISO 8601 being befor
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -202,6 +209,7 @@ test('processing an issue with no label and a start date as ISO 8601 being after
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -233,6 +241,7 @@ test('processing an issue with no label and a start date as RFC 2822 being befor
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -264,6 +273,7 @@ test('processing an issue with no label and a start date as RFC 2822 being after
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -287,6 +297,7 @@ test('processing an issue with no label will make it stale and close it, if it i
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -311,6 +322,7 @@ test('processing an issue with no label will make it stale and not close it, if
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -333,6 +345,7 @@ test('processing an issue with no label will make it stale and not close it if d
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -356,6 +369,7 @@ test('processing an issue with no label will make it stale and not close it if d
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -379,6 +393,7 @@ test('processing an issue with no label will not make it stale if days-before-st
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -403,6 +418,7 @@ test('processing an issue with no label will not make it stale if days-before-st
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -430,6 +446,7 @@ test('processing an issue with no label will make it stale but not close it', as
];
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -455,11 +472,13 @@ test('processing a stale issue will close it', async () => {
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
['Stale']
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -485,11 +504,13 @@ test('processing a stale issue containing a space in the label will close it', a
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
['state: stale']
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -515,11 +536,13 @@ test('processing a stale issue containing a slash in the label will close it', a
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
['lifecycle/stale']
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -546,11 +569,13 @@ test('processing a stale issue will close it when days-before-issue-stale overri
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
['Stale']
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -575,12 +600,14 @@ test('processing a stale PR will close it', async () => {
'A stale PR that should be closed',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
true,
['Stale']
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -606,12 +633,14 @@ test('processing a stale PR will close it when days-before-pr-stale override day
'A stale PR that should be closed',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
true,
['Stale']
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -638,11 +667,13 @@ test('processing a stale issue will close it even if configured not to mark as s
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
['Stale']
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -670,11 +701,13 @@ test('processing a stale issue will close it even if configured not to mark as s
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
['Stale']
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -700,12 +733,14 @@ test('processing a stale PR will close it even if configured not to mark as stal
'An issue with no label',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
true,
['Stale']
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -732,12 +767,14 @@ test('processing a stale PR will close it even if configured not to mark as stal
'An issue with no label',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
true,
['Stale']
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -759,12 +796,14 @@ test('closed issues will not be marked stale', async () => {
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
[],
true
)
];
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => []
);
@@ -785,12 +824,14 @@ test('stale closed issues will not be closed', async () => {
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
['Stale'],
true
)
];
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -811,6 +852,7 @@ test('closed prs will not be marked stale', async () => {
'A closed PR that will not be marked',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
true,
[],
true
@@ -818,6 +860,7 @@ test('closed prs will not be marked stale', async () => {
];
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -838,6 +881,7 @@ test('stale closed prs will not be closed', async () => {
'A stale closed PR that will not be closed again',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
true,
['Stale'],
true
@@ -845,6 +889,7 @@ test('stale closed prs will not be closed', async () => {
];
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -866,13 +911,16 @@ test('locked issues will not be marked stale', async () => {
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
[],
false,
true
)
];
const processor = new IssuesProcessorMock(DefaultProcessorOptions, async p =>
p === 1 ? TestIssueList : []
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : [])
);
// process our fake issue list
@@ -891,6 +939,7 @@ test('stale locked issues will not be closed', async () => {
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
['Stale'],
false,
true
@@ -898,6 +947,7 @@ test('stale locked issues will not be closed', async () => {
];
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -918,14 +968,17 @@ test('locked prs will not be marked stale', async () => {
'A locked PR that will not be marked stale',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
true,
[],
false,
true
)
];
const processor = new IssuesProcessorMock(DefaultProcessorOptions, async p =>
p === 1 ? TestIssueList : []
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : [])
);
// process our fake issue list
@@ -943,6 +996,7 @@ test('stale locked prs will not be closed', async () => {
'A stale locked PR that will not be closed',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
true,
['Stale'],
false,
@@ -951,6 +1005,7 @@ test('stale locked prs will not be closed', async () => {
];
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -975,11 +1030,13 @@ test('exempt issue labels will not be marked stale', async () => {
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
['Exempt']
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1004,11 +1061,13 @@ test('exempt issue labels will not be marked stale (multi issue label with space
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
['Cool']
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1032,11 +1091,13 @@ test('exempt issue labels will not be marked stale (multi issue label)', async (
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
['Cool']
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1061,6 +1122,7 @@ test('exempt pr labels will not be marked stale', async () => {
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
['Cool']
),
generateIssue(
@@ -1069,6 +1131,7 @@ test('exempt pr labels will not be marked stale', async () => {
'My first PR',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
true,
['Cool']
),
@@ -1078,11 +1141,13 @@ test('exempt pr labels will not be marked stale', async () => {
'Another issue',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1105,6 +1170,7 @@ test('stale issues should not be closed if days is set to -1', async () => {
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
['Stale']
),
generateIssue(
@@ -1113,6 +1179,7 @@ test('stale issues should not be closed if days is set to -1', async () => {
'My first PR',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
true,
['Stale']
),
@@ -1123,11 +1190,13 @@ test('stale issues should not be closed if days is set to -1', async () => {
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
['Stale']
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1150,11 +1219,13 @@ test('stale label should be removed if a comment was added to a stale issue', as
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
['Stale']
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [
{
@@ -1191,11 +1262,13 @@ test('when the option "labelsToAddWhenUnstale" is set, the labels should be adde
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
['Stale']
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [
{
@@ -1235,11 +1308,13 @@ test('when the option "labelsToRemoveWhenStale" is set, the labels should be rem
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
['Stale', 'test']
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [
{
@@ -1273,11 +1348,13 @@ test('stale label should not be removed if a comment was added by the bot (and t
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
['Stale']
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [
{
@@ -1313,11 +1390,13 @@ test('stale label containing a space should be removed if a comment was added to
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
['stat: stale']
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [{user: {login: 'notme', type: 'User'}, body: 'Body'}], // return a fake comment to indicate there was an update
async () => new Date().toDateString()
@@ -1349,6 +1428,7 @@ test('stale issues should not be closed until after the closed number of days',
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1376,11 +1456,13 @@ test('stale issues should be closed if the closed nubmer of days (additive) is a
lastUpdate.toString(),
lastUpdate.toString(),
false,
false,
['Stale']
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1412,6 +1494,7 @@ test('stale issues should not be closed until after the closed number of days (l
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1444,6 +1527,7 @@ test('skips stale message on issues when stale-issue-message is empty', async ()
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1488,6 +1572,7 @@ test('send stale message on issues when stale-issue-message is not empty', async
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1527,11 +1612,13 @@ test('skips stale message on prs when stale-pr-message is empty', async () => {
'An issue that should be marked stale but not closed',
lastUpdate.toString(),
lastUpdate.toString(),
false,
true
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1571,11 +1658,13 @@ test('send stale message on prs when stale-pr-message is not empty', async () =>
'An issue that should be marked stale but not closed',
lastUpdate.toString(),
lastUpdate.toString(),
false,
true
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1611,12 +1700,14 @@ test('git branch is deleted when option is enabled', async () => {
'An issue that should have its branch deleted',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
isPullRequest,
['Stale']
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1640,12 +1731,14 @@ test('git branch is not deleted when issue is not pull request', async () => {
'An issue that should not have its branch deleted',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
isPullRequest,
['Stale']
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1669,6 +1762,7 @@ test('an issue without a milestone will be marked as stale', async () => {
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
undefined,
undefined,
undefined,
@@ -1677,6 +1771,7 @@ test('an issue without a milestone will be marked as stale', async () => {
];
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1702,6 +1797,7 @@ test('an issue without an exempted milestone will be marked as stale', async ()
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
undefined,
undefined,
undefined,
@@ -1710,6 +1806,7 @@ test('an issue without an exempted milestone will be marked as stale', async ()
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1735,6 +1832,7 @@ test('an issue with an exempted milestone will not be marked as stale', async ()
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
undefined,
undefined,
undefined,
@@ -1743,6 +1841,7 @@ test('an issue with an exempted milestone will not be marked as stale', async ()
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1768,6 +1867,7 @@ test('an issue with an exempted milestone will not be marked as stale (multi mil
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
undefined,
undefined,
undefined,
@@ -1776,6 +1876,7 @@ test('an issue with an exempted milestone will not be marked as stale (multi mil
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1801,6 +1902,7 @@ test('an issue with an exempted milestone will not be marked as stale (multi mil
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
undefined,
undefined,
undefined,
@@ -1809,6 +1911,7 @@ test('an issue with an exempted milestone will not be marked as stale (multi mil
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1835,6 +1938,7 @@ test('an issue with an exempted milestone but without an exempted issue mileston
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
undefined,
undefined,
undefined,
@@ -1843,6 +1947,7 @@ test('an issue with an exempted milestone but without an exempted issue mileston
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1869,6 +1974,7 @@ test('an issue with an exempted milestone but with another exempted issue milest
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
undefined,
undefined,
undefined,
@@ -1877,6 +1983,7 @@ test('an issue with an exempted milestone but with another exempted issue milest
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1903,6 +2010,7 @@ test('an issue with an exempted milestone and with an exempted issue milestone w
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
false,
undefined,
undefined,
undefined,
@@ -1911,6 +2019,7 @@ test('an issue with an exempted milestone and with an exempted issue milestone w
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1938,6 +2047,7 @@ test('processing an issue opened since 2 days and with the option "daysBeforeIss
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1964,6 +2074,7 @@ test('processing an issue opened since 2 days and with the option "daysBeforeIss
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1990,6 +2101,7 @@ test('processing an issue opened since 2 days and with the option "daysBeforeIss
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -2016,6 +2128,7 @@ test('processing an issue opened since 1 hour and with the option "daysBeforeIss
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toISOString()
@@ -2042,6 +2155,7 @@ test('processing an issue opened since 4 hours and with the option "daysBeforeIs
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toISOString()
@@ -2068,6 +2182,7 @@ test('processing an issue opened since 5 hours and with the option "daysBeforeIs
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toISOString()
@@ -2096,11 +2211,13 @@ test('processing a pull request opened since 2 days and with the option "daysBef
'A pull request with no label',
issueDate.toDateString(),
issueDate.toDateString(),
false,
true
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -2129,11 +2246,13 @@ test('processing a pull request opened since 2 days and with the option "daysBef
'A pull request with no label',
issueDate.toDateString(),
issueDate.toDateString(),
false,
true
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -2162,11 +2281,13 @@ test('processing a pull request opened since 2 days and with the option "daysBef
'A pull request with no label',
issueDate.toDateString(),
issueDate.toDateString(),
false,
true
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -2195,11 +2316,13 @@ test('processing a pull request opened since 1 hour and with the option "daysBef
'A pull request with no label',
issueDate.toISOString(),
issueDate.toISOString(),
false,
true
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toISOString()
@@ -2228,11 +2351,13 @@ test('processing a pull request opened since 4 hours and with the option "daysBe
'A pull request with no label',
issueDate.toISOString(),
issueDate.toISOString(),
false,
true
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toISOString()
@@ -2261,11 +2386,13 @@ test('processing a pull request opened since 5 hours and with the option "daysBe
'A pull request with no label',
issueDate.toISOString(),
issueDate.toISOString(),
false,
true
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toISOString()
@@ -2295,6 +2422,7 @@ test('processing a previously closed issue with a close label will remove the cl
oneWeekAgo.toDateString(),
now.toDateString(),
false,
false,
['close'],
false,
false
@@ -2302,6 +2430,7 @@ test('processing a previously closed issue with a close label will remove the cl
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -2330,6 +2459,7 @@ test('processing a closed issue with a close label will not remove the close lab
oneWeekAgo.toDateString(),
now.toDateString(),
false,
false,
['close'],
true,
false
@@ -2337,6 +2467,7 @@ test('processing a closed issue with a close label will not remove the close lab
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -2365,6 +2496,7 @@ test('processing a locked issue with a close label will not remove the close lab
oneWeekAgo.toDateString(),
now.toDateString(),
false,
false,
['close'],
false,
true
@@ -2372,6 +2504,7 @@ test('processing a locked issue with a close label will not remove the close lab
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -2404,6 +2537,7 @@ test('processing an issue stale since less than the daysBeforeStale with a stale
updatedAt.toDateString(),
new Date(2021, 0, 16).toDateString(),
false,
false,
['stale-label'], // This was the problem for the user BTW, the issue was re-opened without removing the previous stale label
false,
false
@@ -2411,6 +2545,7 @@ test('processing an issue stale since less than the daysBeforeStale with a stale
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async (): Promise<IComment[]> => Promise.resolve([]),
async () => labelCreatedAt.toDateString()
@@ -2444,6 +2579,7 @@ test('processing an issue stale since less than the daysBeforeStale without a st
updatedAt.toDateString(),
new Date(2021, 0, 16).toDateString(),
false,
false,
[],
false,
false
@@ -2451,6 +2587,7 @@ test('processing an issue stale since less than the daysBeforeStale without a st
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async (): Promise<IComment[]> => Promise.resolve([]),
async () => new Date().toDateString()
@@ -2481,11 +2618,13 @@ test('processing a pull request to be stale with the "stalePrMessage" option set
'A pull request with no label and a stale message',
issueDate.toDateString(),
issueDate.toDateString(),
false,
true
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -2516,11 +2655,13 @@ test('processing a pull request to be stale with the "stalePrMessage" option set
'A pull request with no label and a stale message',
issueDate.toDateString(),
issueDate.toDateString(),
false,
true
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -2552,6 +2693,7 @@ test('processing an issue with the "includeOnlyAssigned" option and nonempty ass
issueDate.toDateString(),
issueDate.toDateString(),
false,
false,
[],
false,
false,
@@ -2561,6 +2703,7 @@ test('processing an issue with the "includeOnlyAssigned" option and nonempty ass
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -2588,6 +2731,7 @@ test('processing an issue with the "includeOnlyAssigned" option set and no assig
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()

View File

@@ -3,6 +3,7 @@ import {IIssuesProcessorOptions} from '../src/interfaces/issues-processor-option
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';
interface ITestData {
isPullRequest: boolean;
@@ -27,6 +28,7 @@ describe('milestones options', (): void => {
'My first issue',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
isPullRequest,
undefined,
undefined,
@@ -39,6 +41,7 @@ describe('milestones options', (): void => {
const setProcessor = () => {
processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? testIssueList : []),
async () => [],
async () => new Date().toDateString()

View File

@@ -4,6 +4,7 @@ import {IIssuesProcessorOptions} from '../src/interfaces/issues-processor-option
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';
let issuesProcessorBuilder: IssuesProcessorBuilder;
let issuesProcessor: IssuesProcessorMock;
@@ -1102,6 +1103,7 @@ class IssuesProcessorBuilder {
issue.title ?? 'dummy-title',
issue.updated_at ?? new Date().toDateString(),
issue.created_at ?? new Date().toDateString(),
false,
!!issue.pull_request,
issue.labels ? issue.labels.map(label => label.name || '') : []
)
@@ -1139,6 +1141,7 @@ class IssuesProcessorBuilder {
build(): IssuesProcessorMock {
return new IssuesProcessorMock(
this._options,
alwaysFalseStateMock,
async p => (p === 1 ? this._issues : []),
async () => [],
async () => new Date().toDateString()

View File

@@ -4,6 +4,7 @@ import {IsoDateString} from '../src/types/iso-date-string';
import {IssuesProcessorMock} from './classes/issues-processor-mock';
import {DefaultProcessorOptions} from './constants/default-processor-options';
import {generateIssue} from './functions/generate-issue';
import {alwaysFalseStateMock, StateMock} from './classes/state-mock';
describe('operations-per-run option', (): void => {
let sut: SUT;
@@ -205,6 +206,7 @@ class SUT {
private async _setProcessor(): Promise<number> {
this.processor = new IssuesProcessorMock(
this._opts,
alwaysFalseStateMock,
async p => (p === 1 ? this._testIssueList : []),
async () => [],
async () => new Date().toDateString()

View File

@@ -5,6 +5,7 @@ import {ILabel} from '../src/interfaces/label';
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';
let issuesProcessorBuilder: IssuesProcessorBuilder;
let issuesProcessor: IssuesProcessorMock;
@@ -141,7 +142,9 @@ describe('remove-issue-stale-when-updated option', (): void => {
test('should not remove the stale label on the pull request', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build();
issuesProcessor = issuesProcessorBuilder
.stalePrs([{draft: true}])
.build();
await issuesProcessor.processIssues();
@@ -454,6 +457,7 @@ class IssuesProcessorBuilder {
issue.title ?? 'dummy-title',
issue.updated_at ?? new Date().toDateString(),
issue.created_at ?? new Date().toDateString(),
!!issue.draft,
!!issue.pull_request,
issue.labels ? issue.labels.map(label => label.name || '') : []
)
@@ -515,7 +519,7 @@ class IssuesProcessorBuilder {
stalePrs(issues: Partial<IIssue>[]): IssuesProcessorBuilder {
this.prs(
issues.map((issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
const o = {
...issue,
updated_at: '2020-01-01T17:00:00Z',
created_at: '2020-01-01T17:00:00Z',
@@ -530,6 +534,7 @@ class IssuesProcessorBuilder {
}
]
};
return o;
})
);
@@ -539,6 +544,7 @@ class IssuesProcessorBuilder {
build(): IssuesProcessorMock {
return new IssuesProcessorMock(
this._options,
alwaysFalseStateMock,
async p => (p === 1 ? this._issues : []),
async () => [
{

View File

@@ -4,6 +4,7 @@ import {IsoDateString} from '../src/types/iso-date-string';
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';
describe('ignore-updates options', (): void => {
let sut: SUT;
@@ -676,6 +677,7 @@ class SUT {
'My first issue',
this._updatedAt,
this._createdAt,
false,
this._isPullRequest
)
];
@@ -686,6 +688,7 @@ class SUT {
private async _setProcessor(): Promise<number> {
this.processor = new IssuesProcessorMock(
this._opts,
alwaysFalseStateMock,
async p => (p === 1 ? this._testIssueList : []),
async () => [],
async () => new Date().toDateString()