fix(server): forks no longer merge into their upstream repo's project group (#16353)
Fixes #4880. Originally #14639 by @Project516. Co-authored-by: Project516 <[email protected]>
This commit is contained in:
1 parent
99db70cf1a
commit
017c9a0eb5
8 files changed
+144
-15
No files matched your search
@@ -288,6 +288,29 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
|
||||
}).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
|
||||
);
|
||||
|
||||
it.effect("reports a fork's own remote as origin next to the upstream identity", () =>
|
||||
Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const cwd = yield* fileSystem.makeTempDirectoryScoped({
|
||||
prefix: "t3-repository-identity-fork-test-",
|
||||
});
|
||||
|
||||
yield* git(cwd, ["init"]);
|
||||
yield* git(cwd, ["remote", "add", "origin", "[email protected]:julius/t3code-fork.git"]);
|
||||
yield* git(cwd, ["remote", "add", "upstream", "[email protected]:T3Tools/t3code.git"]);
|
||||
|
||||
const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
|
||||
const identity = yield* resolver.resolve(cwd);
|
||||
|
||||
expect(identity?.canonicalKey).toBe("github.com/t3tools/t3code");
|
||||
expect(identity?.displayName).toBe("t3tools/t3code");
|
||||
expect(identity?.origin).toEqual({
|
||||
canonicalKey: "github.com/julius/t3code-fork",
|
||||
displayName: "julius/t3code-fork",
|
||||
});
|
||||
}).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
|
||||
);
|
||||
|
||||
it.effect("uses the last remote path segment as the repository name for nested groups", () =>
|
||||
Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
|
||||
@@ -70,17 +70,34 @@ function pickPrimaryRemote(
|
||||
return remoteName && remoteUrl ? { remoteName, remoteUrl } : null;
|
||||
}
|
||||
|
||||
function repositoryPathOf(canonicalKey: string): string {
|
||||
return canonicalKey.split("/").slice(1).join("/");
|
||||
}
|
||||
|
||||
function buildRepositoryOrigin(
|
||||
originUrl: string | undefined,
|
||||
canonicalKey: string,
|
||||
): RepositoryIdentity["origin"] {
|
||||
if (!originUrl) return undefined;
|
||||
const originKey = normalizeGitRemoteUrl(originUrl);
|
||||
if (originKey === canonicalKey) return undefined;
|
||||
const displayName = repositoryPathOf(originKey);
|
||||
return { canonicalKey: originKey, ...(displayName ? { displayName } : {}) };
|
||||
}
|
||||
|
||||
function buildRepositoryIdentity(input: {
|
||||
readonly remoteName: string;
|
||||
readonly remoteUrl: string;
|
||||
readonly originUrl: string | undefined;
|
||||
readonly rootPath: string;
|
||||
}): RepositoryIdentity {
|
||||
const canonicalKey = normalizeGitRemoteUrl(input.remoteUrl);
|
||||
const sourceControlProvider = detectSourceControlProviderFromGitRemoteUrl(input.remoteUrl);
|
||||
const repositoryPath = canonicalKey.split("/").slice(1).join("/");
|
||||
const repositoryPath = repositoryPathOf(canonicalKey);
|
||||
const repositoryPathSegments = repositoryPath.split("/").filter((segment) => segment.length > 0);
|
||||
const [owner] = repositoryPathSegments;
|
||||
const repositoryName = repositoryPathSegments.at(-1);
|
||||
const origin = buildRepositoryOrigin(input.originUrl, canonicalKey);
|
||||
|
||||
return {
|
||||
canonicalKey,
|
||||
@@ -94,6 +111,7 @@ function buildRepositoryIdentity(input: {
|
||||
...(sourceControlProvider ? { provider: sourceControlProvider.kind } : {}),
|
||||
...(owner ? { owner } : {}),
|
||||
...(repositoryName ? { name: repositoryName } : {}),
|
||||
...(origin ? { origin } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -136,8 +154,11 @@ const resolveRepositoryIdentityFromCacheKey = Effect.fn(
|
||||
return null;
|
||||
}
|
||||
|
||||
const remote = pickPrimaryRemote(parseRemoteFetchUrls(remoteResult.value.stdout));
|
||||
return remote ? buildRepositoryIdentity({ ...remote, rootPath: cacheKey }) : null;
|
||||
const remotes = parseRemoteFetchUrls(remoteResult.value.stdout);
|
||||
const remote = pickPrimaryRemote(remotes);
|
||||
return remote
|
||||
? buildRepositoryIdentity({ ...remote, originUrl: remotes.get("origin"), rootPath: cacheKey })
|
||||
: null;
|
||||
});
|
||||
|
||||
export const make = Effect.fn("RepositoryIdentityResolver.make")(function* (
|
||||
|
||||
Reference in new issue
Block a user