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 {IssuesProcessorMock} from './classes/issues-processor-mock';
import {DefaultProcessorOptions} from './constants/default-processor-options'; import {DefaultProcessorOptions} from './constants/default-processor-options';
import {generateIssue} from './functions/generate-issue'; import {generateIssue} from './functions/generate-issue';
import {StateMock} from './classes/state-mock';
let issuesProcessorBuilder: IssuesProcessorBuilder; let issuesProcessorBuilder: IssuesProcessorBuilder;
let issuesProcessor: IssuesProcessorMock; let issuesProcessor: IssuesProcessorMock;
@ -1102,6 +1103,7 @@ class IssuesProcessorBuilder {
issue.title ?? 'dummy-title', issue.title ?? 'dummy-title',
issue.updated_at ?? new Date().toDateString(), issue.updated_at ?? new Date().toDateString(),
issue.created_at ?? new Date().toDateString(), issue.created_at ?? new Date().toDateString(),
false,
!!issue.pull_request, !!issue.pull_request,
issue.labels ? issue.labels.map(label => label.name || '') : [] issue.labels ? issue.labels.map(label => label.name || '') : []
) )
@ -1139,6 +1141,7 @@ class IssuesProcessorBuilder {
build(): IssuesProcessorMock { build(): IssuesProcessorMock {
return new IssuesProcessorMock( return new IssuesProcessorMock(
this._options, this._options,
new StateMock(),
async p => (p === 1 ? this._issues : []), async p => (p === 1 ? this._issues : []),
async () => [], async () => [],
async () => new Date().toDateString() 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 {IssuesProcessorMock} from './classes/issues-processor-mock';
import {DefaultProcessorOptions} from './constants/default-processor-options'; import {DefaultProcessorOptions} from './constants/default-processor-options';
import {generateIssue} from './functions/generate-issue'; import {generateIssue} from './functions/generate-issue';
import {alwaysFalseStateMock} from './classes/state-mock';
interface ITestData { interface ITestData {
id: number; id: number;
@ -35,6 +36,7 @@ describe('assignees options', (): void => {
'My first issue', 'My first issue',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false,
isPullRequest, isPullRequest,
undefined, undefined,
undefined, undefined,
@ -48,6 +50,7 @@ describe('assignees options', (): void => {
const setProcessor = () => { const setProcessor = () => {
processor = new IssuesProcessorMock( processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? testIssueList : []), async p => (p === 1 ? testIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() async () => new Date().toDateString()

View File

@ -3,10 +3,12 @@ import {IssuesProcessor} from '../../src/classes/issues-processor';
import {IComment} from '../../src/interfaces/comment'; import {IComment} from '../../src/interfaces/comment';
import {IIssuesProcessorOptions} from '../../src/interfaces/issues-processor-options'; import {IIssuesProcessorOptions} from '../../src/interfaces/issues-processor-options';
import {IPullRequest} from '../../src/interfaces/pull-request'; import {IPullRequest} from '../../src/interfaces/pull-request';
import {IState} from '../../src/interfaces/state';
export class IssuesProcessorMock extends IssuesProcessor { export class IssuesProcessorMock extends IssuesProcessor {
constructor( constructor(
options: IIssuesProcessorOptions, options: IIssuesProcessorOptions,
state: IState,
getIssues?: (page: number) => Promise<Issue[]>, getIssues?: (page: number) => Promise<Issue[]>,
listIssueComments?: ( listIssueComments?: (
issue: Issue, issue: Issue,
@ -18,7 +20,7 @@ export class IssuesProcessorMock extends IssuesProcessor {
) => Promise<string | undefined>, ) => Promise<string | undefined>,
getPullRequest?: (issue: Issue) => Promise<IPullRequest | undefined | void> getPullRequest?: (issue: Issue) => Promise<IPullRequest | undefined | void>
) { ) {
super(options); super(options, state);
if (getIssues) { if (getIssues) {
this.getIssues = 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 {IssuesProcessorMock} from './classes/issues-processor-mock';
import {DefaultProcessorOptions} from './constants/default-processor-options'; import {DefaultProcessorOptions} from './constants/default-processor-options';
import {generateIssue} from './functions/generate-issue'; import {generateIssue} from './functions/generate-issue';
import {alwaysFalseStateMock} from './classes/state-mock';
let issuesProcessorBuilder: IssuesProcessorBuilder; let issuesProcessorBuilder: IssuesProcessorBuilder;
let issuesProcessor: IssuesProcessorMock; let issuesProcessor: IssuesProcessorMock;
@ -45,6 +46,7 @@ describe('exempt-draft-pr option', (): void => {
issuesProcessor = issuesProcessorBuilder issuesProcessor = issuesProcessorBuilder
.toStalePrs([ .toStalePrs([
{ {
draft: true,
number: 20 number: 20
} }
]) ])
@ -84,6 +86,7 @@ class IssuesProcessorBuilder {
issue.title ?? 'dummy-title', issue.title ?? 'dummy-title',
issue.updated_at ?? new Date().toDateString(), issue.updated_at ?? new Date().toDateString(),
issue.created_at ?? new Date().toDateString(), issue.created_at ?? new Date().toDateString(),
!!issue.draft,
!!issue.pull_request, !!issue.pull_request,
issue.labels ? issue.labels.map(label => label.name || '') : [] issue.labels ? issue.labels.map(label => label.name || '') : []
) )
@ -122,6 +125,7 @@ class IssuesProcessorBuilder {
build(): IssuesProcessorMock { build(): IssuesProcessorMock {
return new IssuesProcessorMock( return new IssuesProcessorMock(
this._options, this._options,
alwaysFalseStateMock,
async p => (p === 1 ? this._issues : []), async p => (p === 1 ? this._issues : []),
async () => [], async () => [],
async () => new Date().toDateString(), async () => new Date().toDateString(),

View File

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

View File

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

View File

@ -5,6 +5,7 @@ import {IIssuesProcessorOptions} from '../src/interfaces/issues-processor-option
import {IssuesProcessorMock} from './classes/issues-processor-mock'; import {IssuesProcessorMock} from './classes/issues-processor-mock';
import {DefaultProcessorOptions} from './constants/default-processor-options'; import {DefaultProcessorOptions} from './constants/default-processor-options';
import {generateIssue} from './functions/generate-issue'; 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 () => { 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 = { 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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( const processor = new IssuesProcessorMock(
DefaultProcessorOptions, DefaultProcessorOptions,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
['Stale'] ['Stale']
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
['state: stale'] ['state: stale']
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
['lifecycle/stale'] ['lifecycle/stale']
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
['Stale'] ['Stale']
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() async () => new Date().toDateString()
@ -575,12 +600,14 @@ test('processing a stale PR will close it', async () => {
'A stale PR that should be closed', 'A stale PR that should be closed',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false,
true, true,
['Stale'] ['Stale']
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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', 'A stale PR that should be closed',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false,
true, true,
['Stale'] ['Stale']
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
['Stale'] ['Stale']
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
['Stale'] ['Stale']
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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', 'An issue with no label',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false,
true, true,
['Stale'] ['Stale']
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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', 'An issue with no label',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false,
true, true,
['Stale'] ['Stale']
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
[], [],
true true
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
DefaultProcessorOptions, DefaultProcessorOptions,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [] async () => []
); );
@ -785,12 +824,14 @@ test('stale closed issues will not be closed', async () => {
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
['Stale'], ['Stale'],
true true
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
DefaultProcessorOptions, DefaultProcessorOptions,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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', 'A closed PR that will not be marked',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false,
true, true,
[], [],
true true
@ -818,6 +860,7 @@ test('closed prs will not be marked stale', async () => {
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
DefaultProcessorOptions, DefaultProcessorOptions,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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', 'A stale closed PR that will not be closed again',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false,
true, true,
['Stale'], ['Stale'],
true true
@ -845,6 +889,7 @@ test('stale closed prs will not be closed', async () => {
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
DefaultProcessorOptions, DefaultProcessorOptions,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
[], [],
false, false,
true true
) )
]; ];
const processor = new IssuesProcessorMock(DefaultProcessorOptions, async p => const processor = new IssuesProcessorMock(
p === 1 ? TestIssueList : [] DefaultProcessorOptions,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : [])
); );
// process our fake issue list // 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
['Stale'], ['Stale'],
false, false,
true true
@ -898,6 +947,7 @@ test('stale locked issues will not be closed', async () => {
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
DefaultProcessorOptions, DefaultProcessorOptions,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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', 'A locked PR that will not be marked stale',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false,
true, true,
[], [],
false, false,
true true
) )
]; ];
const processor = new IssuesProcessorMock(DefaultProcessorOptions, async p => const processor = new IssuesProcessorMock(
p === 1 ? TestIssueList : [] DefaultProcessorOptions,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : [])
); );
// process our fake issue list // 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', 'A stale locked PR that will not be closed',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false,
true, true,
['Stale'], ['Stale'],
false, false,
@ -951,6 +1005,7 @@ test('stale locked prs will not be closed', async () => {
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
DefaultProcessorOptions, DefaultProcessorOptions,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
['Exempt'] ['Exempt']
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
['Cool'] ['Cool']
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
['Cool'] ['Cool']
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
['Cool'] ['Cool']
), ),
generateIssue( generateIssue(
@ -1069,6 +1131,7 @@ test('exempt pr labels will not be marked stale', async () => {
'My first PR', 'My first PR',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false,
true, true,
['Cool'] ['Cool']
), ),
@ -1078,11 +1141,13 @@ test('exempt pr labels will not be marked stale', async () => {
'Another issue', 'Another issue',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false,
false false
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
['Stale'] ['Stale']
), ),
generateIssue( generateIssue(
@ -1113,6 +1179,7 @@ test('stale issues should not be closed if days is set to -1', async () => {
'My first PR', 'My first PR',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false,
true, true,
['Stale'] ['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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
['Stale'] ['Stale']
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
['Stale'] ['Stale']
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [ 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
['Stale'] ['Stale']
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [ 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
['Stale', 'test'] ['Stale', 'test']
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [ 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
['Stale'] ['Stale']
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [ 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
['stat: stale'] ['stat: stale']
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [{user: {login: 'notme', type: 'User'}, body: 'Body'}], // return a fake comment to indicate there was an update async () => [{user: {login: 'notme', type: 'User'}, body: 'Body'}], // return a fake comment to indicate there was an update
async () => new Date().toDateString() 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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(),
lastUpdate.toString(), lastUpdate.toString(),
false, false,
false,
['Stale'] ['Stale']
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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', 'An issue that should be marked stale but not closed',
lastUpdate.toString(), lastUpdate.toString(),
lastUpdate.toString(), lastUpdate.toString(),
false,
true true
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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', 'An issue that should be marked stale but not closed',
lastUpdate.toString(), lastUpdate.toString(),
lastUpdate.toString(), lastUpdate.toString(),
false,
true true
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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', 'An issue that should have its branch deleted',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false,
isPullRequest, isPullRequest,
['Stale'] ['Stale']
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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', 'An issue that should not have its branch deleted',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false,
isPullRequest, isPullRequest,
['Stale'] ['Stale']
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
undefined, undefined,
undefined, undefined,
undefined, undefined,
@ -1677,6 +1771,7 @@ test('an issue without a milestone will be marked as stale', async () => {
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
DefaultProcessorOptions, DefaultProcessorOptions,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
undefined, undefined,
undefined, undefined,
undefined, undefined,
@ -1710,6 +1806,7 @@ test('an issue without an exempted milestone will be marked as stale', async ()
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
undefined, undefined,
undefined, 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
undefined, undefined,
undefined, 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
undefined, undefined,
undefined, 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
undefined, undefined,
undefined, undefined,
undefined, undefined,
@ -1843,6 +1947,7 @@ test('an issue with an exempted milestone but without an exempted issue mileston
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
undefined, undefined,
undefined, undefined,
undefined, undefined,
@ -1877,6 +1983,7 @@ test('an issue with an exempted milestone but with another exempted issue milest
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false, false,
false,
undefined, undefined,
undefined, 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toISOString() 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toISOString() 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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toISOString() 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', 'A pull request with no label',
issueDate.toDateString(), issueDate.toDateString(),
issueDate.toDateString(), issueDate.toDateString(),
false,
true true
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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', 'A pull request with no label',
issueDate.toDateString(), issueDate.toDateString(),
issueDate.toDateString(), issueDate.toDateString(),
false,
true true
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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', 'A pull request with no label',
issueDate.toDateString(), issueDate.toDateString(),
issueDate.toDateString(), issueDate.toDateString(),
false,
true true
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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', 'A pull request with no label',
issueDate.toISOString(), issueDate.toISOString(),
issueDate.toISOString(), issueDate.toISOString(),
false,
true true
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toISOString() 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', 'A pull request with no label',
issueDate.toISOString(), issueDate.toISOString(),
issueDate.toISOString(), issueDate.toISOString(),
false,
true true
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toISOString() 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', 'A pull request with no label',
issueDate.toISOString(), issueDate.toISOString(),
issueDate.toISOString(), issueDate.toISOString(),
false,
true true
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toISOString() async () => new Date().toISOString()
@ -2295,6 +2422,7 @@ test('processing a previously closed issue with a close label will remove the cl
oneWeekAgo.toDateString(), oneWeekAgo.toDateString(),
now.toDateString(), now.toDateString(),
false, false,
false,
['close'], ['close'],
false, false,
false false
@ -2302,6 +2430,7 @@ test('processing a previously closed issue with a close label will remove the cl
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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(), oneWeekAgo.toDateString(),
now.toDateString(), now.toDateString(),
false, false,
false,
['close'], ['close'],
true, true,
false false
@ -2337,6 +2467,7 @@ test('processing a closed issue with a close label will not remove the close lab
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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(), oneWeekAgo.toDateString(),
now.toDateString(), now.toDateString(),
false, false,
false,
['close'], ['close'],
false, false,
true true
@ -2372,6 +2504,7 @@ test('processing a locked issue with a close label will not remove the close lab
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() async () => new Date().toDateString()
@ -2404,6 +2537,7 @@ test('processing an issue stale since less than the daysBeforeStale with a stale
updatedAt.toDateString(), updatedAt.toDateString(),
new Date(2021, 0, 16).toDateString(), new Date(2021, 0, 16).toDateString(),
false, false,
false,
['stale-label'], // This was the problem for the user BTW, the issue was re-opened without removing the previous stale label ['stale-label'], // This was the problem for the user BTW, the issue was re-opened without removing the previous stale label
false, false,
false false
@ -2411,6 +2545,7 @@ test('processing an issue stale since less than the daysBeforeStale with a stale
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async (): Promise<IComment[]> => Promise.resolve([]), async (): Promise<IComment[]> => Promise.resolve([]),
async () => labelCreatedAt.toDateString() async () => labelCreatedAt.toDateString()
@ -2444,6 +2579,7 @@ test('processing an issue stale since less than the daysBeforeStale without a st
updatedAt.toDateString(), updatedAt.toDateString(),
new Date(2021, 0, 16).toDateString(), new Date(2021, 0, 16).toDateString(),
false, false,
false,
[], [],
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( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async (): Promise<IComment[]> => Promise.resolve([]), async (): Promise<IComment[]> => Promise.resolve([]),
async () => new Date().toDateString() 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', 'A pull request with no label and a stale message',
issueDate.toDateString(), issueDate.toDateString(),
issueDate.toDateString(), issueDate.toDateString(),
false,
true true
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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', 'A pull request with no label and a stale message',
issueDate.toDateString(), issueDate.toDateString(),
issueDate.toDateString(), issueDate.toDateString(),
false,
true true
) )
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() async () => new Date().toDateString()
@ -2552,6 +2693,7 @@ test('processing an issue with the "includeOnlyAssigned" option and nonempty ass
issueDate.toDateString(), issueDate.toDateString(),
issueDate.toDateString(), issueDate.toDateString(),
false, false,
false,
[], [],
false, false,
false, false,
@ -2561,6 +2703,7 @@ test('processing an issue with the "includeOnlyAssigned" option and nonempty ass
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() async () => new Date().toDateString()
@ -2588,6 +2731,7 @@ test('processing an issue with the "includeOnlyAssigned" option set and no assig
]; ];
const processor = new IssuesProcessorMock( const processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []), async p => (p === 1 ? TestIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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 {IssuesProcessorMock} from './classes/issues-processor-mock';
import {DefaultProcessorOptions} from './constants/default-processor-options'; import {DefaultProcessorOptions} from './constants/default-processor-options';
import {generateIssue} from './functions/generate-issue'; import {generateIssue} from './functions/generate-issue';
import {alwaysFalseStateMock} from './classes/state-mock';
interface ITestData { interface ITestData {
isPullRequest: boolean; isPullRequest: boolean;
@ -27,6 +28,7 @@ describe('milestones options', (): void => {
'My first issue', 'My first issue',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z', '2020-01-01T17:00:00Z',
false,
isPullRequest, isPullRequest,
undefined, undefined,
undefined, undefined,
@ -39,6 +41,7 @@ describe('milestones options', (): void => {
const setProcessor = () => { const setProcessor = () => {
processor = new IssuesProcessorMock( processor = new IssuesProcessorMock(
opts, opts,
alwaysFalseStateMock,
async p => (p === 1 ? testIssueList : []), async p => (p === 1 ? testIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() 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 {IssuesProcessorMock} from './classes/issues-processor-mock';
import {DefaultProcessorOptions} from './constants/default-processor-options'; import {DefaultProcessorOptions} from './constants/default-processor-options';
import {generateIssue} from './functions/generate-issue'; import {generateIssue} from './functions/generate-issue';
import {alwaysFalseStateMock} from './classes/state-mock';
let issuesProcessorBuilder: IssuesProcessorBuilder; let issuesProcessorBuilder: IssuesProcessorBuilder;
let issuesProcessor: IssuesProcessorMock; let issuesProcessor: IssuesProcessorMock;
@ -1102,6 +1103,7 @@ class IssuesProcessorBuilder {
issue.title ?? 'dummy-title', issue.title ?? 'dummy-title',
issue.updated_at ?? new Date().toDateString(), issue.updated_at ?? new Date().toDateString(),
issue.created_at ?? new Date().toDateString(), issue.created_at ?? new Date().toDateString(),
false,
!!issue.pull_request, !!issue.pull_request,
issue.labels ? issue.labels.map(label => label.name || '') : [] issue.labels ? issue.labels.map(label => label.name || '') : []
) )
@ -1139,6 +1141,7 @@ class IssuesProcessorBuilder {
build(): IssuesProcessorMock { build(): IssuesProcessorMock {
return new IssuesProcessorMock( return new IssuesProcessorMock(
this._options, this._options,
alwaysFalseStateMock,
async p => (p === 1 ? this._issues : []), async p => (p === 1 ? this._issues : []),
async () => [], async () => [],
async () => new Date().toDateString() 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 {IssuesProcessorMock} from './classes/issues-processor-mock';
import {DefaultProcessorOptions} from './constants/default-processor-options'; import {DefaultProcessorOptions} from './constants/default-processor-options';
import {generateIssue} from './functions/generate-issue'; import {generateIssue} from './functions/generate-issue';
import {alwaysFalseStateMock, StateMock} from './classes/state-mock';
describe('operations-per-run option', (): void => { describe('operations-per-run option', (): void => {
let sut: SUT; let sut: SUT;
@ -205,6 +206,7 @@ class SUT {
private async _setProcessor(): Promise<number> { private async _setProcessor(): Promise<number> {
this.processor = new IssuesProcessorMock( this.processor = new IssuesProcessorMock(
this._opts, this._opts,
alwaysFalseStateMock,
async p => (p === 1 ? this._testIssueList : []), async p => (p === 1 ? this._testIssueList : []),
async () => [], async () => [],
async () => new Date().toDateString() async () => new Date().toDateString()

View File

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

View File

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

6924
dist/index.js vendored

File diff suppressed because it is too large Load Diff

96
package-lock.json generated
View File

@ -9,6 +9,7 @@
"version": "7.0.0", "version": "7.0.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/artifact": "^1.1.1",
"@actions/core": "^1.10.0", "@actions/core": "^1.10.0",
"@actions/github": "^5.1.1", "@actions/github": "^5.1.1",
"@octokit/core": "^4.2.0", "@octokit/core": "^4.2.0",
@ -44,6 +45,17 @@
"npm": ">=7.0.0 <10.0.0-0" "npm": ">=7.0.0 <10.0.0-0"
} }
}, },
"node_modules/@actions/artifact": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@actions/artifact/-/artifact-1.1.1.tgz",
"integrity": "sha512-Vv4y0EW0ptEkU+Pjs5RGS/0EryTvI6s79LjSV9Gg/h+O3H/ddpjhuX/Bi/HZE4pbNPyjGtQjbdFWphkZhmgabA==",
"dependencies": {
"@actions/core": "^1.9.1",
"@actions/http-client": "^2.0.1",
"tmp": "^0.2.1",
"tmp-promise": "^3.0.2"
}
},
"node_modules/@actions/core": { "node_modules/@actions/core": {
"version": "1.10.0", "version": "1.10.0",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz", "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz",
@ -2468,8 +2480,7 @@
"node_modules/balanced-match": { "node_modules/balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
"dev": true
}, },
"node_modules/before-after-hook": { "node_modules/before-after-hook": {
"version": "2.2.3", "version": "2.2.3",
@ -2485,7 +2496,6 @@
"version": "1.1.11", "version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"dev": true,
"dependencies": { "dependencies": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
@ -2755,8 +2765,7 @@
"node_modules/concat-map": { "node_modules/concat-map": {
"version": "0.0.1", "version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
"dev": true
}, },
"node_modules/concat-stream": { "node_modules/concat-stream": {
"version": "2.0.0", "version": "2.0.0",
@ -4151,8 +4160,7 @@
"node_modules/fs.realpath": { "node_modules/fs.realpath": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
"dev": true
}, },
"node_modules/fsevents": { "node_modules/fsevents": {
"version": "2.3.2", "version": "2.3.2",
@ -4347,7 +4355,6 @@
"version": "7.1.6", "version": "7.1.6",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz",
"integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==",
"dev": true,
"dependencies": { "dependencies": {
"fs.realpath": "^1.0.0", "fs.realpath": "^1.0.0",
"inflight": "^1.0.4", "inflight": "^1.0.4",
@ -4554,7 +4561,6 @@
"version": "1.0.6", "version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
"dev": true,
"dependencies": { "dependencies": {
"once": "^1.3.0", "once": "^1.3.0",
"wrappy": "1" "wrappy": "1"
@ -4563,8 +4569,7 @@
"node_modules/inherits": { "node_modules/inherits": {
"version": "2.0.4", "version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
"dev": true
}, },
"node_modules/ini": { "node_modules/ini": {
"version": "1.3.8", "version": "1.3.8",
@ -6454,7 +6459,6 @@
"version": "3.1.2", "version": "3.1.2",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
"integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
"dev": true,
"dependencies": { "dependencies": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
}, },
@ -6713,7 +6717,6 @@
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
"dev": true,
"engines": { "engines": {
"node": ">=0.10.0" "node": ">=0.10.0"
} }
@ -7181,7 +7184,6 @@
"version": "3.0.2", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
"dev": true,
"dependencies": { "dependencies": {
"glob": "^7.1.3" "glob": "^7.1.3"
}, },
@ -7743,6 +7745,25 @@
"readable-stream": "3" "readable-stream": "3"
} }
}, },
"node_modules/tmp": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.1.tgz",
"integrity": "sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==",
"dependencies": {
"rimraf": "^3.0.0"
},
"engines": {
"node": ">=8.17.0"
}
},
"node_modules/tmp-promise": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/tmp-promise/-/tmp-promise-3.0.3.tgz",
"integrity": "sha512-RwM7MoPojPxsOBYnyd2hy0bxtIlVrihNs9pj5SUvY8Zz1sQcQG2tG1hSr8PDxfgEB8RNKDhqbIlroIarSNDNsQ==",
"dependencies": {
"tmp": "^0.2.0"
}
},
"node_modules/tmpl": { "node_modules/tmpl": {
"version": "1.0.5", "version": "1.0.5",
"resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz", "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz",
@ -8225,6 +8246,17 @@
} }
}, },
"dependencies": { "dependencies": {
"@actions/artifact": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@actions/artifact/-/artifact-1.1.1.tgz",
"integrity": "sha512-Vv4y0EW0ptEkU+Pjs5RGS/0EryTvI6s79LjSV9Gg/h+O3H/ddpjhuX/Bi/HZE4pbNPyjGtQjbdFWphkZhmgabA==",
"requires": {
"@actions/core": "^1.9.1",
"@actions/http-client": "^2.0.1",
"tmp": "^0.2.1",
"tmp-promise": "^3.0.2"
}
},
"@actions/core": { "@actions/core": {
"version": "1.10.0", "version": "1.10.0",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz", "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz",
@ -10093,8 +10125,7 @@
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
"dev": true
}, },
"before-after-hook": { "before-after-hook": {
"version": "2.2.3", "version": "2.2.3",
@ -10110,7 +10141,6 @@
"version": "1.1.11", "version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"dev": true,
"requires": { "requires": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
@ -10310,8 +10340,7 @@
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
"dev": true
}, },
"concat-stream": { "concat-stream": {
"version": "2.0.0", "version": "2.0.0",
@ -11349,8 +11378,7 @@
"fs.realpath": { "fs.realpath": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
"dev": true
}, },
"fsevents": { "fsevents": {
"version": "2.3.2", "version": "2.3.2",
@ -11500,7 +11528,6 @@
"version": "7.1.6", "version": "7.1.6",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz",
"integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==",
"dev": true,
"requires": { "requires": {
"fs.realpath": "^1.0.0", "fs.realpath": "^1.0.0",
"inflight": "^1.0.4", "inflight": "^1.0.4",
@ -11645,7 +11672,6 @@
"version": "1.0.6", "version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
"dev": true,
"requires": { "requires": {
"once": "^1.3.0", "once": "^1.3.0",
"wrappy": "1" "wrappy": "1"
@ -11654,8 +11680,7 @@
"inherits": { "inherits": {
"version": "2.0.4", "version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
"dev": true
}, },
"ini": { "ini": {
"version": "1.3.8", "version": "1.3.8",
@ -13068,7 +13093,6 @@
"version": "3.1.2", "version": "3.1.2",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
"integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
"dev": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }
@ -13266,8 +13290,7 @@
"path-is-absolute": { "path-is-absolute": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18="
"dev": true
}, },
"path-key": { "path-key": {
"version": "3.1.1", "version": "3.1.1",
@ -13591,7 +13614,6 @@
"version": "3.0.2", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
"dev": true,
"requires": { "requires": {
"glob": "^7.1.3" "glob": "^7.1.3"
} }
@ -14007,6 +14029,22 @@
"readable-stream": "3" "readable-stream": "3"
} }
}, },
"tmp": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.1.tgz",
"integrity": "sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==",
"requires": {
"rimraf": "^3.0.0"
}
},
"tmp-promise": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/tmp-promise/-/tmp-promise-3.0.3.tgz",
"integrity": "sha512-RwM7MoPojPxsOBYnyd2hy0bxtIlVrihNs9pj5SUvY8Zz1sQcQG2tG1hSr8PDxfgEB8RNKDhqbIlroIarSNDNsQ==",
"requires": {
"tmp": "^0.2.0"
}
},
"tmpl": { "tmpl": {
"version": "1.0.5", "version": "1.0.5",
"resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz", "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz",

View File

@ -37,6 +37,7 @@
"author": "GitHub", "author": "GitHub",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/artifact": "^1.1.1",
"@actions/core": "^1.10.0", "@actions/core": "^1.10.0",
"@actions/github": "^5.1.1", "@actions/github": "^5.1.1",
"@octokit/core": "^4.2.0", "@octokit/core": "^4.2.0",

View File

@ -17,6 +17,8 @@ export class ExemptDraftPullRequest {
} }
async shouldExemptDraftPullRequest( async shouldExemptDraftPullRequest(
// keep this for backward compatibility
// eslint-disable-next-line @typescript-eslint/no-unused-vars
pullRequestCallback: () => Promise<IPullRequest | undefined | void> pullRequestCallback: () => Promise<IPullRequest | undefined | void>
): Promise<boolean> { ): Promise<boolean> {
if (this._issue.isPullRequest) { if (this._issue.isPullRequest) {

View File

@ -71,6 +71,7 @@ describe('Issue', (): void => {
number: 8, number: 8,
created_at: 'dummy-created-at', created_at: 'dummy-created-at',
updated_at: 'dummy-updated-at', updated_at: 'dummy-updated-at',
draft: false,
labels: [ labels: [
{ {
name: 'dummy-name' name: 'dummy-name'

View File

@ -34,7 +34,7 @@ export class Issue implements IIssue {
this.number = issue.number; this.number = issue.number;
this.created_at = issue.created_at; this.created_at = issue.created_at;
this.updated_at = issue.updated_at; this.updated_at = issue.updated_at;
this.draft = issue.draft || false; this.draft = Boolean(issue.draft);
this.labels = mapLabels(issue.labels); this.labels = mapLabels(issue.labels);
this.pull_request = issue.pull_request; this.pull_request = issue.pull_request;
this.state = issue.state; this.state = issue.state;

View File

@ -26,6 +26,7 @@ import {Statistics} from './statistics';
import {LoggerService} from '../services/logger.service'; import {LoggerService} from '../services/logger.service';
import {OctokitIssue} from '../interfaces/issue'; import {OctokitIssue} from '../interfaces/issue';
import {retry} from '@octokit/plugin-retry'; import {retry} from '@octokit/plugin-retry';
import {IState} from '../interfaces/state';
/*** /***
* Handle processing of issues for staleness/closure. * Handle processing of issues for staleness/closure.
@ -72,9 +73,11 @@ export class IssuesProcessor {
readonly addedCloseCommentIssues: Issue[] = []; readonly addedCloseCommentIssues: Issue[] = [];
readonly statistics: Statistics | undefined; readonly statistics: Statistics | undefined;
private readonly _logger: Logger = new Logger(); private readonly _logger: Logger = new Logger();
private readonly state: IState;
constructor(options: IIssuesProcessorOptions) { constructor(options: IIssuesProcessorOptions, state: IState) {
this.options = options; this.options = options;
this.state = state;
this.client = getOctokit(this.options.repoToken, undefined, retry); this.client = getOctokit(this.options.repoToken, undefined, retry);
this.operations = new StaleOperations(this.options); this.operations = new StaleOperations(this.options);
@ -110,6 +113,8 @@ export class IssuesProcessor {
?.setOperationsCount(this.operations.getConsumedOperationsCount()) ?.setOperationsCount(this.operations.getConsumedOperationsCount())
.logStats(); .logStats();
this.state.reset();
return this.operations.getRemainingOperationsCount(); return this.operations.getRemainingOperationsCount();
} else { } else {
this._logger.info( this._logger.info(
@ -196,6 +201,15 @@ export class IssuesProcessor {
)}` )}`
); );
if (this.state.isIssueProcessed(issue)) {
issueLogger.info(
' $$type skipped due being processed during the previous run'
);
return;
}
this.state.addIssueToProcessed(issue);
// calculate string based messages for this issue // calculate string based messages for this issue
const staleMessage: string = issue.isPullRequest const staleMessage: string = issue.isPullRequest
? this.options.stalePrMessage ? this.options.stalePrMessage

69
src/classes/state.ts Normal file
View File

@ -0,0 +1,69 @@
import {Issue} from './issue';
import {IState} from '../interfaces/state';
import os from 'os';
import crypto from 'crypto';
import fs from 'fs';
import path from 'path';
import artifact from '@actions/artifact';
type IssueID = number;
export class State implements IState {
private processedIssuesIDs: Set<IssueID>;
constructor() {
this.processedIssuesIDs = new Set();
}
isIssueProcessed(issue: Issue) {
return this.processedIssuesIDs.has(issue.number);
}
addIssueToProcessed(issue: Issue) {
this.processedIssuesIDs.add(issue.number);
}
reset() {
this.processedIssuesIDs.clear();
}
private static readonly ARTIFACT_NAME = '_stale_state';
async persist() {
const serialized = Array.from(this.processedIssuesIDs).join('|');
const tmpDir = os.tmpdir();
const file = crypto.randomBytes(8).readBigUInt64LE(0).toString();
fs.writeFileSync(path.join(tmpDir, file), serialized);
const artifactClient = artifact.create();
// TODO: handle errors
await artifactClient.uploadArtifact(State.ARTIFACT_NAME, [file], tmpDir);
}
async rehydrate() {
this.reset();
const tmpDir = os.tmpdir();
const artifactClient = artifact.create();
const downloadResponse = await artifactClient.downloadArtifact(
State.ARTIFACT_NAME,
tmpDir
);
const downloadedFiles = fs.readdirSync(downloadResponse.downloadPath);
if (downloadedFiles.length === 0) {
// TODO: handle error
}
const serialized = fs.readFileSync(
path.join(downloadResponse.downloadPath, downloadedFiles[0]),
{encoding: 'utf8'}
);
if (serialized.length === 0) return;
const issueIDs = serialized
.split('|')
.map(parseInt)
.filter(i => !isNaN(i));
this.processedIssuesIDs = new Set(issueIDs);
}
}

9
src/interfaces/state.ts Normal file
View File

@ -0,0 +1,9 @@
import {IIssue} from './issue';
export interface IState {
isIssueProcessed(issue: IIssue): boolean;
addIssueToProcessed(issue: IIssue): void;
reset(): void;
persist(): Promise<void>;
rehydrate(): Promise<void>;
}

View File

@ -3,14 +3,20 @@ import {IssuesProcessor} from './classes/issues-processor';
import {isValidDate} from './functions/dates/is-valid-date'; import {isValidDate} from './functions/dates/is-valid-date';
import {IIssuesProcessorOptions} from './interfaces/issues-processor-options'; import {IIssuesProcessorOptions} from './interfaces/issues-processor-options';
import {Issue} from './classes/issue'; import {Issue} from './classes/issue';
import {StateService} from './services/state.service';
async function _run(): Promise<void> { async function _run(): Promise<void> {
try { try {
const args = _getAndValidateArgs(); const args = _getAndValidateArgs();
const issueProcessor: IssuesProcessor = new IssuesProcessor(args); const state = StateService.getState();
await state.rehydrate();
const issueProcessor: IssuesProcessor = new IssuesProcessor(args, state);
await issueProcessor.processIssues(); await issueProcessor.processIssues();
await state.persist();
await processOutput( await processOutput(
issueProcessor.staleIssues, issueProcessor.staleIssues,
issueProcessor.closedIssues issueProcessor.closedIssues

View File

@ -0,0 +1,8 @@
import {IState} from '../interfaces/state';
import {State} from '../classes/state';
export class StateService {
static getState(): IState {
return new State();
}
}