mirror of
https://github.com/peter-evans/create-pull-request.git
synced 2026-12-03 04:49:02 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
45c510e1f6 | ||
|
|
249b80db6b | ||
|
|
6c2b44c6ac | ||
|
|
76c58cf6a9 | ||
|
|
8c603dbb04 | ||
|
|
d01e0807ef | ||
|
|
ce699aa2d1 | ||
|
|
9984f611a7 | ||
|
|
ff0beed1b2 | ||
|
|
ddeca94037 | ||
|
|
0fd77ba8cc |
No files matched your search
Vendored
+41
-28
@@ -93,12 +93,6 @@ function isEven(git, branch1, branch2) {
|
||||
!(yield isBehind(git, branch1, branch2)));
|
||||
});
|
||||
}
|
||||
function hasDiff(git, branch1, branch2) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const result = yield git.diff([`${branch1}..${branch2}`]);
|
||||
return result.length > 0;
|
||||
});
|
||||
}
|
||||
function splitLines(multilineString) {
|
||||
return multilineString
|
||||
.split('\n')
|
||||
@@ -140,8 +134,19 @@ function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName
|
||||
// Perform fetch and reset the working base
|
||||
// Commits made during the workflow will be removed
|
||||
if (workingBaseType == WorkingBaseType.Branch) {
|
||||
core.info(`Resetting working base branch '${workingBase}' to its remote`);
|
||||
yield git.fetch([`${workingBase}:${workingBase}`], baseRemote, ['--force']);
|
||||
core.info(`Resetting working base branch '${workingBase}'`);
|
||||
if (branchRemoteName == 'fork') {
|
||||
// If pushing to a fork we must fetch with 'unshallow' to avoid the following error on git push
|
||||
// ! [remote rejected] HEAD -> tests/push-branch-to-fork (shallow update not allowed)
|
||||
yield git.fetch([`${workingBase}:${workingBase}`], baseRemote, [
|
||||
'--force'
|
||||
]);
|
||||
}
|
||||
else {
|
||||
// If the remote is 'origin' we can git reset
|
||||
yield git.checkout(workingBase);
|
||||
yield git.exec(['reset', '--hard', `${baseRemote}/${workingBase}`]);
|
||||
}
|
||||
}
|
||||
// If the working base is not the base, rebase the temp branch commits
|
||||
// This will also be true if the working base type is a commit
|
||||
@@ -168,7 +173,7 @@ function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName
|
||||
// The pull request branch does not exist
|
||||
core.info(`Pull request branch '${branch}' does not exist yet.`);
|
||||
// Create the pull request branch
|
||||
yield git.checkout(branch, 'HEAD');
|
||||
yield git.checkout(branch, tempBranch);
|
||||
// Check if the pull request branch is ahead of the base
|
||||
result.hasDiffWithBase = yield isAhead(git, base, branch);
|
||||
if (result.hasDiffWithBase) {
|
||||
@@ -192,7 +197,7 @@ function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName
|
||||
// squash merged but not deleted. We need to reset to make sure it doesn't appear
|
||||
// to have a diff with the base due to different commits for the same changes.
|
||||
// For changes on base this reset is equivalent to a rebase of the pull request branch.
|
||||
if ((yield hasDiff(git, branch, tempBranch)) ||
|
||||
if ((yield git.hasDiff([`${branch}..${tempBranch}`])) ||
|
||||
!(yield isAhead(git, base, tempBranch))) {
|
||||
core.info(`Resetting '${branch}'`);
|
||||
// Alternatively, git switch -C branch tempBranch
|
||||
@@ -321,6 +326,12 @@ function createPullRequest(inputs) {
|
||||
if (branchRemoteName == 'origin' && base == inputs.branch) {
|
||||
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();
|
||||
// Apply the branch suffix if set
|
||||
if (inputs.branchSuffix) {
|
||||
@@ -662,16 +673,6 @@ class GitCommandManager {
|
||||
return output.exitCode === 0;
|
||||
});
|
||||
}
|
||||
diff(options) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const args = ['-c', 'core.pager=cat', 'diff'];
|
||||
if (options) {
|
||||
args.push(...options);
|
||||
}
|
||||
const output = yield this.exec(args);
|
||||
return output.stdout.trim();
|
||||
});
|
||||
}
|
||||
fetch(refSpec, remoteName, options) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const args = ['-c', 'protocol.version=2', 'fetch'];
|
||||
@@ -712,19 +713,28 @@ class GitCommandManager {
|
||||
getWorkingDirectory() {
|
||||
return this.workingDirectory;
|
||||
}
|
||||
hasDiff(options) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const args = ['diff', '--quiet'];
|
||||
if (options) {
|
||||
args.push(...options);
|
||||
}
|
||||
const output = yield this.exec(args, true);
|
||||
return output.exitCode === 1;
|
||||
});
|
||||
}
|
||||
isDirty(untracked) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const diffArgs = ['--abbrev=40', '--full-index', '--raw'];
|
||||
// Check staged changes
|
||||
if (yield this.diff([...diffArgs, '--staged'])) {
|
||||
// Check untracked changes
|
||||
if (untracked && (yield this.status(['--porcelain', '-unormal']))) {
|
||||
return true;
|
||||
}
|
||||
// Check working index changes
|
||||
if (yield this.diff(diffArgs)) {
|
||||
if (yield this.hasDiff()) {
|
||||
return true;
|
||||
}
|
||||
// Check untracked changes
|
||||
if (untracked && (yield this.status(['--porcelain', '-unormal']))) {
|
||||
// Check staged changes
|
||||
if (yield this.hasDiff(['--staged'])) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -912,8 +922,11 @@ class GitHubHelper {
|
||||
};
|
||||
}
|
||||
catch (e) {
|
||||
if (!e.message ||
|
||||
!e.message.includes(`A pull request already exists for ${headBranch}`)) {
|
||||
if (e.message &&
|
||||
e.message.includes(`A pull request already exists for ${headBranch}`)) {
|
||||
core.info(`A pull request already exists for ${headBranch}`);
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
- [Misc workflow tips](#misc-workflow-tips)
|
||||
- [Filtering push events](#filtering-push-events)
|
||||
- [Dynamic configuration using variables](#dynamic-configuration-using-variables)
|
||||
- [Setting the pull request body from a file](#setting-the-pull-request-body-from-a-file)
|
||||
- [Debugging GitHub Actions](#debugging-github-actions)
|
||||
|
||||
|
||||
|
||||
Generated
+3
-3
@@ -5764,9 +5764,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"node-notifier": {
|
||||
"version": "8.0.0",
|
||||
"resolved": "https://registry.npmjs.org/node-notifier/-/node-notifier-8.0.0.tgz",
|
||||
"integrity": "sha512-46z7DUmcjoYdaWyXouuFNNfUo6eFa94t23c53c+lG/9Cvauk4a98rAUp9672X5dxGdQmLpPzTxzu8f/OeEPaFA==",
|
||||
"version": "8.0.1",
|
||||
"resolved": "https://registry.npmjs.org/node-notifier/-/node-notifier-8.0.1.tgz",
|
||||
"integrity": "sha512-BvEXF+UmsnAfYfoapKM9nGxnP+Wn7P91YfXmrKnfcYCx6VBeoN5Ez5Ogck6I8Bi5k4RlpqRYaw75pAwzX9OphA==",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
|
||||
@@ -78,15 +78,6 @@ async function isEven(
|
||||
)
|
||||
}
|
||||
|
||||
async function hasDiff(
|
||||
git: GitCommandManager,
|
||||
branch1: string,
|
||||
branch2: string
|
||||
): Promise<boolean> {
|
||||
const result = await git.diff([`${branch1}..${branch2}`])
|
||||
return result.length > 0
|
||||
}
|
||||
|
||||
function splitLines(multilineString: string): string[] {
|
||||
return multilineString
|
||||
.split('\n')
|
||||
@@ -139,8 +130,18 @@ export async function createOrUpdateBranch(
|
||||
// Perform fetch and reset the working base
|
||||
// Commits made during the workflow will be removed
|
||||
if (workingBaseType == WorkingBaseType.Branch) {
|
||||
core.info(`Resetting working base branch '${workingBase}' to its remote`)
|
||||
await git.fetch([`${workingBase}:${workingBase}`], baseRemote, ['--force'])
|
||||
core.info(`Resetting working base branch '${workingBase}'`)
|
||||
if (branchRemoteName == 'fork') {
|
||||
// If pushing to a fork we must fetch with 'unshallow' to avoid the following error on git push
|
||||
// ! [remote rejected] HEAD -> tests/push-branch-to-fork (shallow update not allowed)
|
||||
await git.fetch([`${workingBase}:${workingBase}`], baseRemote, [
|
||||
'--force'
|
||||
])
|
||||
} else {
|
||||
// If the remote is 'origin' we can git reset
|
||||
await git.checkout(workingBase)
|
||||
await git.exec(['reset', '--hard', `${baseRemote}/${workingBase}`])
|
||||
}
|
||||
}
|
||||
|
||||
// If the working base is not the base, rebase the temp branch commits
|
||||
@@ -177,7 +178,7 @@ export async function createOrUpdateBranch(
|
||||
// The pull request branch does not exist
|
||||
core.info(`Pull request branch '${branch}' does not exist yet.`)
|
||||
// Create the pull request branch
|
||||
await git.checkout(branch, 'HEAD')
|
||||
await git.checkout(branch, tempBranch)
|
||||
// Check if the pull request branch is ahead of the base
|
||||
result.hasDiffWithBase = await isAhead(git, base, branch)
|
||||
if (result.hasDiffWithBase) {
|
||||
@@ -205,7 +206,7 @@ export async function createOrUpdateBranch(
|
||||
// to have a diff with the base due to different commits for the same changes.
|
||||
// For changes on base this reset is equivalent to a rebase of the pull request branch.
|
||||
if (
|
||||
(await hasDiff(git, branch, tempBranch)) ||
|
||||
(await git.hasDiff([`${branch}..${tempBranch}`])) ||
|
||||
!(await isAhead(git, base, tempBranch))
|
||||
) {
|
||||
core.info(`Resetting '${branch}'`)
|
||||
|
||||
@@ -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.`
|
||||
)
|
||||
}
|
||||
// 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()
|
||||
|
||||
// Apply the branch suffix if set
|
||||
|
||||
+14
-15
@@ -96,15 +96,6 @@ export class GitCommandManager {
|
||||
return output.exitCode === 0
|
||||
}
|
||||
|
||||
async diff(options?: string[]): Promise<string> {
|
||||
const args = ['-c', 'core.pager=cat', 'diff']
|
||||
if (options) {
|
||||
args.push(...options)
|
||||
}
|
||||
const output = await this.exec(args)
|
||||
return output.stdout.trim()
|
||||
}
|
||||
|
||||
async fetch(
|
||||
refSpec: string[],
|
||||
remoteName?: string,
|
||||
@@ -153,18 +144,26 @@ export class GitCommandManager {
|
||||
return this.workingDirectory
|
||||
}
|
||||
|
||||
async hasDiff(options?: string[]): Promise<boolean> {
|
||||
const args = ['diff', '--quiet']
|
||||
if (options) {
|
||||
args.push(...options)
|
||||
}
|
||||
const output = await this.exec(args, true)
|
||||
return output.exitCode === 1
|
||||
}
|
||||
|
||||
async isDirty(untracked: boolean): Promise<boolean> {
|
||||
const diffArgs = ['--abbrev=40', '--full-index', '--raw']
|
||||
// Check staged changes
|
||||
if (await this.diff([...diffArgs, '--staged'])) {
|
||||
// Check untracked changes
|
||||
if (untracked && (await this.status(['--porcelain', '-unormal']))) {
|
||||
return true
|
||||
}
|
||||
// Check working index changes
|
||||
if (await this.diff(diffArgs)) {
|
||||
if (await this.hasDiff()) {
|
||||
return true
|
||||
}
|
||||
// Check untracked changes
|
||||
if (untracked && (await this.status(['--porcelain', '-unormal']))) {
|
||||
// Check staged changes
|
||||
if (await this.hasDiff(['--staged'])) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
@@ -58,9 +58,11 @@ export class GitHubHelper {
|
||||
}
|
||||
} catch (e) {
|
||||
if (
|
||||
!e.message ||
|
||||
!e.message.includes(`A pull request already exists for ${headBranch}`)
|
||||
e.message &&
|
||||
e.message.includes(`A pull request already exists for ${headBranch}`)
|
||||
) {
|
||||
core.info(`A pull request already exists for ${headBranch}`)
|
||||
} else {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user