Skip to content

Commit

Permalink
fix: ensure the fork remote doesn't exists before creating it (#2012)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
jackton1 and actions-user committed Mar 26, 2024
1 parent c6557ed commit 4bbd49b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 11 deletions.
27 changes: 22 additions & 5 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ const getChangedFilesFromLocalGitHistory = async ({
}

if (isFork) {
await setForkRemote({cwd: workingDirectory})
remoteName = 'fork'
remoteName = await setForkRemote({cwd: workingDirectory})
}

let diffResult: DiffResult
Expand Down
36 changes: 33 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -744,15 +744,45 @@ export const getParentSha = async ({cwd}: {cwd: string}): Promise<string> => {
return stdout.trim()
}

export const setForkRemote = async ({cwd}: {cwd: string}): Promise<void> => {
await exec.getExecOutput(
const remoteExists = async (
cwd: string,
remoteName: string
): Promise<boolean> => {
const {exitCode} = await exec.getExecOutput(
'git',
['remote', 'add', 'fork', github.context.payload.repository?.clone_url],
['remote', 'get-url', remoteName],
{
cwd,
ignoreReturnCode: true,
silent: !core.isDebug()
}
)

return exitCode === 0
}

export const setForkRemote = async ({cwd}: {cwd: string}): Promise<string> => {
const remoteName = 'changed-files-fork'

const remoteFound = await remoteExists(cwd, remoteName)

if (!remoteFound) {
await exec.getExecOutput(
'git',
[
'remote',
'add',
remoteName,
github.context.payload.repository?.clone_url
],
{
cwd,
silent: !core.isDebug()
}
)
}

return remoteName
}

export const verifyCommitSha = async ({
Expand Down

0 comments on commit 4bbd49b

Please sign in to comment.