Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure the fork remote doesn't exists before creating it #2012

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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