Unverified Commit 545223a8 authored by Jongwoo Han's avatar Jongwoo Han Committed by GitHub
Browse files

refactor: Use early return pattern to avoid nested conditions (#428)

parent 1df8dbef
Loading
Loading
Loading
Loading
+5 −6
Changes for __tests__/util.test.ts: 5 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -29,14 +29,13 @@ describe('isVersionSatisfies', () => {
describe('isCacheFeatureAvailable', () => {
  it('isCacheFeatureAvailable disabled on GHES', () => {
    jest.spyOn(cache, 'isFeatureAvailable').mockImplementation(() => false);
    const infoMock = jest.spyOn(core, 'warning');
    const message =
      'Caching is only supported on GHES version >= 3.5. If you are on a version >= 3.5, please check with your GHES admin if the Actions cache service is enabled or not.';
    try {
      process.env['GITHUB_SERVER_URL'] = 'http://example.com';
      isCacheFeatureAvailable();
    } catch (error) {
      expect(error).toHaveProperty(
        'message',
        'Caching is only supported on GHES version >= 3.5. If you are on a version >= 3.5, please check with your GHES admin if the Actions cache service is enabled or not.'
      );
      expect(isCacheFeatureAvailable()).toBeFalsy();
      expect(infoMock).toHaveBeenCalledWith(message);
    } finally {
      delete process.env['GITHUB_SERVER_URL'];
    }
+5 −6
Changes for dist/cleanup/index.js: 5 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -68708,17 +68708,16 @@ function isGhes() {
}
exports.isGhes = isGhes;
function isCacheFeatureAvailable() {
    if (!cache.isFeatureAvailable()) {
    if (cache.isFeatureAvailable()) {
        return true;
    }
    if (isGhes()) {
            throw new Error('Caching is only supported on GHES version >= 3.5. If you are on a version >= 3.5, please check with your GHES admin if the Actions cache service is enabled or not.');
        core.warning('Caching is only supported on GHES version >= 3.5. If you are on a version >= 3.5, please check with your GHES admin if the Actions cache service is enabled or not.');
        return false;
    }
        else {
    core.warning('The runner was not able to contact the cache service. Caching will be skipped');
        }
    return false;
}
    return true;
}
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
function getVersionFromFileContent(content, distributionName) {
    var _a, _b, _c, _d, _e;
+5 −6
Changes for dist/setup/index.js: 5 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -105436,17 +105436,16 @@ function isGhes() {
}
exports.isGhes = isGhes;
function isCacheFeatureAvailable() {
    if (!cache.isFeatureAvailable()) {
    if (cache.isFeatureAvailable()) {
        return true;
    }
    if (isGhes()) {
            throw new Error('Caching is only supported on GHES version >= 3.5. If you are on a version >= 3.5, please check with your GHES admin if the Actions cache service is enabled or not.');
        core.warning('Caching is only supported on GHES version >= 3.5. If you are on a version >= 3.5, please check with your GHES admin if the Actions cache service is enabled or not.');
        return false;
    }
        else {
    core.warning('The runner was not able to contact the cache service. Caching will be skipped');
        }
    return false;
}
    return true;
}
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
function getVersionFromFileContent(content, distributionName) {
    var _a, _b, _c, _d, _e;
+7 −7
Changes for src/util.ts: 7 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -85,19 +85,19 @@ export function isGhes(): boolean {
}

export function isCacheFeatureAvailable(): boolean {
  if (!cache.isFeatureAvailable()) {
  if (cache.isFeatureAvailable()) {
    return true;
  }

  if (isGhes()) {
      throw new Error(
    core.warning(
      'Caching is only supported on GHES version >= 3.5. If you are on a version >= 3.5, please check with your GHES admin if the Actions cache service is enabled or not.'
    );
    } else {
      core.warning('The runner was not able to contact the cache service. Caching will be skipped');
    }

    return false;
  }

  return true;
  core.warning('The runner was not able to contact the cache service. Caching will be skipped');
  return false;
}

export function getVersionFromFileContent(