Skip to content
Closed
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
41 changes: 37 additions & 4 deletions apps/mobile/src/native/useOpenPullRequest.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { useNavigation, useRoute, StackActions } from "@react-navigation/native";
import { resolveIssueLinkTarget } from "@t3tools/client-runtime/issue-links";
import {
isLinearIssueLink,
linksAnotherLinearWorkspace,
resolveIssueLinkTarget,
} from "@t3tools/client-runtime/issue-links";
import {
nativePullRequestDestination,
pullRequestCandidateForIssueLink,
} from "../lib/pullRequestNavigation";
import { isAtomCommandInterrupted } from "@t3tools/client-runtime/state/runtime";
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
import { EnvironmentId, type IssueTrackerConnectionList, ThreadId } from "@t3tools/contracts";
import { useProjects, useThreadShell } from "../state/entities";
import { tryOpenExternalUrl } from "../lib/openExternalUrl";
import { appAtomRegistry } from "../state/atom-registry";
import { environmentServerConfigsAtom } from "../state/server";
import { issueEnvironment } from "../state/issues";
import { issueTrackerEnvironment } from "../state/issueTrackers";
import { composerPullRequests } from "../state/pull-requests";
import { useAtomQueryRunner } from "../state/use-atom-query-runner";
import { withKnownPullRequestSummary } from "../state/use-thread-pr";
Expand All @@ -28,6 +34,14 @@ export function useNavigateToPullRequest(options?: { readonly replace?: boolean
reportFailure: false,
reportDefect: false,
});
const readTrackers = useAtomQueryRunner(issueTrackerEnvironment.connections, {
reportFailure: false,
reportDefect: false,
});
const readIssue = useAtomQueryRunner(issueEnvironment.detail, {
reportFailure: false,
reportDefect: false,
});
return async (url: string, context: PullRequestContext | null) => {
// Read at press time so a config push does not hand every link a new handler.
const serverConfigs = appAtomRegistry.get(environmentServerConfigsAtom);
Expand All @@ -37,14 +51,26 @@ export function useNavigateToPullRequest(options?: { readonly replace?: boolean
if (!destination) {
// An issue link from the same text opens the issue; anything else leaves for the browser.
const environmentId = context && EnvironmentId.make(context.environmentId);
const issue =
environmentId && serverConfigs.get(environmentId)?.environment.capabilities.issues === true
const issuesSupported =
environmentId !== null &&
serverConfigs.get(environmentId)?.environment.capabilities.issues === true;
const resolveIssue = (trackerBindings?: IssueTrackerConnectionList["bindings"]) =>
environmentId && issuesSupported
? resolveIssueLinkTarget({
url,
projects: projects.filter((project) => project.environmentId === environmentId),
preferredProjectId: context.projectId,
trackerBindings,
})
: null;
let issue = resolveIssue();
let standalone = false;
if (!issue && environmentId && issuesSupported && isLinearIssueLink(url)) {
// Linear links resolve through the projects bound to a team in Settings.
const trackers = await readTrackers({ environmentId, input: {} });
if (trackers._tag === "Success") issue = resolveIssue(trackers.value.bindings);
standalone = issue !== null;
}
if (!issue || !environmentId) return tryOpenExternalUrl(url, "pull-request");
const candidate = pullRequestCandidateForIssueLink(url, issue.ref);
if (candidate) {
Expand All @@ -64,6 +90,13 @@ export function useNavigateToPullRequest(options?: { readonly replace?: boolean
// A dropped connection says nothing about what the link names; the browser knows.
if (isAtomCommandInterrupted(preview)) return tryOpenExternalUrl(url, "pull-request");
}
if (standalone) {
// Team keys repeat across Linear workspaces; an issue whose workspace is unconfirmed goes to the browser.
const detail = await readIssue({ environmentId, input: issue.ref });
if (detail._tag !== "Success" || linksAnotherLinearWorkspace(url, detail.value.url)) {
return tryOpenExternalUrl(url, "pull-request");
}
}
const issueParams = {
environmentId,
projectId: issue.ref.projectId,
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/chat/RightPanelSurfaceContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export function RightPanelSurfaceContent(props: {
scope: surface.scope,
key: surface.key,
}}
linkUrl={surface.url}
threadRef={threadRef}
onSelectPullRequest={(reference) => {
useRightPanelStore.getState().openPullRequest(threadRef, {
Expand Down
14 changes: 14 additions & 0 deletions apps/web/src/components/issue/IssueDetailPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { RegistryContext, useAtomValue } from "@effect/atom-react";
import { linksAnotherLinearWorkspace } from "@t3tools/client-runtime/issue-links";
import { issueEventSentence, issueWriteAccess } from "@t3tools/client-runtime/issue-presentation";
import { createIssueCommentPager } from "@t3tools/client-runtime/state/issues";
import {
Expand Down Expand Up @@ -381,10 +382,13 @@ export function IssueDetailPanel({
reference,
threadRef = null,
listEntry = null,
linkUrl,
onSelectPullRequest,
}: {
environmentId: EnvironmentId;
reference: IssueRef;
/** The link this issue was opened from, when a click in text opened it. */
linkUrl?: string | undefined;
/** The list row this issue was opened from, shown until the detail arrives. */
listEntry?: IssueListEntry | null;
threadRef?: ScopedThreadRef | null;
Expand Down Expand Up @@ -426,6 +430,16 @@ export function IssueDetailPanel({
return <IssueDetailGhost seed={listEntry} />;
}

if (linkUrl !== undefined && linksAnotherLinearWorkspace(linkUrl, detail.url)) {
return (
<PullRequestsUnavailableState
title={gt("This issue is in another Linear workspace")}
error={gt("The connected Linear account has an issue with the same key, not this one.")}
host={{ url: linkUrl, openLabel: gt("Open on Linear") }}
/>
);
}

const timeline: ReadonlyArray<TimelineItem> = [
...comments.map((c): TimelineItem => ({ kind: "comment", at: c.createdAt, comment: c })),
...detail.events.map((e): TimelineItem => ({ kind: "event", at: e.createdAt, event: e })),
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/issue/IssuesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ export function IssuesPage() {
scope: renderedSurface.scope,
key: renderedSurface.key,
}}
linkUrl={renderedSurface.url}
onSelectPullRequest={(reference) => {
useRightPanelStore.getState().openPullRequest(rightPanelRef, {
projectId: reference.projectId,
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/i18n/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -5681,6 +5681,9 @@
"b8a884177afea13c": "Es gibt mehr Personen, als hier aufgeführt sind.",
"6081fdaabe34daf7": "Zugewiesen",
"2d9b7c42374ecd04": "Dieses Issue konnte nicht geladen werden",
"f4a2cf1e37b0f65c": "Dieses Issue ist in einem anderen Linear-Workspace",
"ccbf4f5267dde5b8": "Das verbundene Linear-Konto hat ein Issue mit demselben Schlüssel, aber nicht dieses.",
"8e8867deed70a6c1": "Auf Linear öffnen",
"217e1e7b60469736": "Issue-Status, {state}",
"a98a269e3061a069": "{issue} auf {provider} öffnen",
"c1ff5afd83b1e027": "Issue aktualisieren",
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5682,6 +5682,9 @@
"b8a884177afea13c": "More people exist than are listed here.",
"6081fdaabe34daf7": "Assigned",
"2d9b7c42374ecd04": "Could not load this issue",
"f4a2cf1e37b0f65c": "This issue is in another Linear workspace",
"ccbf4f5267dde5b8": "The connected Linear account has an issue with the same key, not this one.",
"8e8867deed70a6c1": "Open on Linear",
"217e1e7b60469736": "Issue state, {state}",
"a98a269e3061a069": "Open {issue} on {provider}",
"c1ff5afd83b1e027": "Refresh issue",
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/i18n/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -5680,6 +5680,9 @@
"b8a884177afea13c": "Hay más personas de las que se muestran aquí.",
"6081fdaabe34daf7": "Asignado",
"2d9b7c42374ecd04": "No se pudo cargar esta issue",
"f4a2cf1e37b0f65c": "Esta issue está en otro espacio de trabajo de Linear",
"ccbf4f5267dde5b8": "La cuenta de Linear conectada tiene una issue con la misma clave, pero no esta.",
"8e8867deed70a6c1": "Abrir en Linear",
"217e1e7b60469736": "Estado de la issue, {state}",
"a98a269e3061a069": "Abrir {issue} en {provider}",
"c1ff5afd83b1e027": "Actualizar issue",
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/i18n/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -5681,6 +5681,9 @@
"b8a884177afea13c": "Il existe plus de personnes que celles listées ici.",
"6081fdaabe34daf7": "Assigné",
"2d9b7c42374ecd04": "Impossible de charger ce ticket",
"f4a2cf1e37b0f65c": "Ce ticket se trouve dans un autre espace de travail Linear",
"ccbf4f5267dde5b8": "Le compte Linear connecté a un ticket avec la même clé, mais pas celui-ci.",
"8e8867deed70a6c1": "Ouvrir sur Linear",
"217e1e7b60469736": "État du ticket, {state}",
"a98a269e3061a069": "Ouvrir {issue} sur {provider}",
"c1ff5afd83b1e027": "Actualiser le ticket",
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/i18n/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -5663,6 +5663,9 @@
"b8a884177afea13c": "ここに表示されている以外にもユーザーがいます。",
"6081fdaabe34daf7": "割り当て済み",
"2d9b7c42374ecd04": "この Issue を読み込めませんでした",
"f4a2cf1e37b0f65c": "この Issue は別の Linear ワークスペースにあります",
"ccbf4f5267dde5b8": "接続中の Linear アカウントには同じキーの Issue がありますが、これとは別のものです。",
"8e8867deed70a6c1": "Linear で開く",
"217e1e7b60469736": "Issue の状態、{state}",
"a98a269e3061a069": "{provider} で {issue} を開く",
"c1ff5afd83b1e027": "Issue を更新",
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/i18n/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -5661,6 +5661,9 @@
"b8a884177afea13c": "여기에 표시된 것보다 사용자가 더 있습니다.",
"6081fdaabe34daf7": "지정됨",
"2d9b7c42374ecd04": "이 이슈를 불러올 수 없습니다",
"f4a2cf1e37b0f65c": "이 이슈는 다른 Linear 워크스페이스에 있습니다",
"ccbf4f5267dde5b8": "연결된 Linear 계정에 같은 키의 이슈가 있지만 이 이슈는 아닙니다.",
"8e8867deed70a6c1": "Linear에서 열기",
"217e1e7b60469736": "이슈 상태, {state}",
"a98a269e3061a069": "{provider}에서 {issue} 열기",
"c1ff5afd83b1e027": "이슈 새로 고침",
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/i18n/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -5680,6 +5680,9 @@
"b8a884177afea13c": "Há mais pessoas do que as listadas aqui.",
"6081fdaabe34daf7": "Atribuído",
"2d9b7c42374ecd04": "Não foi possível carregar esta issue",
"f4a2cf1e37b0f65c": "Esta issue está em outro workspace do Linear",
"ccbf4f5267dde5b8": "A conta do Linear conectada tem uma issue com a mesma chave, mas não esta.",
"8e8867deed70a6c1": "Abrir no Linear",
"217e1e7b60469736": "Estado da issue, {state}",
"a98a269e3061a069": "Abrir {issue} no {provider}",
"c1ff5afd83b1e027": "Atualizar issue",
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/i18n/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -5680,6 +5680,9 @@
"b8a884177afea13c": "Людей больше, чем показано здесь.",
"6081fdaabe34daf7": "Назначен",
"2d9b7c42374ecd04": "Не удалось загрузить этот issue",
"f4a2cf1e37b0f65c": "Этот issue находится в другом рабочем пространстве Linear",
"ccbf4f5267dde5b8": "В подключённом аккаунте Linear есть issue с тем же ключом, но не этот.",
"8e8867deed70a6c1": "Открыть в Linear",
"217e1e7b60469736": "Состояние issue: {state}",
"a98a269e3061a069": "Открыть {issue} в {provider}",
"c1ff5afd83b1e027": "Обновить issue",
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/i18n/translations/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -5681,6 +5681,9 @@
"b8a884177afea13c": "Det finns fler personer än som listas här.",
"6081fdaabe34daf7": "Tilldelad",
"2d9b7c42374ecd04": "Kunde inte läsa in det här ärendet",
"f4a2cf1e37b0f65c": "Det här ärendet finns i en annan Linear-arbetsyta",
"ccbf4f5267dde5b8": "Det anslutna Linear-kontot har ett ärende med samma nyckel, men inte det här.",
"8e8867deed70a6c1": "Öppna på Linear",
"217e1e7b60469736": "Ärendestatus, {state}",
"a98a269e3061a069": "Öppna {issue} på {provider}",
"c1ff5afd83b1e027": "Uppdatera ärende",
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/i18n/translations/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -5687,6 +5687,9 @@
"b8a884177afea13c": "还有更多人员未在此列出。",
"6081fdaabe34daf7": "已分配",
"2d9b7c42374ecd04": "无法加载此 issue",
"f4a2cf1e37b0f65c": "此 issue 位于另一个 Linear 工作区",
"ccbf4f5267dde5b8": "已连接的 Linear 账户中有一个键相同的 issue,但不是这一个。",
"8e8867deed70a6c1": "在 Linear 上打开",
"217e1e7b60469736": "issue 状态,{state}",
"a98a269e3061a069": "在 {provider} 上打开 {issue}",
"c1ff5afd83b1e027": "刷新 issue",
Expand Down
10 changes: 10 additions & 0 deletions apps/web/src/lib/openIssueLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import type { MouseEvent } from "react";
import { readIssueListPreferences } from "../components/issue/issueListPreferences";
import { ISSUES_PANEL_REF, PULL_REQUESTS_PANEL_REF, useRightPanelStore } from "../rightPanelStore";
import { useProjects, useServerConfigs } from "../state/entities";
import { issueTrackerEnvironment } from "../state/issueTrackers";
import { useEnvironmentQuery } from "../state/query";

/**
* Opens an issue link beside the thread, and says whether it did. Anything else — a host no
Expand All @@ -27,6 +29,13 @@ export function useOpenIssueLink(
const allProjects = useProjects();
const serverConfigs = useServerConfigs();
const navigate = useNavigate();
const threadEnvironmentId = threadRef?.environmentId;
const trackers = useEnvironmentQuery(
threadEnvironmentId !== undefined &&
serverConfigs.get(threadEnvironmentId)?.environment.capabilities.issues === true
? issueTrackerEnvironment.connections({ environmentId: threadEnvironmentId, input: {} })
: null,
);
return (event, targetUrl, targetEnvironmentId) => {
if (event.metaKey || event.ctrlKey) return false;
const resolvedPanelRef = panelRef ?? threadRef;
Expand All @@ -37,6 +46,7 @@ export function useOpenIssueLink(
const target = resolveIssueLinkTarget({
url: targetUrl,
projects: allProjects.filter((project) => project.environmentId === environmentId),
trackerBindings: environmentId === threadEnvironmentId ? trackers.data?.bindings : undefined,
});
if (target === null) return false;
event.preventDefault();
Expand Down
1 change: 1 addition & 0 deletions packages/client-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@
"dependencies": {
"@pierre/diffs": "catalog:",
"@t3tools/contracts": "workspace:*",
"@t3tools/issue-tracker-linear": "workspace:*",
"@t3tools/provider-acp-registry": "workspace:*",
"@t3tools/provider-core": "workspace:*",
"@t3tools/provider-cursor": "workspace:*",
Expand Down
60 changes: 58 additions & 2 deletions packages/client-runtime/src/issueLinks.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { EnvironmentId, ProjectId, SourceControlProviderKind } from "@t3tools/contracts";
import {
EnvironmentId,
IssueTrackerKind,
ProjectId,
SourceControlProviderKind,
} from "@t3tools/contracts";
import { describe, expect, it } from "vite-plus/test";

import { resolveIssueLinkTarget } from "./issueLinks.ts";
import { linksAnotherLinearWorkspace, resolveIssueLinkTarget } from "./issueLinks.ts";

const project = (id: string, repository: string) =>
({
Expand Down Expand Up @@ -65,10 +70,61 @@ describe("resolveIssueLinkTarget", () => {
expect(custom?.ref).toMatchObject({ projectId: "custom", host: "code.acme.test", key: "7" });
});

it("reads a Linear issue through the project bound to its team, else lends a bound project", () => {
const trackerBindings = {
p1: { tracker: IssueTrackerKind.make("linear"), scope: "OPS" },
p2: { tracker: IssueTrackerKind.make("linear"), scope: "ENG" },
} as never;
const own = resolveIssueLinkTarget({
url: "https://linear.app/acme/issue/ENG-12/fix-the-thing",
projects,
trackerBindings,
});
expect(own?.ref).toEqual({
projectId: "p2",
tracker: "linear",
host: "linear.app",
scope: "ENG",
key: "ENG-12",
});

const lent = resolveIssueLinkTarget({
url: "https://linear.app/acme/issue/WEB-3",
projects,
trackerBindings,
preferredProjectId: ProjectId.make("p2"),
});
expect(lent?.ref).toMatchObject({ projectId: "p2", scope: "WEB", key: "WEB-3" });
});

it.each([
"https://github.com.evil.example/acme/web/issues/7",
"https://github.com/acme/web/pull/7",
"https://linear.app/acme/issue/ENG-12",
])("leaves %s an ordinary link", (url) => {
expect(resolveIssueLinkTarget({ url, projects })).toBeNull();
});
});

describe("linksAnotherLinearWorkspace", () => {
it.each([
{
link: "https://linear.app/acme/issue/ENG-12",
issue: "https://linear.app/acme/issue/ENG-12/a-title",
expected: false,
},
{
link: "https://linear.app/other/issue/ENG-12",
issue: "https://linear.app/acme/issue/ENG-12/a-title",
expected: true,
},
{ link: "https://linear.app/acme/issue/ENG-12", issue: "not a url", expected: true },
{
link: "https://github.com/acme/web/issues/7",
issue: "https://github.com/acme/web/issues/7",
expected: false,
},
])("$link opening $issue is another workspace's: $expected", ({ link, issue, expected }) => {
expect(linksAnotherLinearWorkspace(link, issue)).toBe(expected);
});
});
Loading
Loading