Allow PR merge when GitHub reports it ready (#1172)
This commit is contained in:
@@ -226,6 +226,9 @@ describe("git-actions-policy", () => {
|
|||||||
"merge-from-base",
|
"merge-from-base",
|
||||||
"merge-branch",
|
"merge-branch",
|
||||||
"pr",
|
"pr",
|
||||||
|
"merge-pr-squash",
|
||||||
|
"merge-pr-merge",
|
||||||
|
"merge-pr-rebase",
|
||||||
]);
|
]);
|
||||||
expect(
|
expect(
|
||||||
actions.secondary.some((action) => action.id === "pr" && action.label === "View PR"),
|
actions.secondary.some((action) => action.id === "pr" && action.label === "View PR"),
|
||||||
@@ -324,6 +327,45 @@ describe("git-actions-policy", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("offers direct PR merge when GitHub says the PR is mergeable even if the local branch is behind", () => {
|
||||||
|
const actions = buildGitActions(
|
||||||
|
createInput({
|
||||||
|
hasRemote: true,
|
||||||
|
isOnBaseBranch: false,
|
||||||
|
aheadCount: 2,
|
||||||
|
behindBaseCount: 3,
|
||||||
|
aheadOfOrigin: 0,
|
||||||
|
behindOfOrigin: 2,
|
||||||
|
hasPullRequest: true,
|
||||||
|
pullRequestUrl: "https://example.com/pr/456",
|
||||||
|
pullRequestState: "open",
|
||||||
|
pullRequestMergeable: "MERGEABLE",
|
||||||
|
pullRequestGithub: githubStatus({ mergeStateStatus: "CLEAN" }),
|
||||||
|
shipDefault: "pr",
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(actions.secondary).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: "merge-pr-squash",
|
||||||
|
disabled: false,
|
||||||
|
unavailableMessage: undefined,
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
id: "merge-pr-merge",
|
||||||
|
disabled: false,
|
||||||
|
unavailableMessage: undefined,
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
id: "merge-pr-rebase",
|
||||||
|
disabled: false,
|
||||||
|
unavailableMessage: undefined,
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("respects the ship preference when choosing between PR merge and local merge", () => {
|
it("respects the ship preference when choosing between PR merge and local merge", () => {
|
||||||
const prPreferredActions = buildGitActions(
|
const prPreferredActions = buildGitActions(
|
||||||
createInput({
|
createInput({
|
||||||
|
|||||||
@@ -504,7 +504,7 @@ function canMergeFromBase(input: BuildGitActionsInput): boolean {
|
|||||||
|
|
||||||
function canMergePr(input: BuildGitActionsInput): boolean {
|
function canMergePr(input: BuildGitActionsInput): boolean {
|
||||||
const github = input.pullRequestGithub;
|
const github = input.pullRequestGithub;
|
||||||
const canMergeFromTopLevelStatus =
|
const canMergeFromPullRequestStatus =
|
||||||
input.githubFeaturesEnabled &&
|
input.githubFeaturesEnabled &&
|
||||||
input.hasPullRequest &&
|
input.hasPullRequest &&
|
||||||
input.pullRequestState === "open" &&
|
input.pullRequestState === "open" &&
|
||||||
@@ -512,17 +512,19 @@ function canMergePr(input: BuildGitActionsInput): boolean {
|
|||||||
!input.pullRequestIsMerged &&
|
!input.pullRequestIsMerged &&
|
||||||
input.pullRequestMergeable !== "CONFLICTING" &&
|
input.pullRequestMergeable !== "CONFLICTING" &&
|
||||||
input.aheadCount > 0 &&
|
input.aheadCount > 0 &&
|
||||||
!input.hasUncommittedChanges &&
|
!input.hasUncommittedChanges;
|
||||||
input.behindOfOrigin === 0 &&
|
|
||||||
input.aheadOfOrigin === 0 &&
|
|
||||||
!canMergeFromBase(input);
|
|
||||||
|
|
||||||
if (!canMergeFromTopLevelStatus) {
|
if (!canMergeFromPullRequestStatus) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasPullRequestGithubFacts(github)) {
|
if (!hasPullRequestGithubFacts(github)) {
|
||||||
return input.pullRequestMergeable === "MERGEABLE";
|
return (
|
||||||
|
input.pullRequestMergeable === "MERGEABLE" &&
|
||||||
|
input.behindOfOrigin === 0 &&
|
||||||
|
input.aheadOfOrigin === 0 &&
|
||||||
|
!canMergeFromBase(input)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user