From c6043a67024746e18a9013d60754c353bb80cee0 Mon Sep 17 00:00:00 2001 From: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Date: Thu, 21 May 2026 13:30:41 -0700 Subject: [PATCH] Show GitHub issue assignees in the task list (#2557) --- src/main/github/client-work-items.test.ts | 30 ++- src/main/github/client.ts | 19 +- src/renderer/src/components/TaskPage.tsx | 248 +++++++++++++++++++++- 3 files changed, 278 insertions(+), 19 deletions(-) diff --git a/src/main/github/client-work-items.test.ts b/src/main/github/client-work-items.test.ts index c88edd68f..e8e3dcba8 100644 --- a/src/main/github/client-work-items.test.ts +++ b/src/main/github/client-work-items.test.ts @@ -99,7 +99,14 @@ describe('listWorkItems', () => { url: 'https://github.com/acme/widgets/issues/12', labels: [], updatedAt: '2026-03-29T00:00:00Z', - author: { login: 'octocat' } + author: { login: 'octocat' }, + assignees: [ + { + login: 'test-assignee', + name: 'Test Assignee', + databaseId: 1 + } + ] } ]) }) @@ -120,8 +127,8 @@ describe('listWorkItems', () => { reviewRequests: [ { requestedReviewer: { - login: 'AmethystLiang', - name: 'Amethyst Liang', + login: 'test-assignee', + name: 'Test Assignee', avatarUrl: 'https://avatars.githubusercontent.com/u/1?v=4' } } @@ -142,7 +149,7 @@ describe('listWorkItems', () => { '--limit', '10', '--json', - 'number,title,state,url,labels,updatedAt,author', + 'number,title,state,url,labels,updatedAt,author,assignees', '--repo', 'acme/widgets', '--assignee', @@ -180,7 +187,14 @@ describe('listWorkItems', () => { url: 'https://github.com/acme/widgets/issues/12', labels: [], updatedAt: '2026-03-29T00:00:00Z', - author: 'octocat' + author: 'octocat', + assignees: [ + { + login: 'test-assignee', + name: 'Test Assignee', + avatarUrl: 'https://avatars.githubusercontent.com/u/1?v=4' + } + ] }, { id: 'pr:42', @@ -198,8 +212,8 @@ describe('listWorkItems', () => { prRepo: { owner: 'acme', repo: 'widgets' }, reviewRequests: [ { - login: 'AmethystLiang', - name: 'Amethyst Liang', + login: 'test-assignee', + name: 'Test Assignee', avatarUrl: 'https://avatars.githubusercontent.com/u/1?v=4' } ] @@ -453,7 +467,7 @@ describe('listWorkItems', () => { '--limit', '10', '--json', - 'number,title,state,url,labels,updatedAt,author', + 'number,title,state,url,labels,updatedAt,author,assignees', '--repo', 'acme/widgets', '--state', diff --git a/src/main/github/client.ts b/src/main/github/client.ts index 5c822e9a1..cc31e464a 100644 --- a/src/main/github/client.ts +++ b/src/main/github/client.ts @@ -331,6 +331,8 @@ export async function getAuthenticatedViewer(): Promise { // single-repo and cross-repo items are uniform downstream. type MainWorkItem = Omit +const WORK_ITEM_ISSUE_LIST_JSON_FIELDS = 'number,title,state,url,labels,updatedAt,author,assignees' + const WORK_ITEM_PR_LIST_JSON_FIELDS = 'number,title,state,url,labels,updatedAt,author,isDraft,headRefName,baseRefName,headRefOid,headRepositoryOwner,reviewRequests' @@ -364,7 +366,8 @@ function mapIssueWorkItem(item: Record): MainWorkItem { ? String((item.user as { login?: unknown }).login ?? '') : typeof item.author === 'object' && item.author !== null && 'login' in item.author ? String((item.author as { login?: unknown }).login ?? '') - : null + : null, + ...(item.assignees !== undefined ? { assignees: usersFromUnknown(item.assignees) } : {}) } } @@ -423,6 +426,7 @@ function userFromUnknown( if (!login) { return null } + const databaseId = numberFromUnknown(raw.databaseId) return { login, name: typeof raw.name === 'string' ? raw.name : null, @@ -431,7 +435,9 @@ function userFromUnknown( ? raw.avatarUrl : typeof raw.avatar_url === 'string' ? raw.avatar_url - : '' + : databaseId !== undefined + ? `https://avatars.githubusercontent.com/u/${databaseId}?v=4` + : '' } } @@ -707,10 +713,7 @@ function buildWorkItemListArgs(args: { before?: string }): string[] { const { kind, ownerRepo, limit, query, before } = args - const fields = - kind === 'issue' - ? 'number,title,state,url,labels,updatedAt,author' - : WORK_ITEM_PR_LIST_JSON_FIELDS + const fields = kind === 'issue' ? WORK_ITEM_ISSUE_LIST_JSON_FIELDS : WORK_ITEM_PR_LIST_JSON_FIELDS const command = kind === 'issue' ? ['issue', 'list'] : ['pr', 'list'] const out = [...command, '--limit', String(limit), '--json', fields] @@ -828,7 +831,7 @@ async function listRecentWorkItems( '--state', 'open', '--json', - 'number,title,state,url,labels,updatedAt,author' + WORK_ITEM_ISSUE_LIST_JSON_FIELDS ], ghOptions ), @@ -924,7 +927,7 @@ async function listRecentWorkItems( '--state', 'open', '--json', - 'number,title,state,url,labels,updatedAt,author' + WORK_ITEM_ISSUE_LIST_JSON_FIELDS ], ghOptions ), diff --git a/src/renderer/src/components/TaskPage.tsx b/src/renderer/src/components/TaskPage.tsx index 19c67ad93..b9efdf67b 100644 --- a/src/renderer/src/components/TaskPage.tsx +++ b/src/renderer/src/components/TaskPage.tsx @@ -252,7 +252,7 @@ const LINEAR_ITEM_LIMIT = 36 const PR_CHECKS_EAGER_PREFETCH_LIMIT = 20 const GITHUB_TASK_GRID_CLASS = - 'min-w-[860px] grid-cols-[72px_minmax(260px,2fr)_minmax(130px,0.8fr)_100px_92px_158px]' + 'min-w-[790px] grid-cols-[72px_minmax(320px,1fr)_84px_100px_92px_122px]' const GITHUB_PR_TASK_GRID_CLASS = 'min-w-[1170px] grid-cols-[72px_minmax(260px,2fr)_minmax(130px,0.8fr)_132px_128px_132px_92px_158px]' const GITHUB_TASK_ROW_SURFACE_CLASS = @@ -862,6 +862,248 @@ function ReviewChipAvatar({ return } +function GitHubAssigneeAvatar({ assignee }: { assignee: GitHubAssignableUser }): React.JSX.Element { + if (assignee.avatarUrl) { + return ( + {assignee.login} + ) + } + return ( + + {assignee.login.slice(0, 1).toUpperCase()} + + ) +} + +function GHAssigneesCell({ + item, + repo +}: { + item: GitHubWorkItem + repo: Repo | null +}): React.JSX.Element { + const patchWorkItem = useAppStore((s) => s.patchWorkItem) + const settings = useAppStore((s) => s.settings) + const [open, setOpen] = useState(false) + const [pendingLogin, setPendingLogin] = useState(null) + const assignees = useMemo(() => item.assignees ?? [], [item.assignees]) + const parsed = useMemo(() => parseGitHubIssueOrPRLink(item.url), [item.url]) + const owner = parsed?.slug.owner ?? null + const repoName = parsed?.slug.repo ?? null + const seedLogins = useMemo( + () => + assignees + .map((a) => a.login) + .sort() + .filter(Boolean), + [assignees] + ) + const metadata = useRepoAssigneesBySlug( + open ? owner : null, + open ? repoName : null, + seedLogins, + settings + ) + + const toggleAssignee = useCallback( + async (user: GitHubAssignableUser): Promise => { + if (item.type !== 'issue' || pendingLogin) { + return + } + const userLoginKey = user.login.toLowerCase() + const isOn = assignees.some((a) => a.login.toLowerCase() === userLoginKey) + const previousAssignees = assignees + const nextAssignees = isOn + ? assignees.filter((a) => a.login.toLowerCase() !== userLoginKey) + : [...assignees, user] + setPendingLogin(user.login) + patchWorkItem(item.id, { assignees: nextAssignees }, item.repoId) + + try { + const updates = isOn ? { removeAssignees: [user.login] } : { addAssignees: [user.login] } + const target = getActiveRuntimeTarget(settings) + if (owner && repoName) { + const args = { + owner, + repo: repoName, + number: item.number, + updates + } + const res = + target.kind === 'environment' + ? await callRuntimeRpc>>( + target, + 'github.project.updateIssueBySlug', + args, + { timeoutMs: 30_000 } + ) + : await window.api.gh.updateIssueBySlug(args) + if (!res.ok) { + throw new Error(res.error.message) + } + } else if (repo) { + const res = + target.kind === 'environment' + ? await callRuntimeRpc<{ ok?: boolean; error?: string }>( + target, + 'github.updateIssue', + { repo: repo.id, number: item.number, updates }, + { timeoutMs: 30_000 } + ) + : await window.api.gh.updateIssue({ + repoPath: repo.path, + repoId: repo.id, + number: item.number, + updates + }) + if (res && res.ok === false) { + throw new Error(res.error) + } + } else { + throw new Error('No GitHub repository context available for this issue.') + } + } catch (err) { + patchWorkItem(item.id, { assignees: previousAssignees }, item.repoId) + toast.error(err instanceof Error ? err.message : 'Failed to update assignees.') + } finally { + setPendingLogin(null) + } + }, + [ + assignees, + item.id, + item.number, + item.repoId, + item.type, + owner, + patchWorkItem, + pendingLogin, + repo, + repoName, + settings + ] + ) + + const triggerContent = + assignees.length > 0 ? ( + <> +
+ {assignees.slice(0, 3).map((assignee) => ( + + ))} +
+ {assignees.length > 3 ? ( + + +{assignees.length - 3} + + ) : null} + + ) : ( + - + ) + + return ( + + + + + event.stopPropagation()} + > + {!owner || !repoName ? ( +
Issue has no repo slug.
+ ) : metadata.loading ? ( +
Loading…
+ ) : metadata.error ? ( +
{metadata.error}
+ ) : metadata.data.length === 0 ? ( +
No assignable users.
+ ) : ( + metadata.data.map((user) => { + const isOn = assignees.some((a) => a.login.toLowerCase() === user.login.toLowerCase()) + const pending = pendingLogin === user.login + return ( + + ) + }) + )} +
+
+ ) +} + function getChecksLabel(item: GitHubWorkItem): string { const summary = item.checksSummary if (!summary) { @@ -4530,7 +4772,7 @@ export default function TaskPage(): React.JSX.Element { > ID Title / Context - Branch + {activeGithubTaskKind === 'issues' ? 'Assignees' : 'Branch'} {showPRManagementColumns ? ( <> Reviewers @@ -4778,7 +5020,7 @@ export default function TaskPage(): React.JSX.Element { ) : ( - workspace/default + )}