feat(plugins): add source-control extension contracts (#2117)

This commit is contained in:
José Almeida
2026-08-13 08:29:29 +01:00
committed by GitHub
parent 064b852884
commit f218880ecb
530 changed files with 39054 additions and 7518 deletions
@@ -52,6 +52,21 @@ describe("getWorkspaceSourceCapabilities", () => {
{ provider: "github", provider_owner: "acme", provider_name: "api" },
true,
],
[
"a future provider with an explicit host, owner, and name",
{
provider: "example-vcs",
provider_host: "code.example.test",
provider_owner: "acme",
provider_name: "api",
},
true,
],
[
"an unknown provider without an explicit host",
{ provider: "example-vcs", provider_owner: "acme", provider_name: "api" },
false,
],
["a provider ID without owner and name", { provider: "github", provider_repo_id: "42" }, false],
["no remote locator", {}, false],
])("recognizes %s as cloneable: %s", (_, repository, expected) => {
@@ -39,8 +39,8 @@ function hasProviderRepositoryLocator(repository: SavedRepositoryIdentity): bool
if (!provider || !repository.provider_owner?.trim() || !repository.provider_name?.trim()) {
return false;
}
if (provider === "gitlab" && !repository.provider_host?.trim()) return false;
return provider === "github" || provider === "gitlab" || provider === "bitbucket";
if (repository.provider_host?.trim()) return true;
return provider === "github" || provider === "gitlab";
}
function hasSafeRemoteURL(remoteURL: string | undefined): boolean {
@@ -64,7 +64,9 @@ describe("workspace source state payloads and validation", () => {
updateWorkspaceSourceRow([invalid, valid], "bad", { remoteUrl: "https://x/y.git" }),
).toEqual([{ ...invalid, remoteUrl: "https://x/y.git" }, valid]);
});
});
describe("workspace source state provider validation", () => {
it("accepts task-create's supported SCP remotes and rejects unsupported hosts", () => {
const rows = [
{
@@ -91,6 +93,16 @@ describe("workspace source state payloads and validation", () => {
remoteUrl: "https://bitbucket.org/acme/api.git",
baseBranch: "main",
},
{
key: "plugin-authorized",
kind: "repository" as const,
remoteUrl: "https://bitbucket.example.test/scm/acme/api.git",
provider: "bitbucket",
providerRepoId: "api-42",
providerOwner: "acme",
providerName: "api",
baseBranch: "main",
},
];
expect(getWorkspaceSourceValidation(rows)).toEqual({
@@ -13,7 +13,7 @@ export type WorkspaceSourceRow = {
repositoryId?: string;
localPath?: string;
remoteUrl?: string;
provider?: "github" | "gitlab" | "azure_devops";
provider?: string;
providerRepoId?: string;
providerOwner?: string;
providerName?: string;
@@ -90,7 +90,7 @@ function validateRow(
return null;
}
const locator = repositoryLocator(row);
if (row.remoteUrl && !isValidRemoteUrl(row.remoteUrl)) {
if (row.remoteUrl && !row.provider && !isValidRemoteUrl(row.remoteUrl)) {
return "Enter a valid remote repository URL and base branch.";
}
if (!locator || !row.baseBranch?.trim()) return "Choose a repository and base branch.";