mirror of
https://forgejo.stefka.eu/jiriks74/create-pull-request.git
synced 2025-01-18 16:01:06 +01:00
[CI] test built
This commit is contained in:
parent
6c704eb7a8
commit
c6f963d0ab
2 changed files with 25 additions and 5 deletions
29
dist/index.js
vendored
29
dist/index.js
vendored
|
@ -74,18 +74,30 @@ function tryFetch(git, remote, branch) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.tryFetch = tryFetch;
|
exports.tryFetch = tryFetch;
|
||||||
|
// Return the number of commits that branch2 is ahead of branch1
|
||||||
|
function commitsAhead(git, branch1, branch2) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const result = yield git.revList([`${branch1}...${branch2}`], ['--right-only', '--count']);
|
||||||
|
return Number(result);
|
||||||
|
});
|
||||||
|
}
|
||||||
// Return true if branch2 is ahead of branch1
|
// Return true if branch2 is ahead of branch1
|
||||||
function isAhead(git, branch1, branch2) {
|
function isAhead(git, branch1, branch2) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const result = yield git.revList([`${branch1}...${branch2}`], ['--right-only', '--count']);
|
return (yield commitsAhead(git, branch1, branch2)) > 0;
|
||||||
return Number(result) > 0;
|
});
|
||||||
|
}
|
||||||
|
// Return the number of commits that branch2 is behind branch1
|
||||||
|
function commitsBehind(git, branch1, branch2) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const result = yield git.revList([`${branch1}...${branch2}`], ['--left-only', '--count']);
|
||||||
|
return Number(result);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Return true if branch2 is behind branch1
|
// Return true if branch2 is behind branch1
|
||||||
function isBehind(git, branch1, branch2) {
|
function isBehind(git, branch1, branch2) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const result = yield git.revList([`${branch1}...${branch2}`], ['--left-only', '--count']);
|
return (yield commitsBehind(git, branch1, branch2)) > 0;
|
||||||
return Number(result) > 0;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Return true if branch2 is even with branch1
|
// Return true if branch2 is even with branch1
|
||||||
|
@ -214,9 +226,16 @@ function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName
|
||||||
// branches after merging. In particular, it catches a case where the branch was
|
// branches after merging. In particular, it catches a case where the branch was
|
||||||
// squash merged but not deleted. We need to reset to make sure it doesn't appear
|
// 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.
|
// to have a diff with the base due to different commits for the same changes.
|
||||||
|
// - If the number of commits ahead of the base branch differs between the branch and
|
||||||
|
// temp branch. This catches a case where the base branch has been force pushed to
|
||||||
|
// a new commit.
|
||||||
// For changes on base this reset is equivalent to a rebase of the pull request branch.
|
// For changes on base this reset is equivalent to a rebase of the pull request branch.
|
||||||
|
const tempBranchCommitsAhead = yield commitsAhead(git, base, tempBranch);
|
||||||
|
const branchCommitsAhead = yield commitsAhead(git, base, branch);
|
||||||
if ((yield git.hasDiff([`${branch}..${tempBranch}`])) ||
|
if ((yield git.hasDiff([`${branch}..${tempBranch}`])) ||
|
||||||
!(yield isAhead(git, base, tempBranch))) {
|
branchCommitsAhead != tempBranchCommitsAhead ||
|
||||||
|
!(tempBranchCommitsAhead > 0) // !isAhead
|
||||||
|
) {
|
||||||
core.info(`Resetting '${branch}'`);
|
core.info(`Resetting '${branch}'`);
|
||||||
// Alternatively, git switch -C branch tempBranch
|
// Alternatively, git switch -C branch tempBranch
|
||||||
yield git.checkout(branch, tempBranch);
|
yield git.checkout(branch, tempBranch);
|
||||||
|
|
1
report.txt
Normal file
1
report.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
1668146350
|
Loading…
Add table
Add a link
Reference in a new issue