mirror of
https://github.com/peter-evans/create-pull-request.git
synced 2026-05-15 02:54:48 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8c603dbb04 | |||
| d01e0807ef | |||
| ce699aa2d1 | |||
| 9984f611a7 | |||
| ff0beed1b2 | |||
| ddeca94037 | |||
| 0fd77ba8cc |
Vendored
+27
-25
@@ -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')
|
||||
@@ -192,7 +186,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 +315,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 +662,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 +702,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 +911,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)
|
||||
|
||||
|
||||
|
||||
@@ -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')
|
||||
@@ -205,7 +196,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