Files
stale/__tests__/classes/issues-processor-mock.ts
shamoon db5d06a4c8 Enhancement: ignore stale labeling events (#1311)
* Ignore updates if only stale label changed after marking

* Initial tests

* test hasOnlyStaleLabelUpdateSince itself

* Actually we should only ignore label events, not unlabel

* Add logger

* Fix test

* Remove trailing whitespace

* Add test for non-label event

* Add boundary test

* Add error handling to hasOnlyStaleLabelAddedSince

* Add comment noting intentional event before boundary

* Remove unneeded optional chaining

* Limit pagination to max 3 calls / 300 events

* Rename method

* Handle invalid timestamps

* Fallback when limit reached

* Oh wow, just realized we already got events...

* Refactor

* Lint

* Build

* Remove events "cache"

* Update index.js
2026-03-18 11:25:18 -05:00

65 lines
1.9 KiB
TypeScript

import {Issue} from '../../src/classes/issue';
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/state';
import {IIssueEvent} from '../../src/interfaces/issue-event';
export class IssuesProcessorMock extends IssuesProcessor {
constructor(
options: IIssuesProcessorOptions,
state: IState,
getIssues?: (page: number) => Promise<Issue[]>,
listIssueComments?: (
issue: Issue,
sinceDate: string
) => Promise<IComment[]>,
getLabelCreationDate?: (
issue: Issue,
label: string
) =>
| Promise<string | undefined>
| Promise<{creationDate?: string; events: IIssueEvent[]}>,
hasOnlyStaleLabelingEventsSince?: (
issue: Issue,
sinceDate: string,
staleLabel: string,
events: IIssueEvent[]
) => Promise<boolean>,
getPullRequest?: (issue: Issue) => Promise<IPullRequest | undefined | void>
) {
super(options, state);
if (getIssues) {
this.getIssues = getIssues;
}
if (listIssueComments) {
this.listIssueComments = listIssueComments;
}
if (getLabelCreationDate) {
this.getLabelCreationDate = async (
issue: Issue,
label: string
): Promise<{creationDate?: string; events: IIssueEvent[]}> => {
const result = await getLabelCreationDate(issue, label);
if (typeof result === 'string' || typeof result === 'undefined') {
return {creationDate: result, events: []};
}
return result;
};
}
if (hasOnlyStaleLabelingEventsSince) {
this.hasOnlyStaleLabelingEventsSince = hasOnlyStaleLabelingEventsSince;
}
if (getPullRequest) {
this.getPullRequest = getPullRequest;
}
}
}