60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import { matchAuthorizedRepository, parseGitHubRemote } from "./shared";
|
|
|
|
test("parseGitHubRemote 支持 https 和 ssh", () => {
|
|
assert.deepEqual(parseGitHubRemote("https://github.com/pmflow/control-plane.git"), {
|
|
owner: "pmflow",
|
|
repoName: "control-plane",
|
|
});
|
|
assert.deepEqual(parseGitHubRemote("git@github.com:pmflow/control-plane.git"), {
|
|
owner: "pmflow",
|
|
repoName: "control-plane",
|
|
});
|
|
assert.equal(parseGitHubRemote("https://gitlab.com/pmflow/control-plane"), null);
|
|
});
|
|
|
|
test("matchAuthorizedRepository 只命中 GitHub App 已授权仓库", () => {
|
|
const matched = matchAuthorizedRepository(
|
|
[
|
|
{
|
|
id: "1",
|
|
installation_id: "101",
|
|
installation_account_login: "pmflow",
|
|
external_repo_id: "9001",
|
|
owner: "pmflow",
|
|
repo_name: "control-plane",
|
|
full_name: "pmflow/control-plane",
|
|
default_branch: "main",
|
|
is_private: true,
|
|
status: "active",
|
|
},
|
|
],
|
|
{ owner: "PMFlow", repoName: "CONTROL-PLANE" }
|
|
);
|
|
|
|
assert.ok(matched);
|
|
assert.equal(matched?.full_name, "pmflow/control-plane");
|
|
assert.equal(
|
|
matchAuthorizedRepository(
|
|
[
|
|
{
|
|
id: "1",
|
|
installation_id: "101",
|
|
installation_account_login: "pmflow",
|
|
external_repo_id: "9001",
|
|
owner: "pmflow",
|
|
repo_name: "control-plane",
|
|
full_name: "pmflow/control-plane",
|
|
default_branch: "main",
|
|
is_private: true,
|
|
status: "active",
|
|
},
|
|
],
|
|
{ owner: "other", repoName: "unknown" }
|
|
),
|
|
null
|
|
);
|
|
});
|