From 1e059ce975a5dd63045bd268882f3af5412eb991 Mon Sep 17 00:00:00 2001 From: Sergey Dolin Date: Fri, 23 Jun 2023 09:12:13 +0200 Subject: [PATCH] Do not mutate state in debug mode --- dist/index.js | 9 +++++++-- src/classes/state.ts | 11 +++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index 918b4848..44e5e2ba 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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()); diff --git a/src/classes/state.ts b/src/classes/state.ts index 2f42d772..e0d86d88 100644 --- a/src/classes/state.ts +++ b/src/classes/state.ts @@ -10,8 +10,13 @@ import * as core from '@actions/core'; type IssueID = number; export class State implements IState { private processedIssuesIDs: Set; + /** + * @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();