Reject same-repo PRs for cross-repo heads
This commit is contained in:
1 parent
eb9b509af8
commit
32358fd7e2
2 files changed
+58
-8
No files matched your search
@@ -23,7 +23,7 @@ import {
|
||||
import { type TextGenerationShape, TextGeneration } from "../Services/TextGeneration.ts";
|
||||
import { GitCoreLive } from "./GitCore.ts";
|
||||
import { GitCore } from "../Services/GitCore.ts";
|
||||
import { makeGitManager } from "./GitManager.ts";
|
||||
import { makeGitManager, matchesBranchHeadContext } from "./GitManager.ts";
|
||||
import { ServerConfig } from "../../config.ts";
|
||||
import { ServerSettingsService } from "../../serverSettings.ts";
|
||||
import {
|
||||
@@ -2101,6 +2101,53 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
12_000,
|
||||
);
|
||||
|
||||
it.effect("rejects same-repo PR metadata when matching a cross-repo head context", () =>
|
||||
Effect.sync(() => {
|
||||
const headContext = {
|
||||
headBranch: "statemachine",
|
||||
headRepositoryNameWithOwner: "pingdotgg/codething-mvp",
|
||||
headRepositoryOwnerLogin: "pingdotgg",
|
||||
isCrossRepository: true,
|
||||
};
|
||||
|
||||
expect(
|
||||
matchesBranchHeadContext(
|
||||
{
|
||||
number: 41,
|
||||
title: "Same-repo PR",
|
||||
url: "https://github.com/pingdotgg/codething-mvp/pull/41",
|
||||
baseRefName: "main",
|
||||
headRefName: "statemachine",
|
||||
state: "open",
|
||||
updatedAt: null,
|
||||
isCrossRepository: false,
|
||||
headRepositoryNameWithOwner: "pingdotgg/codething-mvp",
|
||||
headRepositoryOwnerLogin: "pingdotgg",
|
||||
},
|
||||
headContext,
|
||||
),
|
||||
).toBe(false);
|
||||
|
||||
expect(
|
||||
matchesBranchHeadContext(
|
||||
{
|
||||
number: 142,
|
||||
title: "Fork PR",
|
||||
url: "https://github.com/pingdotgg/codething-mvp/pull/142",
|
||||
baseRefName: "main",
|
||||
headRefName: "statemachine",
|
||||
state: "open",
|
||||
updatedAt: null,
|
||||
isCrossRepository: true,
|
||||
headRepositoryNameWithOwner: "pingdotgg/codething-mvp",
|
||||
headRepositoryOwnerLogin: "pingdotgg",
|
||||
},
|
||||
headContext,
|
||||
),
|
||||
).toBe(true);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("creates PR when one does not already exist", () =>
|
||||
Effect.gen(function* () {
|
||||
const repoDir = yield* makeTempDir("t3code-git-manager-");
|
||||
|
||||
@@ -235,7 +235,7 @@ function resolvePullRequestHeadIdentity(pr: PullRequestInfo): PullRequestHeadIde
|
||||
};
|
||||
}
|
||||
|
||||
function matchesBranchHeadContext(
|
||||
export function matchesBranchHeadContext(
|
||||
pr: PullRequestInfo,
|
||||
headContext: Pick<
|
||||
BranchHeadContext,
|
||||
@@ -251,18 +251,21 @@ function matchesBranchHeadContext(
|
||||
|
||||
if (expectedHead.repositoryNameWithOwner) {
|
||||
if (pullRequestHead.repositoryNameWithOwner) {
|
||||
return expectedHead.repositoryNameWithOwner === pullRequestHead.repositoryNameWithOwner;
|
||||
if (expectedHead.repositoryNameWithOwner !== pullRequestHead.repositoryNameWithOwner) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (expectedHead.ownerLogin && pullRequestHead.ownerLogin) {
|
||||
return expectedHead.ownerLogin === pullRequestHead.ownerLogin;
|
||||
}
|
||||
if (pr.isCrossRepository === true) {
|
||||
return false;
|
||||
if (expectedHead.ownerLogin !== pullRequestHead.ownerLogin) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (expectedHead.ownerLogin && pullRequestHead.ownerLogin) {
|
||||
return expectedHead.ownerLogin === pullRequestHead.ownerLogin;
|
||||
if (expectedHead.ownerLogin !== pullRequestHead.ownerLogin) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (headContext.isCrossRepository) {
|
||||
|
||||
Reference in new issue
Block a user