+36
![github-actions[bot]](/assets/img/avatar_default.png)








Julius Marminge
maria-rcks
Bilal Bakr
shivam
Vitalii Yehorov
Jake Leventhal
Claude Opus 5
Alex Southwell
github-actions[bot]
Nicholas Wasmiller
PB
Exotic
Yash Singh
Devin
Theo Browne
Gabriel De Andrade
Dara Adedeji
scratchyone
Dominic Roy
chukfinley
Primož Ajdišek
benthecarman
NaveDanan
aaditagrawal
Aditya Garud
Nick Anisimov
MacKinley Smith
Yordis Prieto
t3-code[bot]
AKolenda
Guillermo Casanova
Otavio Salvador
Shirish Pothi
Ishaan Kothari
Bob Fowler
Anton Bezdenezhnykh
ValeraZSD
Ephraim
Ryan Ilano
Alex
maco
Cursor
Tristan Knight
PR Batch Tester
oliver
kamkm
de34391427
Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Bilal Bakr <[email protected]> Co-authored-by: shivam <[email protected]> Co-authored-by: Vitalii Yehorov <[email protected]> Co-authored-by: Jake Leventhal <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: Alex Southwell <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Nicholas Wasmiller <[email protected]> Co-authored-by: PB <[email protected]> Co-authored-by: Exotic <[email protected]> Co-authored-by: Yash Singh <[email protected]> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Theo Browne <[email protected]> Co-authored-by: Gabriel De Andrade <[email protected]> Co-authored-by: Dara Adedeji <[email protected]> Co-authored-by: scratchyone <[email protected]> Co-authored-by: Dominic Roy <[email protected]> Co-authored-by: chukfinley <[email protected]> Co-authored-by: Primož Ajdišek <[email protected]> Co-authored-by: benthecarman <[email protected]> Co-authored-by: NaveDanan <[email protected]> Co-authored-by: aaditagrawal <[email protected]> Co-authored-by: Aditya Garud <[email protected]> Co-authored-by: Nick Anisimov <[email protected]> Co-authored-by: MacKinley Smith <[email protected]> Co-authored-by: Yordis Prieto <[email protected]> Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com> Co-authored-by: AKolenda <[email protected]> Co-authored-by: Guillermo Casanova <[email protected]> Co-authored-by: Otavio Salvador <[email protected]> Co-authored-by: Shirish Pothi <[email protected]> Co-authored-by: Ishaan Kothari <[email protected]> Co-authored-by: Bob Fowler <[email protected]> Co-authored-by: Anton Bezdenezhnykh <[email protected]> Co-authored-by: ValeraZSD <[email protected]> Co-authored-by: Ephraim <[email protected]> Co-authored-by: Ryan Ilano <[email protected]> Co-authored-by: Alex <[email protected]> Co-authored-by: maco <[email protected]> Co-authored-by: Cursor <[email protected]> Co-authored-by: Tristan Knight <[email protected]> Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: oliver <[email protected]> Co-authored-by: kamkm <[email protected]> Signed-off-by: Yordis Prieto <[email protected]>
95 lines
3.5 KiB
TypeScript
95 lines
3.5 KiB
TypeScript
import { sourceControlRepositorySelector } from "@t3tools/shared/sourceControl";
|
|
import {
|
|
type CommandId,
|
|
pullRequestHostOf,
|
|
type GitRunStackedActionResult,
|
|
type OrchestrationProjectShell,
|
|
type SourceControlProviderKind,
|
|
type ThreadId,
|
|
} from "@t3tools/contracts";
|
|
import { parseChangeRequestUrl } from "@t3tools/shared/changeRequestUrl";
|
|
import * as Cause from "effect/Cause";
|
|
import * as Effect from "effect/Effect";
|
|
import * as Option from "effect/Option";
|
|
|
|
import * as Orchestrator from "../orchestration-v2/Orchestrator.ts";
|
|
import * as ProjectService from "../project/ProjectService.ts";
|
|
|
|
export interface CreatedPullRequestKey {
|
|
readonly host: string;
|
|
readonly repository: string;
|
|
readonly number: number;
|
|
readonly url: string;
|
|
}
|
|
|
|
/**
|
|
* The identity a stacked action's pull request should be linked under, or
|
|
* null when the action did not leave one behind. Reading the host and
|
|
* repository from the URL keeps the link host-level even when the checkout's
|
|
* remote differs from where the PR was opened (a fork, say); the project is
|
|
* only consulted when the URL is one this cannot read.
|
|
*/
|
|
export function createdPullRequestKey(
|
|
result: Pick<GitRunStackedActionResult, "pr">,
|
|
project: OrchestrationProjectShell | undefined,
|
|
): CreatedPullRequestKey | null {
|
|
const { status, number, url } = result.pr;
|
|
if ((status !== "created" && status !== "opened_existing") || number === undefined || !url) {
|
|
return null;
|
|
}
|
|
const parsed = parseChangeRequestUrl(url);
|
|
if (parsed !== null) return { ...parsed, url };
|
|
const identity = project?.repositoryIdentity;
|
|
const kind = identity?.provider as SourceControlProviderKind | undefined;
|
|
const repository = sourceControlRepositorySelector(identity);
|
|
if (!identity || kind === undefined || repository === null) return null;
|
|
return {
|
|
host: pullRequestHostOf(identity, kind),
|
|
repository: repository.toLowerCase(),
|
|
number,
|
|
url,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Links the pull request a `create_pr`-shaped action produced to the thread it
|
|
* ran beside. Never fails: the git action already succeeded and its result is
|
|
* on its way to the client, so a link that cannot be made is logged and
|
|
* dropped. A duplicate link is the decider saying the thread already knew.
|
|
*/
|
|
export const linkCreatedPullRequest = <E>(input: {
|
|
readonly threadId: ThreadId;
|
|
readonly result: Pick<GitRunStackedActionResult, "pr">;
|
|
readonly commandId: Effect.Effect<CommandId, E>;
|
|
}): Effect.Effect<void, never, Orchestrator.OrchestratorV2 | ProjectService.ProjectService> =>
|
|
Effect.gen(function* () {
|
|
const engine = yield* Orchestrator.OrchestratorV2;
|
|
const projects = yield* ProjectService.ProjectService;
|
|
const thread = yield* engine
|
|
.getThreadShell(input.threadId)
|
|
.pipe(Effect.map(Option.fromNullishOr));
|
|
if (Option.isNone(thread)) return;
|
|
const project = Option.getOrUndefined(yield* projects.getShell(thread.value.projectId));
|
|
const key = createdPullRequestKey(input.result, project);
|
|
if (key === null) return;
|
|
const commandId = yield* input.commandId;
|
|
yield* engine
|
|
.dispatch({
|
|
type: "thread.pull-request.link",
|
|
commandId,
|
|
threadId: input.threadId,
|
|
...key,
|
|
source: "created",
|
|
})
|
|
.pipe(Effect.asVoid);
|
|
}).pipe(
|
|
Effect.withSpan("linkCreatedPullRequest"),
|
|
Effect.catchCause((cause) =>
|
|
Cause.hasInterruptsOnly(cause)
|
|
? Effect.failCause(cause as Cause.Cause<never>)
|
|
: Effect.logWarning("failed to link created pull request to thread", {
|
|
threadId: input.threadId,
|
|
}),
|
|
),
|
|
);
|