Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ const makeLayer = (input: {
readonly stored: Deferred.Deferred<void>;
readonly enabled?: boolean;
readonly currentHead?: Ref.Ref<string>;
readonly identity?: typeof ACME_APP;
readonly identity?: typeof ACME_APP & { readonly webUrl?: string };
}) =>
PullRequestReviewGuideService.layer.pipe(
Layer.provide(
Expand Down Expand Up @@ -590,4 +590,45 @@ it.layer(layerBase, { excludeTestServices: true })("PullRequestReviewGuideServic
}),
),
);

it.effect("writes a guide for a Forgejo checkout whose SSH remote is not the web host", () =>
Effect.scoped(
Effect.gen(function* () {
const repositories = yield* makeRepositories;
const stored = yield* Deferred.make<void>();
const context = yield* Layer.build(
makeLayer({
...repositories,
stored,
// The checkout's remote is not HTTP, so only the signed-in server's web URL names the host.
identity: {
...ACME_APP,
provider: "forgejo",
canonicalKey: "git-ssh.internal/owner/repo",
displayName: "owner/repo",
owner: "owner",
name: "repo",
webUrl: "https://git.example.com/owner/repo",
},
generate: () => Effect.succeed({ stops: [] }),
}),
);
const service = Context.get(
context,
PullRequestReviewGuideService.PullRequestReviewGuideService,
);
const forgejoReference: PullRequestRef = {
projectId,
host: "git.example.com",
repository: "owner/repo",
number: 7,
};
const started = yield* service.generate(forgejoReference);
assert.isTrue(started.started);
yield* Deferred.await(stored);
const result = yield* service.get(forgejoReference);
assert.strictEqual(result.guide?.headSha, repositories.headSha);
}),
),
);
});
1 change: 1 addition & 0 deletions packages/source-control-core/src/shared/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export type ChangeRequestHostIdentity =
| {
readonly canonicalKey?: string | undefined;
readonly locator?: { readonly remoteUrl: string } | undefined;
readonly webUrl?: string | undefined;
}
| null
| undefined;
Expand Down
7 changes: 7 additions & 0 deletions packages/source-control-forgejo/src/shared/definition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,12 @@ describe("Forgejo change request host", () => {
expect(
definition.changeRequestHost?.(identity("ssh://git@forge.example:2222/git/team/repo.git")),
).toBe("forge.example");
expect(
definition.changeRequestHost?.(
identity("ssh://git@ssh.forge.example:2222/git/team/repo.git", {
webUrl: "http://forge.example:3000/git/team/repo",
}),
),
).toBe("forge.example:3000");
});
});
9 changes: 5 additions & 4 deletions packages/source-control-forgejo/src/shared/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
buildCommitUrl,
changeRequestUrlBelow,
type ChangeRequestHostIdentity,
type ChangeRequestProjectIdentity,
defineSourceControl,
isChangeRequestAuthorityOfProject,
isChangeRequestInProjectRepository,
Expand Down Expand Up @@ -31,8 +30,8 @@ const changeRequestHeadRef = (number: number) => `refs/pull/${number}/head`;
* The repository's browser URL the server resolved from the signed-in account, which is the
* only place a Forgejo mounted below a path says so.
*/
function resolvedWebUrl(identity: ChangeRequestProjectIdentity): URL | null {
if (!identity.webUrl) return null;
function resolvedWebUrl(identity: ChangeRequestHostIdentity): URL | null {
if (!identity?.webUrl) return null;
try {
const url = new URL(identity.webUrl);
return url.protocol === "http:" || url.protocol === "https:" ? url : null;
Expand All @@ -41,8 +40,10 @@ function resolvedWebUrl(identity: ChangeRequestProjectIdentity): URL | null {
}
}

/** A server's identity includes its port, which only an HTTP remote names. */
/** A server's identity includes its port, which only its web URL or an HTTP remote names. */
function changeRequestHost(identity: ChangeRequestHostIdentity): string {
const web = resolvedWebUrl(identity);
if (web) return web.host.toLowerCase();
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
try {
const remote = new URL(identity?.locator?.remoteUrl ?? "");
if (remote.protocol === "http:" || remote.protocol === "https:") {
Expand Down
Loading