| 
									
										
										
										
											2019-12-03 10:28:59 -05:00
										 |  |  | import * as core from '@actions/core' | 
					
						
							|  |  |  | import * as fsHelper from './fs-helper' | 
					
						
							|  |  |  | import * as github from '@actions/github' | 
					
						
							|  |  |  | import * as path from 'path' | 
					
						
							| 
									
										
										
										
											2021-11-01 11:43:18 -05:00
										 |  |  | import * as workflowContextHelper from './workflow-context-helper' | 
					
						
							| 
									
										
										
										
											2020-03-02 11:33:30 -05:00
										 |  |  | import {IGitSourceSettings} from './git-source-settings' | 
					
						
							| 
									
										
										
										
											2019-12-03 10:28:59 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-01 11:43:18 -05:00
										 |  |  | export async function getInputs(): Promise<IGitSourceSettings> { | 
					
						
							| 
									
										
										
										
											2020-03-02 11:33:30 -05:00
										 |  |  |   const result = ({} as unknown) as IGitSourceSettings | 
					
						
							| 
									
										
										
										
											2019-12-03 10:28:59 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // GitHub workspace
 | 
					
						
							|  |  |  |   let githubWorkspacePath = process.env['GITHUB_WORKSPACE'] | 
					
						
							|  |  |  |   if (!githubWorkspacePath) { | 
					
						
							|  |  |  |     throw new Error('GITHUB_WORKSPACE not defined') | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   githubWorkspacePath = path.resolve(githubWorkspacePath) | 
					
						
							|  |  |  |   core.debug(`GITHUB_WORKSPACE = '${githubWorkspacePath}'`) | 
					
						
							|  |  |  |   fsHelper.directoryExistsSync(githubWorkspacePath, true) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Qualified repository
 | 
					
						
							|  |  |  |   const qualifiedRepository = | 
					
						
							|  |  |  |     core.getInput('repository') || | 
					
						
							|  |  |  |     `${github.context.repo.owner}/${github.context.repo.repo}` | 
					
						
							|  |  |  |   core.debug(`qualified repository = '${qualifiedRepository}'`) | 
					
						
							|  |  |  |   const splitRepository = qualifiedRepository.split('/') | 
					
						
							|  |  |  |   if ( | 
					
						
							|  |  |  |     splitRepository.length !== 2 || | 
					
						
							|  |  |  |     !splitRepository[0] || | 
					
						
							|  |  |  |     !splitRepository[1] | 
					
						
							|  |  |  |   ) { | 
					
						
							|  |  |  |     throw new Error( | 
					
						
							|  |  |  |       `Invalid repository '${qualifiedRepository}'. Expected format {owner}/{repo}.` | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   result.repositoryOwner = splitRepository[0] | 
					
						
							|  |  |  |   result.repositoryName = splitRepository[1] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Repository path
 | 
					
						
							|  |  |  |   result.repositoryPath = core.getInput('path') || '.' | 
					
						
							|  |  |  |   result.repositoryPath = path.resolve( | 
					
						
							|  |  |  |     githubWorkspacePath, | 
					
						
							|  |  |  |     result.repositoryPath | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  |   if ( | 
					
						
							|  |  |  |     !(result.repositoryPath + path.sep).startsWith( | 
					
						
							|  |  |  |       githubWorkspacePath + path.sep | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |   ) { | 
					
						
							|  |  |  |     throw new Error( | 
					
						
							|  |  |  |       `Repository path '${result.repositoryPath}' is not under '${githubWorkspacePath}'` | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Workflow repository?
 | 
					
						
							|  |  |  |   const isWorkflowRepository = | 
					
						
							|  |  |  |     qualifiedRepository.toUpperCase() === | 
					
						
							|  |  |  |     `${github.context.repo.owner}/${github.context.repo.repo}`.toUpperCase() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Source branch, source version
 | 
					
						
							|  |  |  |   result.ref = core.getInput('ref') | 
					
						
							|  |  |  |   if (!result.ref) { | 
					
						
							|  |  |  |     if (isWorkflowRepository) { | 
					
						
							|  |  |  |       result.ref = github.context.ref | 
					
						
							|  |  |  |       result.commit = github.context.sha | 
					
						
							| 
									
										
										
										
											2020-01-21 14:17:04 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |       // Some events have an unqualifed ref. For example when a PR is merged (pull_request closed event),
 | 
					
						
							| 
									
										
										
										
											2020-07-14 09:23:30 -04:00
										 |  |  |       // the ref is unqualifed like "main" instead of "refs/heads/main".
 | 
					
						
							| 
									
										
										
										
											2020-01-21 14:17:04 -05:00
										 |  |  |       if (result.commit && result.ref && !result.ref.startsWith('refs/')) { | 
					
						
							|  |  |  |         result.ref = `refs/heads/${result.ref}` | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-12-03 10:28:59 -05:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   // SHA?
 | 
					
						
							|  |  |  |   else if (result.ref.match(/^[0-9a-fA-F]{40}$/)) { | 
					
						
							|  |  |  |     result.commit = result.ref | 
					
						
							|  |  |  |     result.ref = '' | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   core.debug(`ref = '${result.ref}'`) | 
					
						
							|  |  |  |   core.debug(`commit = '${result.commit}'`) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Clean
 | 
					
						
							|  |  |  |   result.clean = (core.getInput('clean') || 'true').toUpperCase() === 'TRUE' | 
					
						
							|  |  |  |   core.debug(`clean = ${result.clean}`) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-22 18:30:36 +01:00
										 |  |  |   // Filter
 | 
					
						
							|  |  |  |   const filter = core.getInput('filter') | 
					
						
							|  |  |  |   if (filter) { | 
					
						
							|  |  |  |     result.filter = filter | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   core.debug(`filter = ${result.filter}`) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-09 15:08:21 +02:00
										 |  |  |   // Sparse checkout
 | 
					
						
							|  |  |  |   const sparseCheckout = core.getMultilineInput('sparse-checkout') | 
					
						
							|  |  |  |   if (sparseCheckout.length) { | 
					
						
							|  |  |  |     result.sparseCheckout = sparseCheckout | 
					
						
							|  |  |  |     core.debug(`sparse checkout = ${result.sparseCheckout}`) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   result.sparseCheckoutConeMode = | 
					
						
							|  |  |  |     (core.getInput('sparse-checkout-cone-mode') || 'true').toUpperCase() === | 
					
						
							|  |  |  |     'TRUE' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-03 10:28:59 -05:00
										 |  |  |   // Fetch depth
 | 
					
						
							|  |  |  |   result.fetchDepth = Math.floor(Number(core.getInput('fetch-depth') || '1')) | 
					
						
							|  |  |  |   if (isNaN(result.fetchDepth) || result.fetchDepth < 0) { | 
					
						
							|  |  |  |     result.fetchDepth = 0 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   core.debug(`fetch depth = ${result.fetchDepth}`) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-16 22:34:54 +02:00
										 |  |  |   // Fetch tags
 | 
					
						
							|  |  |  |   result.fetchTags = | 
					
						
							|  |  |  |     (core.getInput('fetch-tags') || 'false').toUpperCase() === 'TRUE' | 
					
						
							|  |  |  |   core.debug(`fetch tags = ${result.fetchTags}`) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-01 14:19:18 -04:00
										 |  |  |   // Show fetch progress
 | 
					
						
							|  |  |  |   result.showProgress = | 
					
						
							|  |  |  |     (core.getInput('show-progress') || 'true').toUpperCase() === 'TRUE' | 
					
						
							|  |  |  |   core.debug(`show progress = ${result.showProgress}`) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-03 10:28:59 -05:00
										 |  |  |   // LFS
 | 
					
						
							|  |  |  |   result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE' | 
					
						
							|  |  |  |   core.debug(`lfs = ${result.lfs}`) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-05 14:21:59 -05:00
										 |  |  |   // Submodules
 | 
					
						
							|  |  |  |   result.submodules = false | 
					
						
							|  |  |  |   result.nestedSubmodules = false | 
					
						
							|  |  |  |   const submodulesString = (core.getInput('submodules') || '').toUpperCase() | 
					
						
							|  |  |  |   if (submodulesString == 'RECURSIVE') { | 
					
						
							|  |  |  |     result.submodules = true | 
					
						
							|  |  |  |     result.nestedSubmodules = true | 
					
						
							|  |  |  |   } else if (submodulesString == 'TRUE') { | 
					
						
							|  |  |  |     result.submodules = true | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   core.debug(`submodules = ${result.submodules}`) | 
					
						
							|  |  |  |   core.debug(`recursive submodules = ${result.nestedSubmodules}`) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-12 13:49:26 -05:00
										 |  |  |   // Auth token
 | 
					
						
							| 
									
										
										
										
											2020-06-16 13:41:01 -04:00
										 |  |  |   result.authToken = core.getInput('token', {required: true}) | 
					
						
							| 
									
										
										
										
											2019-12-12 13:49:26 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-11 15:55:17 -04:00
										 |  |  |   // SSH
 | 
					
						
							|  |  |  |   result.sshKey = core.getInput('ssh-key') | 
					
						
							|  |  |  |   result.sshKnownHosts = core.getInput('ssh-known-hosts') | 
					
						
							|  |  |  |   result.sshStrict = | 
					
						
							|  |  |  |     (core.getInput('ssh-strict') || 'true').toUpperCase() === 'TRUE' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-12 13:49:26 -05:00
										 |  |  |   // Persist credentials
 | 
					
						
							|  |  |  |   result.persistCredentials = | 
					
						
							|  |  |  |     (core.getInput('persist-credentials') || 'false').toUpperCase() === 'TRUE' | 
					
						
							| 
									
										
										
										
											2019-12-03 10:28:59 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-01 11:43:18 -05:00
										 |  |  |   // Workflow organization ID
 | 
					
						
							|  |  |  |   result.workflowOrganizationId = await workflowContextHelper.getOrganizationId() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-20 21:37:43 -04:00
										 |  |  |   // Set safe.directory in git global config.
 | 
					
						
							|  |  |  |   result.setSafeDirectory = | 
					
						
							|  |  |  |     (core.getInput('set-safe-directory') || 'true').toUpperCase() === 'TRUE' | 
					
						
							| 
									
										
										
										
											2022-09-26 17:34:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // 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}`) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-03 10:28:59 -05:00
										 |  |  |   return result | 
					
						
							|  |  |  | } |