Do not mutate state in debug mode
This commit is contained in:
parent
7109b30ab8
commit
1e059ce975
|
@ -1564,18 +1564,23 @@ const core = __importStar(__nccwpck_require__(2186));
|
||||||
class State {
|
class State {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.processedIssuesIDs = new Set();
|
this.processedIssuesIDs = new Set();
|
||||||
|
this.debug = core.getInput('debug-only') === 'true';
|
||||||
}
|
}
|
||||||
isIssueProcessed(issue) {
|
isIssueProcessed(issue) {
|
||||||
return this.processedIssuesIDs.has(issue.number);
|
return this.processedIssuesIDs.has(issue.number);
|
||||||
}
|
}
|
||||||
addIssueToProcessed(issue) {
|
addIssueToProcessed(issue) {
|
||||||
|
if (!this.debug)
|
||||||
this.processedIssuesIDs.add(issue.number);
|
this.processedIssuesIDs.add(issue.number);
|
||||||
}
|
}
|
||||||
reset() {
|
reset() {
|
||||||
|
if (!this.debug)
|
||||||
this.processedIssuesIDs.clear();
|
this.processedIssuesIDs.clear();
|
||||||
}
|
}
|
||||||
persist() {
|
persist() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
if (this.debug)
|
||||||
|
return;
|
||||||
const serialized = Array.from(this.processedIssuesIDs).join('|');
|
const serialized = Array.from(this.processedIssuesIDs).join('|');
|
||||||
const tmpDir = os_1.default.tmpdir();
|
const tmpDir = os_1.default.tmpdir();
|
||||||
const file = path_1.default.join(tmpDir, crypto_1.default.randomBytes(8).readBigUInt64LE(0).toString());
|
const file = path_1.default.join(tmpDir, crypto_1.default.randomBytes(8).readBigUInt64LE(0).toString());
|
||||||
|
|
|
@ -10,8 +10,13 @@ import * as core from '@actions/core';
|
||||||
type IssueID = number;
|
type IssueID = number;
|
||||||
export class State implements IState {
|
export class State implements IState {
|
||||||
private processedIssuesIDs: Set<IssueID>;
|
private processedIssuesIDs: Set<IssueID>;
|
||||||
|
/**
|
||||||
|
* @private don't mutate in the debug mode
|
||||||
|
*/
|
||||||
|
private readonly debug: boolean;
|
||||||
constructor() {
|
constructor() {
|
||||||
this.processedIssuesIDs = new Set();
|
this.processedIssuesIDs = new Set();
|
||||||
|
this.debug = core.getInput('debug-only') === 'true';
|
||||||
}
|
}
|
||||||
|
|
||||||
isIssueProcessed(issue: Issue) {
|
isIssueProcessed(issue: Issue) {
|
||||||
|
@ -19,15 +24,17 @@ export class State implements IState {
|
||||||
}
|
}
|
||||||
|
|
||||||
addIssueToProcessed(issue: Issue) {
|
addIssueToProcessed(issue: Issue) {
|
||||||
this.processedIssuesIDs.add(issue.number);
|
if (!this.debug) this.processedIssuesIDs.add(issue.number);
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
this.processedIssuesIDs.clear();
|
if (!this.debug) this.processedIssuesIDs.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly ARTIFACT_NAME = '_stale_state';
|
private static readonly ARTIFACT_NAME = '_stale_state';
|
||||||
async persist() {
|
async persist() {
|
||||||
|
if (this.debug) return;
|
||||||
|
|
||||||
const serialized = Array.from(this.processedIssuesIDs).join('|');
|
const serialized = Array.from(this.processedIssuesIDs).join('|');
|
||||||
|
|
||||||
const tmpDir = os.tmpdir();
|
const tmpDir = os.tmpdir();
|
||||||
|
|
Loading…
Reference in New Issue