Add dist.js
This commit is contained in:
parent
ee531bffac
commit
0f79a426cc
|
@ -1644,22 +1644,27 @@ const resetCacheWithOctokit = (cacheKey) => __awaiter(void 0, void 0, void 0, fu
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
class StateCacheStorage {
|
class StateCacheStorage {
|
||||||
|
constructor(options) {
|
||||||
|
this.statePrefix = options.cachePrefix;
|
||||||
|
}
|
||||||
save(serializedState) {
|
save(serializedState) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const tmpDir = mkTempDir();
|
const tmpDir = mkTempDir();
|
||||||
const filePath = path_1.default.join(tmpDir, STATE_FILE);
|
const stateFile = `${this.statePrefix}_${STATE_FILE}`;
|
||||||
|
const filePath = path_1.default.join(tmpDir, stateFile);
|
||||||
fs_1.default.writeFileSync(filePath, serializedState);
|
fs_1.default.writeFileSync(filePath, serializedState);
|
||||||
try {
|
try {
|
||||||
const cacheExists = yield checkIfCacheExists(CACHE_KEY);
|
const cacheKey = `${this.statePrefix}${CACHE_KEY}`;
|
||||||
|
const cacheExists = yield checkIfCacheExists(cacheKey);
|
||||||
if (cacheExists) {
|
if (cacheExists) {
|
||||||
yield resetCacheWithOctokit(CACHE_KEY);
|
yield resetCacheWithOctokit(cacheKey);
|
||||||
}
|
}
|
||||||
const fileSize = fs_1.default.statSync(filePath).size;
|
const fileSize = fs_1.default.statSync(filePath).size;
|
||||||
if (fileSize === 0) {
|
if (fileSize === 0) {
|
||||||
core.info(`the state will be removed`);
|
core.info(`the state will be removed`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
yield cache.saveCache([path_1.default.dirname(filePath)], CACHE_KEY);
|
yield cache.saveCache([path_1.default.dirname(filePath)], cacheKey);
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
core.warning(`Saving the state was not successful due to "${error.message || 'unknown reason'}"`);
|
core.warning(`Saving the state was not successful due to "${error.message || 'unknown reason'}"`);
|
||||||
|
@ -1672,20 +1677,22 @@ class StateCacheStorage {
|
||||||
restore() {
|
restore() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const tmpDir = mkTempDir();
|
const tmpDir = mkTempDir();
|
||||||
const filePath = path_1.default.join(tmpDir, STATE_FILE);
|
const stateFile = `${this.statePrefix}_${STATE_FILE}`;
|
||||||
|
const filePath = path_1.default.join(tmpDir, stateFile);
|
||||||
unlinkSafely(filePath);
|
unlinkSafely(filePath);
|
||||||
try {
|
try {
|
||||||
const cacheExists = yield checkIfCacheExists(CACHE_KEY);
|
const cacheKey = `${this.statePrefix}${CACHE_KEY}`;
|
||||||
|
const cacheExists = yield checkIfCacheExists(cacheKey);
|
||||||
if (!cacheExists) {
|
if (!cacheExists) {
|
||||||
core.info('The saved state was not found, the process starts from the first issue.');
|
core.info('The saved state was not found, the process starts from the first issue.');
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
yield cache.restoreCache([path_1.default.dirname(filePath)], CACHE_KEY);
|
yield cache.restoreCache([path_1.default.dirname(filePath)], cacheKey);
|
||||||
if (!fs_1.default.existsSync(filePath)) {
|
if (!fs_1.default.existsSync(filePath)) {
|
||||||
core.warning('Unknown error when unpacking the cache, the process starts from the first issue.');
|
core.warning('Unknown error when unpacking the cache, the process starts from the first issue.');
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
return fs_1.default.readFileSync(path_1.default.join(tmpDir, STATE_FILE), {
|
return fs_1.default.readFileSync(path_1.default.join(tmpDir, stateFile), {
|
||||||
encoding: 'utf8'
|
encoding: 'utf8'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -2222,6 +2229,7 @@ var Option;
|
||||||
Option["IgnorePrUpdates"] = "ignore-pr-updates";
|
Option["IgnorePrUpdates"] = "ignore-pr-updates";
|
||||||
Option["ExemptDraftPr"] = "exempt-draft-pr";
|
Option["ExemptDraftPr"] = "exempt-draft-pr";
|
||||||
Option["CloseIssueReason"] = "close-issue-reason";
|
Option["CloseIssueReason"] = "close-issue-reason";
|
||||||
|
Option["CachePrefix"] = "cache-prefix";
|
||||||
})(Option || (exports.Option = Option = {}));
|
})(Option || (exports.Option = Option = {}));
|
||||||
|
|
||||||
|
|
||||||
|
@ -2567,7 +2575,8 @@ function _getAndValidateArgs() {
|
||||||
ignorePrUpdates: _toOptionalBoolean('ignore-pr-updates'),
|
ignorePrUpdates: _toOptionalBoolean('ignore-pr-updates'),
|
||||||
exemptDraftPr: core.getInput('exempt-draft-pr') === 'true',
|
exemptDraftPr: core.getInput('exempt-draft-pr') === 'true',
|
||||||
closeIssueReason: core.getInput('close-issue-reason'),
|
closeIssueReason: core.getInput('close-issue-reason'),
|
||||||
includeOnlyAssigned: core.getInput('include-only-assigned') === 'true'
|
includeOnlyAssigned: core.getInput('include-only-assigned') === 'true',
|
||||||
|
cachePrefix: core.getInput('cache-prefix')
|
||||||
};
|
};
|
||||||
for (const numberInput of ['days-before-stale']) {
|
for (const numberInput of ['days-before-stale']) {
|
||||||
if (isNaN(parseFloat(core.getInput(numberInput)))) {
|
if (isNaN(parseFloat(core.getInput(numberInput)))) {
|
||||||
|
@ -2694,7 +2703,7 @@ exports.getStateInstance = void 0;
|
||||||
const state_1 = __nccwpck_require__(5186);
|
const state_1 = __nccwpck_require__(5186);
|
||||||
const state_cache_storage_1 = __nccwpck_require__(3709);
|
const state_cache_storage_1 = __nccwpck_require__(3709);
|
||||||
const getStateInstance = (options) => {
|
const getStateInstance = (options) => {
|
||||||
const storage = new state_cache_storage_1.StateCacheStorage();
|
const storage = new state_cache_storage_1.StateCacheStorage(options);
|
||||||
return new state_1.State(storage, options);
|
return new state_1.State(storage, options);
|
||||||
};
|
};
|
||||||
exports.getStateInstance = getStateInstance;
|
exports.getStateInstance = getStateInstance;
|
||||||
|
|
Loading…
Reference in New Issue