Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions apps/server/src/project/RepositoryIdentityResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
expect(identity).not.toBeNull();
expect(identity?.canonicalKey).toBe("github.com/t3tools/t3code");
expect(normalizeResolvedPath(resolvedIdentityRoot)).toBe(normalizeResolvedPath(resolvedCwd));
expect(identity?.displayName).toBe("t3tools/t3code");
expect(identity?.displayName).toBe("T3Tools/t3code");
expect(identity?.provider).toBe("github");
expect(identity?.owner).toBe("t3tools");
expect(identity?.owner).toBe("T3Tools");
expect(identity?.name).toBe("t3code");
}).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
);
Expand Down Expand Up @@ -284,7 +284,7 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
expect(identity).not.toBeNull();
expect(identity?.locator.remoteName).toBe("upstream");
expect(identity?.canonicalKey).toBe("github.com/t3tools/t3code");
expect(identity?.displayName).toBe("t3tools/t3code");
expect(identity?.displayName).toBe("T3Tools/t3code");
expect(yield* resolver.resolve(cwd)).toEqual(identity);
}).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
);
Expand All @@ -304,7 +304,7 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
const identity = yield* resolver.resolve(cwd);

expect(identity?.canonicalKey).toBe("github.com/t3tools/t3code");
expect(identity?.displayName).toBe("t3tools/t3code");
expect(identity?.displayName).toBe("T3Tools/t3code");
expect(identity?.origin).toEqual({
canonicalKey: "github.com/julius/t3code-fork",
displayName: "julius/t3code-fork",
Expand All @@ -327,8 +327,8 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {

expect(identity).not.toBeNull();
expect(identity?.canonicalKey).toBe("gitlab.com/t3tools/platform/t3code");
expect(identity?.displayName).toBe("t3tools/platform/t3code");
expect(identity?.owner).toBe("t3tools");
expect(identity?.displayName).toBe("T3Tools/platform/t3code");
expect(identity?.owner).toBe("T3Tools");
expect(identity?.name).toBe("t3code");
}).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
);
Expand Down Expand Up @@ -400,7 +400,7 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
const refreshedIdentity = yield* resolver.resolve(cwd);
expect(refreshedIdentity).not.toBeNull();
expect(refreshedIdentity?.canonicalKey).toBe("github.com/t3tools/t3code-next");
expect(refreshedIdentity?.displayName).toBe("t3tools/t3code-next");
expect(refreshedIdentity?.displayName).toBe("T3Tools/t3code-next");
expect(refreshedIdentity?.name).toBe("t3code-next");
}).pipe(
Effect.provide(
Expand Down
11 changes: 7 additions & 4 deletions apps/server/src/project/RepositoryIdentityResolver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { RepositoryIdentity, SourceControlProviderError } from "@t3tools/contracts";
import { repositoryPathFromRemoteUrl } from "@t3tools/source-control-core/server/SourceControlProvider";
import {
detectSourceControlProviderFromGitRemoteUrl,
normalizeGitRemoteUrl,
Expand Down Expand Up @@ -70,8 +71,10 @@ function pickPrimaryRemote(
return remoteName && remoteUrl ? { remoteName, remoteUrl } : null;
}

function repositoryPathOf(canonicalKey: string): string {
return canonicalKey.split("/").slice(1).join("/");
function repositoryPathOf(canonicalKey: string, remoteUrl: string): string {
const canonicalPath = canonicalKey.split("/").slice(1).join("/");
const displayPath = repositoryPathFromRemoteUrl(remoteUrl);
return displayPath?.toLowerCase() === canonicalPath ? displayPath : canonicalPath;
}

function buildRepositoryOrigin(
Expand All @@ -81,7 +84,7 @@ function buildRepositoryOrigin(
if (!originUrl) return undefined;
const originKey = normalizeGitRemoteUrl(originUrl);
if (originKey === canonicalKey) return undefined;
const displayName = repositoryPathOf(originKey);
const displayName = repositoryPathOf(originKey, originUrl);
return { canonicalKey: originKey, ...(displayName ? { displayName } : {}) };
}

Expand All @@ -93,7 +96,7 @@ function buildRepositoryIdentity(input: {
}): RepositoryIdentity {
const canonicalKey = normalizeGitRemoteUrl(input.remoteUrl);
const sourceControlProvider = detectSourceControlProviderFromGitRemoteUrl(input.remoteUrl);
const repositoryPath = repositoryPathOf(canonicalKey);
const repositoryPath = repositoryPathOf(canonicalKey, input.remoteUrl);
const repositoryPathSegments = repositoryPath.split("/").filter((segment) => segment.length > 0);
const [owner] = repositoryPathSegments;
const repositoryName = repositoryPathSegments.at(-1);
Expand Down
Loading