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

@@ -26,6 +26,7 @@ import {Statistics} from './statistics';
import {LoggerService} from '../services/logger.service';
import {OctokitIssue} from '../interfaces/issue';
import {retry} from '@octokit/plugin-retry';
import {IState} from '../interfaces/state';
/***
* Handle processing of issues for staleness/closure.
@@ -72,9 +73,11 @@ export class IssuesProcessor {
readonly addedCloseCommentIssues: Issue[] = [];
readonly statistics: Statistics | undefined;
private readonly _logger: Logger = new Logger();
private readonly state: IState;
constructor(options: IIssuesProcessorOptions) {
constructor(options: IIssuesProcessorOptions, state: IState) {
this.options = options;
this.state = state;
this.client = getOctokit(this.options.repoToken, undefined, retry);
this.operations = new StaleOperations(this.options);
@@ -110,6 +113,8 @@ export class IssuesProcessor {
?.setOperationsCount(this.operations.getConsumedOperationsCount())
.logStats();
this.state.reset();
return this.operations.getRemainingOperationsCount();
} else {
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
const staleMessage: string = issue.isPullRequest
? this.options.stalePrMessage