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

Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
Tonye Jack 2024-03-26 13:12:21 -06:00 committed by GitHub
parent c6557ed000
commit 4bbd49b998
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 57 additions and 11 deletions

27
dist/index.js generated vendored
View File

@ -1748,8 +1748,7 @@ const getChangedFilesFromLocalGitHistory = (_a) => __awaiter(void 0, [_a], void
gitFetchExtraArgs = ['--prune', '--no-recurse-submodules'];
}
if (isFork) {
yield (0, utils_1.setForkRemote)({ cwd: workingDirectory });
remoteName = 'fork';
remoteName = yield (0, utils_1.setForkRemote)({ cwd: workingDirectory });
}
let diffResult;
if (!((_e = (_d = github.context.payload.pull_request) === null || _d === void 0 ? void 0 : _d.base) === null || _e === void 0 ? void 0 : _e.ref)) {
@ -2523,12 +2522,30 @@ const getParentSha = (_3) => __awaiter(void 0, [_3], void 0, function* ({ cwd })
return stdout.trim();
});
exports.getParentSha = getParentSha;
const setForkRemote = (_4) => __awaiter(void 0, [_4], void 0, function* ({ cwd }) {
var _5;
yield exec.getExecOutput('git', ['remote', 'add', 'fork', (_5 = github.context.payload.repository) === null || _5 === void 0 ? void 0 : _5.clone_url], {
const remoteExists = (cwd, remoteName) => __awaiter(void 0, void 0, void 0, function* () {
const { exitCode } = yield exec.getExecOutput('git', ['remote', 'get-url', remoteName], {
cwd,
ignoreReturnCode: true,
silent: !core.isDebug()
});
return exitCode === 0;
});
const setForkRemote = (_4) => __awaiter(void 0, [_4], void 0, function* ({ cwd }) {
var _5;
const remoteName = 'changed-files-fork';
const remoteFound = yield remoteExists(cwd, remoteName);
if (!remoteFound) {
yield exec.getExecOutput('git', [
'remote',
'add',
remoteName,
(_5 = github.context.payload.repository) === null || _5 === void 0 ? void 0 : _5.clone_url
], {
cwd,
silent: !core.isDebug()
});
}
return remoteName;
});
exports.setForkRemote = setForkRemote;
const verifyCommitSha = (_6) => __awaiter(void 0, [_6], void 0, function* ({ sha, cwd, showAsErrorMessage = true }) {

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -88,8 +88,7 @@ const getChangedFilesFromLocalGitHistory = async ({
}
if (isFork) {
await setForkRemote({cwd: workingDirectory})
remoteName = 'fork'
remoteName = await setForkRemote({cwd: workingDirectory})
}
let diffResult: DiffResult

View File

@ -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 ({