diff --git a/api/openapi.yaml b/api/openapi.yaml index 52a192d..695d88a 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -127,7 +127,7 @@ paths: patch: operationId: updateMe tags: [auth] - summary: Update profile fields (chat name color) + summary: Update profile fields (chat name color, GitHub login) requestBody: required: true content: @@ -138,6 +138,9 @@ paths: name_color: type: string description: "#rrggbb, or empty string to clear" + github_login: + type: string + description: GitHub username bound for "mine" filters, or empty to clear responses: "200": description: Updated user @@ -2690,7 +2693,7 @@ paths: properties: pull: type: object - description: "number, title, state, draft, merged, mergeable, body, url, author, head, base, additions, deletions, changed_files, commit_count, labels, created_at, updated_at, repo" + description: "number, title, state, draft, merged, mergeable, body, url, author, head, base, additions, deletions, changed_files, commit_count, labels, assignees, reviewers, teams, merged_by, created_at, updated_at, repo" files: type: array items: { type: object } @@ -2700,6 +2703,42 @@ paths: checks: type: array items: { type: object } + reviews: + type: array + description: latest submitted review state per reviewer + items: { type: object } + review_decision: + type: string + description: approved | changes_requested | pending | "" + "400": { $ref: "#/components/responses/BadRequest" } + "404": { $ref: "#/components/responses/NotFound" } + "502": { description: "GitHub upstream error" } + + /api/projects/{projectId}/github/issue: + get: + operationId: issueDetail + summary: In-app GitHub issue detail — issue plus comment thread + tags: [github] + parameters: + - $ref: "#/components/parameters/ProjectId" + - { name: repo, in: query, schema: { type: string }, description: "owner/name or repo id; optional when only one repo is linked" } + - { name: number, in: query, required: true, schema: { type: integer } } + responses: + "200": + description: Issue detail bundle + content: + application/json: + schema: + type: object + properties: + issue: + type: object + description: "number, title, state, body, url, author, avatar_url, author_type, labels, assignees, comment_count, milestone, created_at, updated_at" + comments: + type: array + items: { type: object } + repo: + type: object "400": { $ref: "#/components/responses/BadRequest" } "404": { $ref: "#/components/responses/NotFound" } "502": { description: "GitHub upstream error" } @@ -2858,6 +2897,159 @@ paths: "400": { $ref: "#/components/responses/BadRequest" } "502": { description: "GitHub upstream error" } + /api/projects/{projectId}/github/labels: + get: + operationId: repoLabels + summary: Label catalog of a linked repository + tags: [github] + parameters: + - $ref: "#/components/parameters/ProjectId" + - { name: repo, in: query, schema: { type: string } } + responses: + "200": + description: Labels + content: + application/json: + schema: + type: object + properties: + labels: + type: array + items: + type: object + properties: + name: { type: string } + color: { type: string } + description: { type: string } + "400": { $ref: "#/components/responses/BadRequest" } + "502": { description: "GitHub upstream error" } + post: + operationId: createRepoLabel + summary: Create a label on a linked repository + tags: [github] + parameters: + - $ref: "#/components/parameters/ProjectId" + - { name: repo, in: query, schema: { type: string } } + requestBody: + required: true + content: + application/json: + schema: + type: object + required: [name] + properties: + name: { type: string } + color: + type: string + description: 6-char hex, with or without '#' + description: { type: string } + responses: + "201": + description: Created label + content: + application/json: + schema: + type: object + properties: + name: { type: string } + color: { type: string } + description: { type: string } + "400": { $ref: "#/components/responses/BadRequest" } + "502": { description: "GitHub upstream error" } + + /api/projects/{projectId}/github/assignees: + get: + operationId: repoAssignees + summary: Assignable users of a linked repository + tags: [github] + parameters: + - $ref: "#/components/parameters/ProjectId" + - { name: repo, in: query, schema: { type: string } } + responses: + "200": + description: Assignable users + content: + application/json: + schema: + type: object + properties: + users: + type: array + items: + type: object + properties: + login: { type: string } + avatar_url: { type: string } + type: { type: string } + "400": { $ref: "#/components/responses/BadRequest" } + "502": { description: "GitHub upstream error" } + + /api/projects/{projectId}/github/issues/update: + post: + operationId: updateGitHubIssue + summary: Update a GitHub issue's title, body, labels, or assignees + description: Each provided set replaces the whole list on GitHub. Works on PR numbers too — they share the issues endpoint upstream. + tags: [github] + parameters: + - $ref: "#/components/parameters/ProjectId" + - { name: repo, in: query, schema: { type: string } } + requestBody: + required: true + content: + application/json: + schema: + type: object + required: [number] + properties: + number: { type: integer } + title: { type: string } + body: { type: string } + labels: { type: array, items: { type: string } } + assignees: { type: array, items: { type: string } } + responses: + "200": + description: Updated issue fields + content: + application/json: + schema: + type: object + properties: + title: { type: string } + body: { type: string } + labels: { type: array, items: { type: object } } + assignees: { type: array, items: { type: object } } + "400": { $ref: "#/components/responses/BadRequest" } + "502": { description: "GitHub upstream error" } + + /api/projects/{projectId}/github/issues/state: + post: + operationId: setIssueState + summary: Close or reopen a GitHub issue + tags: [github] + parameters: + - $ref: "#/components/parameters/ProjectId" + - { name: repo, in: query, schema: { type: string } } + requestBody: + required: true + content: + application/json: + schema: + type: object + required: [number, state] + properties: + number: { type: integer } + state: { type: string, enum: [open, closed] } + responses: + "200": + description: New issue state + content: + application/json: + schema: + type: object + properties: { state: { type: string } } + "400": { $ref: "#/components/responses/BadRequest" } + "502": { description: "GitHub upstream error" } + /api/projects/{projectId}/github/pull/state: post: operationId: setPullState @@ -2975,10 +3167,11 @@ paths: /api/workspaces/{workspaceId}/github/pulls: get: operationId: workspacePulls - summary: Open pull requests across every linked repo in the workspace + summary: Pull requests across every linked repo in the workspace tags: [github] parameters: - { name: workspaceId, in: path, required: true, schema: { type: string, format: uuid } } + - { name: state, in: query, schema: { type: string, enum: [open, closed, all], default: open } } responses: "200": description: PR groups keyed by project+repo @@ -2993,6 +3186,28 @@ paths: "400": { $ref: "#/components/responses/BadRequest" } "403": { $ref: "#/components/responses/Forbidden" } + /api/workspaces/{workspaceId}/github/issues: + get: + operationId: workspaceIssues + summary: Issues across every linked repo in the workspace + tags: [github] + parameters: + - { name: workspaceId, in: path, required: true, schema: { type: string, format: uuid } } + - { name: state, in: query, schema: { type: string, enum: [open, closed, all], default: open } } + responses: + "200": + description: Issue groups keyed by project+repo; issue_id links mirrored Relay issues + content: + application/json: + schema: + type: object + properties: + groups: + type: array + items: { type: object } + "400": { $ref: "#/components/responses/BadRequest" } + "403": { $ref: "#/components/responses/Forbidden" } + /api/projects/{projectId}/github/commits: get: operationId: gitCommits @@ -4393,6 +4608,9 @@ components: name_color: type: ["string", "null"] description: Chat name color as #rrggbb; null = palette default. + github_login: + type: string + description: Bound GitHub username; empty = not linked. avatar_url: { type: ["string", "null"] } created_at: { type: string, format: date-time } @@ -4915,6 +5133,8 @@ components: kind: { type: string, enum: [issue, pr] } state: { type: string, enum: [open, closed, merged], description: "GitHub's raw state" } url: { type: string } + author: { type: string, description: "GitHub login of the issue/PR author" } + avatar_url: { type: string, description: "GitHub avatar URL of the author" } IssueActivity: type: object diff --git a/apps/web/src/App.tsx b/apps/web/src/App.tsx index 88d25b9..64466b8 100644 --- a/apps/web/src/App.tsx +++ b/apps/web/src/App.tsx @@ -5,6 +5,7 @@ import { ConfirmHost } from "./components/Confirm"; import { ProfileModalHost } from "./components/ProfileModal"; import { CommitModalHost } from "./features/github/CommitModal"; import { GitHubCreateModalHost } from "./features/github/CreateModals"; +import { GitHubIssueModalHost } from "./features/github/GitHubIssueModal"; import { Rail } from "./components/Rail"; import { ServerBanner } from "./components/ServerBanner"; import { LimitedBanner } from "./components/LimitedBanner"; @@ -55,6 +56,7 @@ export default function App(props: ParentProps) { + diff --git a/apps/web/src/components/Rail.tsx b/apps/web/src/components/Rail.tsx index 03413c1..90f4966 100644 --- a/apps/web/src/components/Rail.tsx +++ b/apps/web/src/components/Rail.tsx @@ -52,6 +52,7 @@ import { ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, + CircleDotIcon, GitPullRequestIcon, GripIcon, BookmarkIcon, @@ -757,6 +758,7 @@ export function Rail() { if (e.type === "review.created" || e.type === "review.responded") { void refreshUnread(); } + if (e.type.startsWith("issue.")) refetchGh(); }); onCleanup(unsub); createEffect(() => { @@ -768,6 +770,22 @@ export function Rail() { onCleanup(() => window.removeEventListener("keydown", onKey)); }); const active = activeWorkspace(session.workspaces); + // Open-issue/PR counts for the nav badges. Both endpoints cache 60s + // server-side; a missing GitHub app yields null and the badges hide. + const [ghCounts, { refetch: refetchGh }] = createResource( + () => active()?.id, + async (ws) => { + const [pulls, issues] = await Promise.all([ + api.workspacePulls(ws).catch(() => null), + api.workspaceIssues(ws).catch(() => null), + ]); + return { + pulls: pulls?.groups.reduce((n, g) => n + g.pulls.length, 0) ?? null, + issues: + issues?.groups.reduce((n, g) => n + g.issues.length, 0) ?? null, + }; + }, + ); // The rail shows one workspace at a time — workspaces are separate // namespaces, so switching swaps the whole project list. const list = () => @@ -925,6 +943,20 @@ export function Rail() { Pull requests + 0}> + + {ghCounts()?.pulls} + + + + + + Issues + 0}> + + {ghCounts()?.issues} + + diff --git a/apps/web/src/components/icons.tsx b/apps/web/src/components/icons.tsx index 2806dc5..25cb507 100644 --- a/apps/web/src/components/icons.tsx +++ b/apps/web/src/components/icons.tsx @@ -227,6 +227,24 @@ export function IssueIcon(props: IconProps): JSX.Element { ); } +export function CircleDotIcon(props: IconProps): JSX.Element { + return ( + + ); +} + export function GitPullRequestIcon(props: IconProps): JSX.Element { return ( + + {initials(props.author)} + + + + ); +} + +// GhLabelChip renders one GitHub label in its own color — the API returns +// bare hex (no #), absent for labels created outside GitHub's palette. +export function GhLabelChip(props: { + label: { name: string; color?: string }; +}) { + const c = () => (props.label.color ? `#${props.label.color}` : undefined); + return ( + + {props.label.name} + + ); +} + +// isGhBot spots GitHub App/bot authors — the API's `type` field says "Bot" +// reliably; the [bot] suffix stays as the fallback for older payloads. +export function isGhBot(login: string, type?: string): boolean { + return type === "Bot" || login.endsWith("[bot]"); +} + +// GhAuthor renders a GitHub login with avatar — the highlighted filer on +// every issue/PR row. Bots get a small badge instead of pretending human. +export function GhAuthor(props: { + author: string; + url?: string; + type?: string; + avatarClass?: string; +}) { + return ( + + + {props.author} + + + bot + + + + ); +} + +// GhIssueMeta renders labels + assignees with an inline editor — the +// catalogs lazy-load on first expand and the PATCH replaces each set +// wholesale. Shared by the issue modal and the PR detail. +export function GhIssueMeta(props: { + projectId: string; + repo: string; + number: number; + labels: { name: string; color?: string }[]; + assignees: { login: string; avatar_url?: string }[]; + onApplied: (r: { + labels: { name: string; color?: string }[]; + assignees: { login: string; avatar_url?: string }[]; + }) => void; +}) { + const [editing, setEditing] = createSignal(false); + const [busy, setBusy] = createSignal(false); + const [err, setErr] = createSignal(""); + // Draft selections seed from the live values each time editing opens. + const [draftLabels, setDraftLabels] = createSignal([]); + const [draftAssignees, setDraftAssignees] = createSignal([]); + const [catalogs, { mutate: mutateCatalogs }] = createResource( + () => (editing() ? `${props.repo}` : null), + () => + Promise.all([ + api.repoLabels(props.projectId, props.repo), + api.repoAssignees(props.projectId, props.repo), + ]), + ); + + // Inline label creation — POSTs to the repo's label list, then the new + // label lands in the catalog pre-checked. + const [creatingLabel, setCreatingLabel] = createSignal(false); + const [labelName, setLabelName] = createSignal(""); + const [labelColor, setLabelColor] = createSignal("#888888"); + const [labelBusy, setLabelBusy] = createSignal(false); + const createLabel = async () => { + const name = labelName().trim(); + if (!name || labelBusy()) return; + setLabelBusy(true); + setErr(""); + try { + const l = await api.createRepoLabel(props.projectId, props.repo, { + name, + color: labelColor().replace("#", ""), + }); + mutateCatalogs((c) => + c ? [{ labels: [...c[0].labels, { name: l.name, color: l.color ?? "", description: l.description ?? "" }] }, c[1]] : c, + ); + setDraftLabels((d) => (d.includes(l.name) ? d : [...d, l.name])); + setLabelName(""); + setCreatingLabel(false); + } catch { + setErr("Could not create the label"); + } finally { + setLabelBusy(false); + } + }; + + const toggle = (list: () => string[], set: (v: string[]) => void, v: string) => + set(list().includes(v) ? list().filter((x) => x !== v) : [...list(), v]); + + const open = () => { + setDraftLabels(props.labels.map((l) => l.name)); + setDraftAssignees(props.assignees.map((a) => a.login)); + setErr(""); + setEditing(true); + }; + + const apply = async () => { + setBusy(true); + setErr(""); + try { + const r = await api.updateGitHubIssue(props.projectId, props.repo, { + number: props.number, + labels: draftLabels(), + assignees: draftAssignees(), + }); + props.onApplied(r); + setEditing(false); + } catch { + setErr("Could not update — check permissions"); + } finally { + setBusy(false); + } + }; + + return ( + + + {(l) => } + 0}> + a.login).join(", ")}`} + > + + {(a) => ( + + )} + + + + + + +
+
+

+ Labels +

+ } + > +
+ + {(l) => ( + + )} + +
+
+ + setLabelColor(e.currentTarget.value)} + class="h-5 w-6 cursor-pointer rounded border border-border bg-transparent p-0" + title="Label color" + /> + setLabelName(e.currentTarget.value)} + onKeyDown={(e) => { + if (e.key === "Enter") { + e.preventDefault(); + void createLabel(); + } + }} + class="min-w-0 flex-1 rounded border border-border bg-transparent px-1.5 py-0.5 text-[11.5px] text-fg outline-none focus:border-accent" + placeholder="label name" + /> + +
+ } + > + +
+
+ +
+
+

+ Assignees +

+ } + > +
+ + {(u) => ( + + )} + +
+
+
+
+ + + {err()} + +
+ +
+
+ ); +} + function RepoLinker(props: { projectId: string; workspaceId: string; @@ -195,27 +516,35 @@ function RepoLinker(props: { ); } -function IssueRow(props: { - number: number; - title: string; - url: string; - author: string; - updated_at: string; -}) { +function IssueRow( + props: DevRepoPanel["issues"][number] & { projectId: string; repo: string }, +) { return (
  • - - + #{props.number} + + + + 0}> + + + {props.comments} + + {timeAgo(props.updated_at)} @@ -254,6 +583,9 @@ function PrRow(props: DevRepoPanel["prs"][number] & { projectId: string; repo: s {props.head} → {props.base} + + +
  • ); } @@ -704,7 +1036,13 @@ export function DevelopmentPanel(props: { } > - {(i) => } + {(i) => ( + + )}
    (null); + +export function openGhIssue(projectId: string, repo: string, number: number) { + setTarget({ projectId, repo, number }); +} + +export function GitHubIssueModalHost() { + const onKey = (e: KeyboardEvent) => { + if (e.key === "Escape") setTarget(null); + }; + window.addEventListener("keydown", onKey); + onCleanup(() => window.removeEventListener("keydown", onKey)); + return ( + + {(t) => ( + setTarget(null)} + /> + )} + + ); +} + +function GitHubIssueModal(props: { + projectId: string; + repo: string; + number: number; + onClose: () => void; +}) { + const [detail, { refetch, mutate }] = createResource( + () => `${props.repo}#${props.number}`, + () => api.issueDetail(props.projectId, props.repo, props.number), + ); + const [body, setBody] = createSignal(""); + const [busy, setBusy] = createSignal<"comment" | "state" | null>(null); + const [error, setError] = createSignal(""); + const issue = () => detail()?.issue; + + // Inline title/body editor — PATCH issues/{n} upstream. + const [editing, setEditing] = createSignal(false); + const [editBusy, setEditBusy] = createSignal(false); + const [draftTitle, setDraftTitle] = createSignal(""); + const [draftBody, setDraftBody] = createSignal(""); + const startEdit = () => { + const iss = issue(); + if (!iss) return; + setDraftTitle(iss.title); + setDraftBody(iss.body); + setEditing(true); + }; + const saveEdit = async () => { + const iss = issue(); + if (!iss || editBusy() || !draftTitle().trim()) return; + setEditBusy(true); + setError(""); + try { + const r = await api.updateGitHubIssue(props.projectId, props.repo, { + number: iss.number, + title: draftTitle().trim(), + body: draftBody(), + }); + mutate((d) => + d + ? { ...d, issue: { ...d.issue, title: r.title, body: r.body } } + : d, + ); + setEditing(false); + } catch { + setError("Could not save the issue"); + } finally { + setEditBusy(false); + } + }; + + const postComment = async () => { + const text = body().trim(); + if (!text || busy()) return; + setBusy("comment"); + setError(""); + try { + await api.commentOnIssue(props.projectId, props.repo, props.number, text); + setBody(""); + refetch(); + } catch { + setError("Could not post the comment"); + } finally { + setBusy(null); + } + }; + + const toggleState = async () => { + const iss = issue(); + if (!iss || busy()) return; + const next = iss.state === "open" ? "closed" : "open"; + setBusy("state"); + setError(""); + try { + await api.setIssueState(props.projectId, props.repo, props.number, next); + mutate((d) => + d ? { ...d, issue: { ...d.issue, state: next } } : d, + ); + } catch { + setError(`Could not ${next === "closed" ? "close" : "reopen"} the issue`); + } finally { + setBusy(null); + } + }; + + return ( +
    { + if (e.target === e.currentTarget) props.onClose(); + }} + > +
    +
    + + + + {issue()?.title} + + {props.repo}#{props.number} + + + + + {(url) => ( + + + + )} + + +
    + +
    + + } + > +

    Could not load this issue

    +
    +
    + } + > + {(iss) => ( + <> +
    + + {iss().state} + + + opened {timeAgo(iss().created_at)} + 0}> + + + {iss().comment_count} + + + + + {iss().milestone} + + + +
    + +
    + + mutate((d) => + d + ? { + ...d, + issue: { + ...d.issue, + labels: r.labels, + assignees: r.assignees, + }, + } + : d, + ) + } + /> +
    + + + setDraftTitle(e.currentTarget.value)} + class="w-full rounded-lg border border-border bg-transparent px-3 py-2 text-[13px] text-fg outline-none focus:border-accent" + placeholder="Title" + /> +