From d2a611248f09ceb00de1306eb79d8588d9acb22b Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 22 Jun 2023 21:41:47 -0600 Subject: [PATCH] Updated silent setting. --- src/changedFiles.ts | 28 +++++++++++++++++++++------- src/utils.ts | 38 +++++++++++++++++++------------------- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/src/changedFiles.ts b/src/changedFiles.ts index ee0d650fd17..640805e1019 100644 --- a/src/changedFiles.ts +++ b/src/changedFiles.ts @@ -278,7 +278,7 @@ export const getChangedFilesFromGithubAPI = async ({ core.info('Getting changed files from GitHub API...') for await (const response of octokit.paginate.iterator< - RestEndpointMethodTypes['pulls']['listFiles']['response']['data'] + RestEndpointMethodTypes['pulls']['listFiles']['response']['data'][0] >( octokit.pulls.listFiles.endpoint.merge({ owner: env.GITHUB_REPOSITORY_OWNER, @@ -287,12 +287,26 @@ export const getChangedFilesFromGithubAPI = async ({ per_page: 100 }) )) { - for (const paginatedItems of response.data) { - for (const item of paginatedItems) { - const changeType: ChangeTypeEnum = - item.status === 'removed' - ? ChangeTypeEnum.Deleted - : (item.status as ChangeTypeEnum) + if (response.status !== 200) { + throw new Error( + `Failed to get changed files from GitHub API. Status: ${response.status}` + ) + } + core.info(`Got ${response.data.length} changed files from GitHub API`) + for (const item of response.data) { + const changeType: ChangeTypeEnum = + item.status === 'removed' + ? ChangeTypeEnum.Deleted + : (item.status as ChangeTypeEnum) + + if (changeType === ChangeTypeEnum.Renamed) { + if (inputs.outputRenamedFilesAsDeletedAndAdded) { + changedFiles[ChangeTypeEnum.Deleted].push(item.filename) + changedFiles[ChangeTypeEnum.Added].push(item.filename) + } else { + changedFiles[ChangeTypeEnum.Renamed].push(item.filename) + } + } else { changedFiles[changeType].push(item.filename) } } diff --git a/src/utils.ts b/src/utils.ts index ab59ad5c77b..762ef952ee4 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -97,7 +97,7 @@ export const verifyMinimumGitVersion = async (): Promise => { const {exitCode, stdout, stderr} = await exec.getExecOutput( 'git', ['--version'], - {silent: process.env.RUNNER_DEBUG !== '1'} + {silent: !core.isDebug()} ) if (exitCode !== 0) { @@ -181,7 +181,7 @@ export const updateGitGlobalConfig = async ({ ['config', '--global', name, value], { ignoreReturnCode: true, - silent: process.env.RUNNER_DEBUG !== '1' + silent: !core.isDebug() } ) @@ -197,7 +197,7 @@ export const isRepoShallow = async ({cwd}: {cwd: string}): Promise => { ['rev-parse', '--is-shallow-repository'], { cwd, - silent: process.env.RUNNER_DEBUG !== '1' + silent: !core.isDebug() } ) @@ -215,7 +215,7 @@ export const submoduleExists = async ({ { cwd, ignoreReturnCode: true, - silent: process.env.RUNNER_DEBUG !== '1' + silent: !core.isDebug() } ) @@ -236,7 +236,7 @@ export const gitFetch = async ({ const {exitCode} = await exec.getExecOutput('git', ['fetch', '-q', ...args], { cwd, ignoreReturnCode: true, - silent: process.env.RUNNER_DEBUG !== '1' + silent: !core.isDebug() }) return exitCode @@ -255,7 +255,7 @@ export const gitFetchSubmodules = async ({ { cwd, ignoreReturnCode: true, - silent: process.env.RUNNER_DEBUG !== '1' + silent: !core.isDebug() } ) @@ -280,7 +280,7 @@ export const getSubmodulePath = async ({ { cwd, ignoreReturnCode: true, - silent: process.env.RUNNER_DEBUG !== '1' + silent: !core.isDebug() } ) @@ -313,7 +313,7 @@ export const gitSubmoduleDiffSHA = async ({ ['diff', parentSha1, parentSha2, '--', submodulePath], { cwd, - silent: process.env.RUNNER_DEBUG !== '1' + silent: !core.isDebug() } ) @@ -366,7 +366,7 @@ export const gitRenamedFiles = async ({ { cwd, ignoreReturnCode: true, - silent: process.env.RUNNER_DEBUG !== '1' + silent: !core.isDebug() } ) @@ -436,7 +436,7 @@ export const getAllChangedFiles = async ({ { cwd, ignoreReturnCode: true, - silent: process.env.RUNNER_DEBUG !== '1' + silent: !core.isDebug() } ) const changedFiles: ChangedFiles = { @@ -537,7 +537,7 @@ export const gitLog = async ({ }): Promise => { const {stdout} = await exec.getExecOutput('git', ['log', ...args], { cwd, - silent: process.env.RUNNER_DEBUG !== '1' + silent: !core.isDebug() }) return stdout.trim() @@ -546,7 +546,7 @@ export const gitLog = async ({ export const getHeadSha = async ({cwd}: {cwd: string}): Promise => { const {stdout} = await exec.getExecOutput('git', ['rev-parse', 'HEAD'], { cwd, - silent: process.env.RUNNER_DEBUG !== '1' + silent: !core.isDebug() }) return stdout.trim() @@ -564,7 +564,7 @@ export const getRemoteBranchHeadSha = async ({ ['rev-parse', `origin/${branch}`], { cwd, - silent: process.env.RUNNER_DEBUG !== '1' + silent: !core.isDebug() } ) @@ -578,7 +578,7 @@ export const getParentSha = async ({cwd}: {cwd: string}): Promise => { { cwd, ignoreReturnCode: true, - silent: process.env.RUNNER_DEBUG !== '1' + silent: !core.isDebug() } ) @@ -604,7 +604,7 @@ export const verifyCommitSha = async ({ { cwd, ignoreReturnCode: true, - silent: process.env.RUNNER_DEBUG !== '1' + silent: !core.isDebug() } ) @@ -634,7 +634,7 @@ export const getPreviousGitTag = async ({ ['tag', '--sort=-version:refname'], { cwd, - silent: process.env.RUNNER_DEBUG !== '1' + silent: !core.isDebug() } ) @@ -652,7 +652,7 @@ export const getPreviousGitTag = async ({ ['rev-parse', previousTag], { cwd, - silent: process.env.RUNNER_DEBUG !== '1' + silent: !core.isDebug() } ) @@ -678,7 +678,7 @@ export const canDiffCommits = async ({ { cwd, ignoreReturnCode: true, - silent: process.env.RUNNER_DEBUG !== '1' + silent: !core.isDebug() } ) @@ -1047,7 +1047,7 @@ const getDeletedFileContents = async ({ ['show', `${sha}:${filePath}`], { cwd, - silent: process.env.RUNNER_DEBUG !== '1', + silent: !core.isDebug(), ignoreReturnCode: true } )