Skip to content

Commit

Permalink
fix: ensure the fork remote doesnt exists before creating it
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 committed Mar 26, 2024
1 parent c6557ed commit 44c20c0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
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 44c20c0

Please sign in to comment.