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
This commit is contained in:
shamoon
2026-03-18 09:25:18 -07:00
committed by GitHub
parent b5d41d4e1d
commit db5d06a4c8
5 changed files with 427 additions and 12 deletions

View File

@@ -4,6 +4,7 @@ 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(
@@ -17,7 +18,15 @@ export class IssuesProcessorMock extends IssuesProcessor {
getLabelCreationDate?: (
issue: Issue,
label: string
) => Promise<string | undefined>,
) =>
| 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);
@@ -31,7 +40,21 @@ export class IssuesProcessorMock extends IssuesProcessor {
}
if (getLabelCreationDate) {
this.getLabelCreationDate = 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) {