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
60 changes: 57 additions & 3 deletions apps/mobile/src/features/issues/IssueRouteScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { visibleLinkedThreads } from "@t3tools/client-runtime/state/threads";
import type {
IssueComment,
IssueEvent,
IssueEventReference,
IssueLinkedPullRequest,
IssueReaction,
IssueState,
Expand Down Expand Up @@ -404,17 +405,70 @@ function IssueCommentCard(props: {
);
}

function IssueEventRow({ event }: { readonly event: IssueEvent }) {
function IssueEventRow({
params,
event,
}: {
readonly params: IssueParams;
readonly event: IssueEvent;
}) {
const gt = useGT();
const messages = useMessages();
const navigation = useNavigation();
const sentence = issueEventSentence(event, messages);
const source = event.reference;
const at = event.detail === null ? -1 : sentence.indexOf(event.detail);
// Only a git host's tracker shares its host with the change request it links.
const sameHost = sourceControlClients.find(params.tracker) !== undefined;
const openSource = (target: IssueEventReference) => {
const host = params.host ? { host: params.host } : {};
if (target.kind === "issue") {
navigation.dispatch(
StackActions.push("Issue", {
environmentId: params.environmentId,
projectId: params.projectId,
tracker: params.tracker,
...host,
scope: target.repository,
issueKey: String(target.number),
}),
);
} else if (sameHost) {
navigation.dispatch(
StackActions.push("PullRequest", {
environmentId: params.environmentId,
projectId: params.projectId,
repository: target.repository,
number: target.number,
...host,
}),
);
} else {
void tryOpenExternalUrl(target.url);
}
};
return (
<View className="flex-row items-center gap-2 px-1">
<PullRequestAvatar actor={event.actor} size={18} />
<Text className="min-w-0 flex-1 text-xs text-foreground-muted">
<Text className="text-xs font-t3-medium">
{event.actor?.login ?? gt("Someone", { $context: "an unknown person" })}
</Text>{" "}
{issueEventSentence(event, messages)}
{source === undefined || event.detail === null || at < 0 ? (
sentence
) : (
<>
{sentence.slice(0, at)}
<Text
accessibilityRole="link"
className="text-xs font-t3-medium text-primary-text"
onPress={() => openSource(source)}
>
{event.detail}
</Text>
{sentence.slice(at + event.detail.length)}
</>
)}
</Text>
<Text className="text-2xs text-foreground-tertiary">
{relativeTime(event.createdAt, undefined, messages)}
Expand Down Expand Up @@ -505,7 +559,7 @@ function IssueRoute({ params }: { readonly params: IssueParams }) {
...detail.events.map((event) => ({
key: `e:${event.id}`,
at: event.createdAt,
content: <IssueEventRow event={event} />,
content: <IssueEventRow params={params} event={event} />,
})),
].sort((left, right) => Date.parse(left.at) - Date.parse(right.at))
: [];
Expand Down
19 changes: 18 additions & 1 deletion apps/web/src/components/chat/RightPanelSurfaceContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,14 @@ export function RightPanelSurfaceContent(props: {
getShortcutContext={props.getShortcutContext}
shortcutsEnabled={visible && props.activeSurfaceId === surface.id}
key={`${scopedThreadKey(threadRef)}:${surface.id}`}
environmentId={props.environmentId}
environmentId={
(surface.environmentId as EnvironmentId | undefined) ?? props.environmentId
}
onSelectPullRequest={(reference) => {
useRightPanelStore.getState().openPullRequest(threadRef, {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
...(surface.environmentId === undefined
? {}
: { environmentId: surface.environmentId }),
projectId: reference.projectId,
repository: reference.repository,
number: reference.number,
Expand Down Expand Up @@ -205,12 +210,24 @@ export function RightPanelSurfaceContent(props: {
threadRef={threadRef}
onSelectPullRequest={(reference) => {
useRightPanelStore.getState().openPullRequest(threadRef, {
...(surface.environmentId === undefined
? {}
: { environmentId: surface.environmentId }),
projectId: reference.projectId,
repository: reference.repository,
number: reference.number,
...(reference.host ? { host: reference.host } : {}),
});
}}
onSelectIssue={({ host, ...reference }) => {
useRightPanelStore.getState().openIssue(threadRef, {
...(surface.environmentId === undefined
? {}
: { environmentId: surface.environmentId }),
...reference,
...(host ? { host } : {}),
});
}}
/>
);
case "pull-requests":
Expand Down
65 changes: 64 additions & 1 deletion apps/web/src/components/issue/IssueDetailPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
IssueComment,
IssueDetail,
IssueEvent,
IssueEventReference,
IssueLabelCandidate,
IssueLinkedPullRequest,
IssueListEntry,
Expand Down Expand Up @@ -376,12 +377,44 @@ function LinkedPullRequestRow({
);
}

/** The sentence for an event, its source shown as a link where the tracker named one. */
function IssueEventText({
event,
sentence,
onOpen,
}: {
event: IssueEvent;
sentence: string;
/** Opens the source beside this issue, and says whether it did; if not, the link goes to the host. */
onOpen: (source: IssueEventReference) => boolean;
}) {
const source = event.reference;
const at = event.detail === null ? -1 : sentence.indexOf(event.detail);
if (source === undefined || event.detail === null || at < 0) return <span>{sentence}</span>;
return (
<span>
{sentence.slice(0, at)}
<InlineButton
tone="muted"
render={<a href={source.url} target="_blank" rel="noopener noreferrer" />}
onClick={(click) => {
if (!click.metaKey && !click.ctrlKey && onOpen(source)) click.preventDefault();
}}
>
{event.detail}
</InlineButton>
{sentence.slice(at + event.detail.length)}
</span>
);
}

export function IssueDetailPanel({
environmentId,
reference,
threadRef = null,
listEntry = null,
onSelectPullRequest,
onSelectIssue,
}: {
environmentId: EnvironmentId;
reference: IssueRef;
Expand All @@ -390,6 +423,8 @@ export function IssueDetailPanel({
threadRef?: ScopedThreadRef | null;
/** Opens a linked change request beside this one; absent, the link goes to the host. */
onSelectPullRequest?: ((reference: PullRequestRef) => void) | undefined;
/** Opens a referenced issue beside this one; absent, the link goes to the host. */
onSelectIssue?: ((reference: IssueRef & { readonly url: string }) => void) | undefined;
}) {
const gt = useGT();
const messages = useMessages();
Expand Down Expand Up @@ -442,6 +477,30 @@ export function IssueDetailPanel({
const tracker = issueTrackerPresentation(detail.tracker);
const currentState = issueStatePresentation(detail.state);

const host = reference.host === undefined ? {} : { host: reference.host };
const openEventSource = (source: IssueEventReference) => {
if (source.kind === "pull-request") {
if (!onSelectPullRequest) return false;
onSelectPullRequest({
projectId: reference.projectId,
...host,
repository: source.repository,
number: source.number,
});
return true;
}
if (!onSelectIssue) return false;
onSelectIssue({
projectId: reference.projectId,
tracker: reference.tracker,
...host,
scope: source.repository,
key: String(source.number),
url: source.url,
});
return true;
};

const loadOlder = async () => {
const failure = await pager.loadOlder(registry, (cursor) =>
loadComments({ environmentId, input: { ...reference, cursor } }),
Expand Down Expand Up @@ -869,7 +928,11 @@ export function IssueDetailPanel({
className="px-1 text-xs text-muted-foreground"
>
<PullRequestActorLabel actor={item.event.actor} />
<span>{issueEventSentence(item.event, messages)}</span>
<IssueEventText
event={item.event}
sentence={issueEventSentence(item.event, messages)}
onOpen={openEventSource}
/>
<span>{formatRelativeTimeLabel(item.event.createdAt, undefined, messages)}</span>
</PullRequestMetaLine>
),
Expand Down
9 changes: 8 additions & 1 deletion apps/web/src/components/issue/IssuesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ export function IssuesPage() {
: clearedSelection,
);

const selectEntry = (entry: IssueRowTarget) => {
const selectEntry = (entry: Omit<IssueRowTarget, "host"> & { readonly host?: string }) => {
if (rightPanelRef === null) return;
useRightPanelStore.getState().openIssue(rightPanelRef, entry);
updateSearch({
Expand Down Expand Up @@ -864,6 +864,13 @@ export function IssuesPage() {
environmentId: panelEnvironmentId,
});
}}
onSelectIssue={({ host, ...reference }) =>
selectEntry({
...reference,
...(host === undefined ? {} : { host }),
environmentId: panelEnvironmentId,
})
}
/>
) : (
<PullRequestDetailPanel
Expand Down
10 changes: 10 additions & 0 deletions packages/contracts/src/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,23 @@ export const IssueEventKind = Schema.Literals([
]);
export type IssueEventKind = typeof IssueEventKind.Type;

export const IssueEventReference = Schema.Struct({
repository: TrimmedNonEmptyString,
number: PositiveInt,
kind: Schema.Literals(["issue", "pull-request"]),
url: TrimmedNonEmptyString,
});
export type IssueEventReference = typeof IssueEventReference.Type;

export const IssueEvent = Schema.Struct({
id: TrimmedNonEmptyString,
kind: IssueEventKind,
actor: Schema.NullOr(IssueActor),
createdAt: IsoDateTime,
/** What the event was about, where it has a subject: a label name, a login, a new title. */
detail: Schema.NullOr(TrimmedNonEmptyString),
/** The issue or change request a `referenced` event came from, so a surface can open it. */
reference: Schema.optional(IssueEventReference),
});
export type IssueEvent = typeof IssueEvent.Type;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,15 @@ Redact secrets before uploading.`);
["referenced", "acme/web#50"],
["closed", null],
]);
// A cross-reference keeps what a surface needs to open its source, not only a label.
expect(issue.events.find((event) => event.kind === "referenced")).toMatchObject({
reference: {
repository: "acme/web",
number: 50,
kind: "pull-request",
url: "https://github.com/acme/web/pull/50",
},
});
}),
);
});
30 changes: 21 additions & 9 deletions packages/source-control-github/src/server/gitHubIssueJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type {
IssueActor,
IssueComment,
IssueEvent,
IssueEventKind,
IssueLabel,
IssueLinkedPullRequest,
IssueState,
Expand Down Expand Up @@ -137,7 +136,7 @@ function toLinkedPullRequest(
/** The change GitHub recorded, or null for a kind this page has no vocabulary for. */
function toEventFields(
raw: TimelineItem,
): { readonly kind: IssueEventKind; readonly detail: string | null } | null {
): Pick<IssueEvent, "kind" | "detail" | "reference"> | null {
switch (raw.__typename) {
case "ClosedEvent":
return { kind: "closed", detail: null };
Expand All @@ -164,15 +163,28 @@ function toEventFields(
case "RenamedTitleEvent":
return { kind: "renamed", detail: trimmed(raw.currentTitle) };
case "CrossReferencedEvent": {
const repository = trimmed(
raw.source != null && "repository" in raw.source
? raw.source.repository.nameWithOwner
: null,
);
const number = raw.source != null && "number" in raw.source ? raw.source.number : 0;
const source =
raw.source.__typename === "PullRequest" || raw.source.__typename === "Issue"
? raw.source
: null;
const repository = trimmed(source?.repository.nameWithOwner);
const url = trimmed(source?.url);
if (source === null || repository === null || source.number <= 0) {
return { kind: "referenced", detail: null };
}
return {
kind: "referenced",
detail: repository === null || number <= 0 ? null : `${repository}#${number}`,
detail: `${repository}#${source.number}`,
...(url === null
? {}
: {
reference: {
repository,
number: source.number,
kind: source.__typename === "PullRequest" ? "pull-request" : "issue",
url,
},
}),
};
}
default:
Expand Down
1 change: 1 addition & 0 deletions packages/source-control-github/src/server/issues.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ query IssueDetail($owner: String!, $name: String!, $number: Int!) {
}
... on Issue {
number
url
repository {
nameWithOwner
}
Expand Down
4 changes: 3 additions & 1 deletion packages/source-control-github/src/server/issues.graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading