Add dist.js

This commit is contained in:
Edward Chang 2024-08-01 22:00:57 -04:00
parent ee531bffac
commit 0f79a426cc
1 changed files with 19 additions and 10 deletions

29
dist/index.js vendored
View File

@ -1644,22 +1644,27 @@ const resetCacheWithOctokit = (cacheKey) => __awaiter(void 0, void 0, void 0, fu
}
});
class StateCacheStorage {
constructor(options) {
this.statePrefix = options.cachePrefix;
}
save(serializedState) {
return __awaiter(this, void 0, void 0, function* () {
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);
try {
const cacheExists = yield checkIfCacheExists(CACHE_KEY);
const cacheKey = `${this.statePrefix}${CACHE_KEY}`;
const cacheExists = yield checkIfCacheExists(cacheKey);
if (cacheExists) {
yield resetCacheWithOctokit(CACHE_KEY);
yield resetCacheWithOctokit(cacheKey);
}
const fileSize = fs_1.default.statSync(filePath).size;
if (fileSize === 0) {
core.info(`the state will be removed`);
return;
}
yield cache.saveCache([path_1.default.dirname(filePath)], CACHE_KEY);
yield cache.saveCache([path_1.default.dirname(filePath)], cacheKey);
}
catch (error) {
core.warning(`Saving the state was not successful due to "${error.message || 'unknown reason'}"`);
@ -1672,20 +1677,22 @@ class StateCacheStorage {
restore() {
return __awaiter(this, void 0, void 0, function* () {
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);
try {
const cacheExists = yield checkIfCacheExists(CACHE_KEY);
const cacheKey = `${this.statePrefix}${CACHE_KEY}`;
const cacheExists = yield checkIfCacheExists(cacheKey);
if (!cacheExists) {
core.info('The saved state was not found, the process starts from the first issue.');
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)) {
core.warning('Unknown error when unpacking the cache, the process starts from the first issue.');
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'
});
}
@ -2222,6 +2229,7 @@ var Option;
Option["IgnorePrUpdates"] = "ignore-pr-updates";
Option["ExemptDraftPr"] = "exempt-draft-pr";
Option["CloseIssueReason"] = "close-issue-reason";
Option["CachePrefix"] = "cache-prefix";
})(Option || (exports.Option = Option = {}));
@ -2567,7 +2575,8 @@ function _getAndValidateArgs() {
ignorePrUpdates: _toOptionalBoolean('ignore-pr-updates'),
exemptDraftPr: core.getInput('exempt-draft-pr') === 'true',
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']) {
if (isNaN(parseFloat(core.getInput(numberInput)))) {
@ -2694,7 +2703,7 @@ exports.getStateInstance = void 0;
const state_1 = __nccwpck_require__(5186);
const state_cache_storage_1 = __nccwpck_require__(3709);
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);
};
exports.getStateInstance = getStateInstance;