From a24ff48c7b168948e0dd06e5670e27c569a072be Mon Sep 17 00:00:00 2001 From: CollinM Date: Sat, 1 Oct 2022 06:48:13 -0500 Subject: [PATCH] Adds force-api-download option Signed-off-by: CollinM --- README.md | 4 ++++ __test__/git-auth-helper.test.ts | 3 ++- action.yml | 4 ++++ dist/index.js | 5 ++++- src/git-source-provider.ts | 2 +- src/git-source-settings.ts | 5 +++++ src/input-helper.ts | 3 +++ 7 files changed, 23 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b85967d..f0025e1 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,10 @@ When Git 2.18 or higher is not in your PATH, falls back to the REST API to downl # running from unless specified. Example URLs are https://github.com or # https://my-ghes-server.example.com github-server-url: '' + + # Force usage of REST API for downloading ref, even if git is installed locally. + # Default: false + force-api-download: '' ``` diff --git a/__test__/git-auth-helper.test.ts b/__test__/git-auth-helper.test.ts index 2acec38..5066744 100644 --- a/__test__/git-auth-helper.test.ts +++ b/__test__/git-auth-helper.test.ts @@ -811,7 +811,8 @@ async function setup(testName: string): Promise { sshStrict: true, workflowOrganizationId: 123456, setSafeDirectory: true, - githubServerUrl: githubServerUrl + githubServerUrl: githubServerUrl, + forceApiDownload: false } } diff --git a/action.yml b/action.yml index cab09eb..f70d0ce 100644 --- a/action.yml +++ b/action.yml @@ -74,6 +74,10 @@ inputs: github-server-url: description: The base URL for the GitHub instance that you are trying to clone from, will use environment defaults to fetch from the same instance that the workflow is running from unless specified. Example URLs are https://github.com or https://my-ghes-server.example.com required: false + force-api-download: + description: Force usage of REST API for downloading ref, even if git is installed locally. + required: false + default: false runs: using: node16 main: dist/index.js diff --git a/dist/index.js b/dist/index.js index d1ed5f9..65d642f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7429,7 +7429,7 @@ function getSource(settings) { if (isExisting) { yield gitDirectoryHelper.prepareExistingDirectory(git, settings.repositoryPath, repositoryUrl, settings.clean, settings.ref); } - if (!git) { + if (!git || settings.forceApiDownload) { // Downloading using REST API core.info(`The repository will be downloaded using the GitHub REST API`); core.info(`To create a local Git repository instead, add Git ${gitCommandManager.MinimumGitVersion} or higher to the PATH`); @@ -17390,6 +17390,9 @@ function getInputs() { // Determine the GitHub URL that the repository is being hosted from result.githubServerUrl = core.getInput('github-server-url'); core.debug(`GitHub Host URL = ${result.githubServerUrl}`); + // Toggle force-api-download + result.forceApiDownload = + (core.getInput('force-api-download') || 'false').toUpperCase() === 'TRUE'; return result; }); } diff --git a/src/git-source-provider.ts b/src/git-source-provider.ts index 48f20da..e7e3f1e 100644 --- a/src/git-source-provider.ts +++ b/src/git-source-provider.ts @@ -71,7 +71,7 @@ export async function getSource(settings: IGitSourceSettings): Promise { ) } - if (!git) { + if (!git || settings.forceApiDownload) { // Downloading using REST API core.info(`The repository will be downloaded using the GitHub REST API`) core.info( diff --git a/src/git-source-settings.ts b/src/git-source-settings.ts index 2da5622..e45497b 100644 --- a/src/git-source-settings.ts +++ b/src/git-source-settings.ts @@ -88,4 +88,9 @@ export interface IGitSourceSettings { * User override on the GitHub Server/Host URL that hosts the repository to be cloned */ githubServerUrl: string | undefined + + /** + * Force the use of API download instead of git commands + */ + forceApiDownload: boolean } diff --git a/src/input-helper.ts b/src/input-helper.ts index 237b06a..fdbc334 100644 --- a/src/input-helper.ts +++ b/src/input-helper.ts @@ -130,5 +130,8 @@ export async function getInputs(): Promise { result.githubServerUrl = core.getInput('github-server-url') core.debug(`GitHub Host URL = ${result.githubServerUrl}`) + // Toggle force-api-download + result.forceApiDownload = + (core.getInput('force-api-download') || 'false').toUpperCase() === 'TRUE' return result }