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 {
|
||||
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());
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue