Compare commits

...

4 Commits

Author SHA1 Message Date
8c603dbb04 Merge pull request #653 from peter-evans/fix-error-handling
fix: change or->and to catch all errors
2020-12-09 09:56:23 +09:00
d01e0807ef fix: change or->and to catch all errors 2020-12-09 09:38:10 +09:00
ce699aa2d1 Merge pull request #637 from peter-evans/prune-remote
fix: prune stale remote ref for self-hosted runners
2020-11-25 12:40:23 +09:00
9984f611a7 fix: prune stale remote ref for self-hosted runners 2020-11-24 12:34:57 +09:00
3 changed files with 21 additions and 4 deletions

13
dist/index.js vendored
View File

@ -315,6 +315,12 @@ function createPullRequest(inputs) {
if (branchRemoteName == 'origin' && base == inputs.branch) { if (branchRemoteName == 'origin' && base == inputs.branch) {
throw new Error(`The 'base' and 'branch' for a pull request must be different branches. Unable to continue.`); throw new Error(`The 'base' and 'branch' for a pull request must be different branches. Unable to continue.`);
} }
// For self-hosted runners the repository state persists between runs.
// This command prunes the stale remote ref when the pull request branch was
// deleted after being merged or closed. Without this the push using
// '--force-with-lease' fails due to "stale info."
// https://github.com/peter-evans/create-pull-request/issues/633
yield git.exec(['remote', 'prune', branchRemoteName]);
core.endGroup(); core.endGroup();
// Apply the branch suffix if set // Apply the branch suffix if set
if (inputs.branchSuffix) { if (inputs.branchSuffix) {
@ -905,8 +911,11 @@ class GitHubHelper {
}; };
} }
catch (e) { catch (e) {
if (!e.message || if (e.message &&
!e.message.includes(`A pull request already exists for ${headBranch}`)) { e.message.includes(`A pull request already exists for ${headBranch}`)) {
core.info(`A pull request already exists for ${headBranch}`);
}
else {
throw e; throw e;
} }
} }

View File

@ -106,6 +106,12 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
`The 'base' and 'branch' for a pull request must be different branches. Unable to continue.` `The 'base' and 'branch' for a pull request must be different branches. Unable to continue.`
) )
} }
// For self-hosted runners the repository state persists between runs.
// This command prunes the stale remote ref when the pull request branch was
// deleted after being merged or closed. Without this the push using
// '--force-with-lease' fails due to "stale info."
// https://github.com/peter-evans/create-pull-request/issues/633
await git.exec(['remote', 'prune', branchRemoteName])
core.endGroup() core.endGroup()
// Apply the branch suffix if set // Apply the branch suffix if set

View File

@ -58,9 +58,11 @@ export class GitHubHelper {
} }
} catch (e) { } catch (e) {
if ( if (
!e.message || e.message &&
!e.message.includes(`A pull request already exists for ${headBranch}`) e.message.includes(`A pull request already exists for ${headBranch}`)
) { ) {
core.info(`A pull request already exists for ${headBranch}`)
} else {
throw e throw e
} }
} }