Do not mutate state in debug mode

This commit is contained in:
Sergey Dolin 2023-06-23 09:12:13 +02:00
parent 7109b30ab8
commit 1e059ce975
2 changed files with 16 additions and 4 deletions

9
dist/index.js vendored
View File

@ -1564,18 +1564,23 @@ const core = __importStar(__nccwpck_require__(2186));
class State {
constructor() {
this.processedIssuesIDs = new Set();
this.debug = core.getInput('debug-only') === 'true';
}
isIssueProcessed(issue) {
return this.processedIssuesIDs.has(issue.number);
}
addIssueToProcessed(issue) {
this.processedIssuesIDs.add(issue.number);
if (!this.debug)
this.processedIssuesIDs.add(issue.number);
}
reset() {
this.processedIssuesIDs.clear();
if (!this.debug)
this.processedIssuesIDs.clear();
}
persist() {
return __awaiter(this, void 0, void 0, function* () {
if (this.debug)
return;
const serialized = Array.from(this.processedIssuesIDs).join('|');
const tmpDir = os_1.default.tmpdir();
const file = path_1.default.join(tmpDir, crypto_1.default.randomBytes(8).readBigUInt64LE(0).toString());

View File

@ -10,8 +10,13 @@ import * as core from '@actions/core';
type IssueID = number;
export class State implements IState {
private processedIssuesIDs: Set<IssueID>;
/**
* @private don't mutate in the debug mode
*/
private readonly debug: boolean;
constructor() {
this.processedIssuesIDs = new Set();
this.debug = core.getInput('debug-only') === 'true';
}
isIssueProcessed(issue: Issue) {
@ -19,15 +24,17 @@ export class State implements IState {
}
addIssueToProcessed(issue: Issue) {
this.processedIssuesIDs.add(issue.number);
if (!this.debug) this.processedIssuesIDs.add(issue.number);
}
reset() {
this.processedIssuesIDs.clear();
if (!this.debug) this.processedIssuesIDs.clear();
}
private static readonly ARTIFACT_NAME = '_stale_state';
async persist() {
if (this.debug) return;
const serialized = Array.from(this.processedIssuesIDs).join('|');
const tmpDir = os.tmpdir();