From 35f4702f6c5039de5e5509241cc58a6128c962ce Mon Sep 17 00:00:00 2001 From: jongwooo Date: Fri, 2 Dec 2022 15:09:10 +0900 Subject: [PATCH] refactor: Use early return pattern to avoid nested conditions Signed-off-by: jongwooo --- dist/restore/index.js | 15 +++++++-------- dist/save/index.js | 15 +++++++-------- src/utils/actionUtils.ts | 23 ++++++++++++----------- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/dist/restore/index.js b/dist/restore/index.js index f2b0971..423d8ae 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -38489,17 +38489,16 @@ function getInputAsInt(name, options) { } exports.getInputAsInt = getInputAsInt; function isCacheFeatureAvailable() { - if (!cache.isFeatureAvailable()) { - if (isGhes()) { - logWarning(`Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not. + if (cache.isFeatureAvailable()) { + return true; + } + if (isGhes()) { + logWarning(`Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not. Otherwise please upgrade to GHES version >= 3.5 and If you are also using Github Connect, please unretire the actions/cache namespace before upgrade (see https://docs.github.com/en/enterprise-server@3.5/admin/github-actions/managing-access-to-actions-from-githubcom/enabling-automatic-access-to-githubcom-actions-using-github-connect#automatic-retirement-of-namespaces-for-actions-accessed-on-githubcom)`); - } - else { - logWarning("An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions."); - } return false; } - return true; + logWarning("An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions."); + return false; } exports.isCacheFeatureAvailable = isCacheFeatureAvailable; diff --git a/dist/save/index.js b/dist/save/index.js index cb4ca06..f413dd0 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -38489,17 +38489,16 @@ function getInputAsInt(name, options) { } exports.getInputAsInt = getInputAsInt; function isCacheFeatureAvailable() { - if (!cache.isFeatureAvailable()) { - if (isGhes()) { - logWarning(`Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not. + if (cache.isFeatureAvailable()) { + return true; + } + if (isGhes()) { + logWarning(`Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not. Otherwise please upgrade to GHES version >= 3.5 and If you are also using Github Connect, please unretire the actions/cache namespace before upgrade (see https://docs.github.com/en/enterprise-server@3.5/admin/github-actions/managing-access-to-actions-from-githubcom/enabling-automatic-access-to-githubcom-actions-using-github-connect#automatic-retirement-of-namespaces-for-actions-accessed-on-githubcom)`); - } - else { - logWarning("An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions."); - } return false; } - return true; + logWarning("An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions."); + return false; } exports.isCacheFeatureAvailable = isCacheFeatureAvailable; diff --git a/src/utils/actionUtils.ts b/src/utils/actionUtils.ts index dacd3a6..7607bf7 100644 --- a/src/utils/actionUtils.ts +++ b/src/utils/actionUtils.ts @@ -77,19 +77,20 @@ export function getInputAsInt( } export function isCacheFeatureAvailable(): boolean { - if (!cache.isFeatureAvailable()) { - if (isGhes()) { - logWarning( - `Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not. + if (cache.isFeatureAvailable()) { + return true; + } + + if (isGhes()) { + logWarning( + `Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not. Otherwise please upgrade to GHES version >= 3.5 and If you are also using Github Connect, please unretire the actions/cache namespace before upgrade (see https://docs.github.com/en/enterprise-server@3.5/admin/github-actions/managing-access-to-actions-from-githubcom/enabling-automatic-access-to-githubcom-actions-using-github-connect#automatic-retirement-of-namespaces-for-actions-accessed-on-githubcom)` - ); - } else { - logWarning( - "An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions." - ); - } + ); return false; } - return true; + logWarning( + "An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions." + ); + return false; }