diff --git a/src/main/github/client.ts b/src/main/github/client.ts index efdf45938..1e140bf73 100644 --- a/src/main/github/client.ts +++ b/src/main/github/client.ts @@ -11,7 +11,7 @@ import type { import { getPRConflictSummary } from './conflict-summary' import { execFileAsync, ghExecFileAsync, acquire, release, getOwnerRepo } from './gh-utils' export { _resetOwnerRepoCache } from './gh-utils' -export { getIssue, listIssues } from './issues' +export { getIssue, listIssues, createIssue } from './issues' import { mapCheckRunRESTStatus, mapCheckRunRESTConclusion, diff --git a/src/main/github/issues.ts b/src/main/github/issues.ts index 224fce4d9..9df848971 100644 --- a/src/main/github/issues.ts +++ b/src/main/github/issues.ts @@ -71,3 +71,53 @@ export async function listIssues(repoPath: string, limit = 20): Promise { + const trimmedTitle = title.trim() + if (!trimmedTitle) { + return { ok: false, error: 'Title is required' } + } + const ownerRepo = await getOwnerRepo(repoPath) + if (!ownerRepo) { + return { ok: false, error: 'Could not resolve GitHub owner/repo for this repository' } + } + await acquire() + try { + const { stdout } = await ghExecFileAsync( + [ + 'api', + '-X', + 'POST', + `repos/${ownerRepo.owner}/${ownerRepo.repo}/issues`, + '-f', + `title=${trimmedTitle}`, + '-f', + `body=${body}` + ], + { cwd: repoPath } + ) + const data = JSON.parse(stdout) as { number?: number; html_url?: string; url?: string } + if (typeof data.number !== 'number') { + return { ok: false, error: 'Unexpected response from GitHub' } + } + return { + ok: true, + number: data.number, + url: String(data.html_url ?? data.url ?? '') + } + } catch (err) { + const message = err instanceof Error ? err.message : String(err) + return { ok: false, error: message } + } finally { + release() + } +} diff --git a/src/main/ipc/github.ts b/src/main/ipc/github.ts index bad360b09..41d10c062 100644 --- a/src/main/ipc/github.ts +++ b/src/main/ipc/github.ts @@ -10,6 +10,7 @@ import { listIssues, listWorkItems, getWorkItem, + createIssue, getAuthenticatedViewer, getPRChecks, getPRComments, @@ -61,6 +62,14 @@ export function registerGitHubHandlers(store: Store, stats: StatsCollector): voi return listIssues(repo.path, args.limit) }) + ipcMain.handle( + 'gh:createIssue', + (_event, args: { repoPath: string; title: string; body: string }) => { + const repo = assertRegisteredRepo(args.repoPath, store) + return createIssue(repo.path, args.title, args.body) + } + ) + ipcMain.handle( 'gh:listWorkItems', (_event, args: { repoPath: string; limit?: number; query?: string }) => { diff --git a/src/preload/api-types.d.ts b/src/preload/api-types.d.ts index a6d1bbfe0..333802cfc 100644 --- a/src/preload/api-types.d.ts +++ b/src/preload/api-types.d.ts @@ -343,6 +343,11 @@ export type PreloadApi = { baseSha: string }) => Promise listIssues: (args: { repoPath: string; limit?: number }) => Promise + createIssue: (args: { + repoPath: string + title: string + body: string + }) => Promise<{ ok: true; number: number; url: string } | { ok: false; error: string }> listWorkItems: (args: { repoPath: string limit?: number diff --git a/src/preload/index.d.ts b/src/preload/index.d.ts index b01d8cf05..c9519d684 100644 --- a/src/preload/index.d.ts +++ b/src/preload/index.d.ts @@ -104,6 +104,11 @@ type GhApi = { baseSha: string }) => Promise listIssues: (args: { repoPath: string; limit?: number }) => Promise + createIssue: (args: { + repoPath: string + title: string + body: string + }) => Promise<{ ok: true; number: number; url: string } | { ok: false; error: string }> listWorkItems: (args: { repoPath: string limit?: number diff --git a/src/preload/index.ts b/src/preload/index.ts index 2c60acb7b..fb5e31a5e 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -367,6 +367,13 @@ const api = { listIssues: (args: { repoPath: string; limit?: number }): Promise => ipcRenderer.invoke('gh:listIssues', args), + createIssue: (args: { + repoPath: string + title: string + body: string + }): Promise<{ ok: true; number: number; url: string } | { ok: false; error: string }> => + ipcRenderer.invoke('gh:createIssue', args), + listWorkItems: (args: { repoPath: string limit?: number diff --git a/src/renderer/src/components/GitHubItemDrawer.tsx b/src/renderer/src/components/GitHubItemDrawer.tsx index 2958b95ea..7bfcc2390 100644 --- a/src/renderer/src/components/GitHubItemDrawer.tsx +++ b/src/renderer/src/components/GitHubItemDrawer.tsx @@ -446,6 +446,34 @@ export default function GitHubItemDrawer({ const requestIdRef = useRef(0) + // Why: when this drawer opens immediately after another Radix overlay + // (e.g. the New Issue dialog) closed, Radix may leave `pointer-events: none` + // on . That silently kills clicks on the header's Close/open-in-GitHub + // buttons. Poll a few frames to clear it whenever Radix re-applies it during + // its own mount sequence. + useEffect(() => { + if (!workItem) { + return + } + let cancelled = false + let count = 0 + const tick = (): void => { + if (cancelled) { + return + } + if (document.body.style.pointerEvents === 'none') { + document.body.style.pointerEvents = '' + } + if (count++ < 5) { + requestAnimationFrame(tick) + } + } + tick() + return () => { + cancelled = true + } + }, [workItem]) + useEffect(() => { if (!workItem || !repoPath) { setDetails(null) diff --git a/src/renderer/src/components/NewWorkspacePage.tsx b/src/renderer/src/components/NewWorkspacePage.tsx index c4f862fd6..e1cc37c11 100644 --- a/src/renderer/src/components/NewWorkspacePage.tsx +++ b/src/renderer/src/components/NewWorkspacePage.tsx @@ -11,6 +11,7 @@ import { Github, GitPullRequest, LoaderCircle, + Plus, RefreshCw, Search, X @@ -19,6 +20,14 @@ import { toast } from 'sonner' import { useAppStore } from '@/store' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle +} from '@/components/ui/dialog' import { DropdownMenu, DropdownMenuContent, @@ -206,6 +215,10 @@ export default function NewWorkspacePage(): React.JSX.Element { // The composer modal is only opened by the drawer's "Use" button, which // calls the same handleSelectWorkItem as the old direct row-click flow. const [drawerWorkItem, setDrawerWorkItem] = useState(null) + const [newIssueOpen, setNewIssueOpen] = useState(false) + const [newIssueTitle, setNewIssueTitle] = useState('') + const [newIssueBody, setNewIssueBody] = useState('') + const [newIssueSubmitting, setNewIssueSubmitting] = useState(false) const filteredWorkItems = useMemo(() => { if (!activeTaskPreset) { @@ -368,12 +381,73 @@ export default function NewWorkspacePage(): React.JSX.Element { [openModal, repoId] ) + const handleCreateNewIssue = useCallback(async (): Promise => { + if (!selectedRepo) { + return + } + const title = newIssueTitle.trim() + if (!title || newIssueSubmitting) { + return + } + setNewIssueSubmitting(true) + try { + const result = await window.api.gh.createIssue({ + repoPath: selectedRepo.path, + title, + body: newIssueBody + }) + if (!result.ok) { + toast.error(result.error || 'Failed to create issue.') + return + } + toast.success(`Opened issue #${result.number}`, { + action: result.url + ? { + label: 'View', + onClick: () => window.open(result.url, '_blank') + } + : undefined + }) + setNewIssueOpen(false) + setNewIssueTitle('') + setNewIssueBody('') + // Why: bump the nonce so the list refetches and shows the new issue. + setTaskRefreshNonce((current) => current + 1) + + // Why: auto-open the new issue in the side drawer so the user sees + // exactly what was filed. Use an optimistic stub first so the drawer + // has immediate content, then refine with the full `workItem` fetch. + const stub: GitHubWorkItem = { + id: `issue:${String(result.number)}`, + type: 'issue', + number: result.number, + title, + state: 'open', + url: result.url, + labels: [], + updatedAt: new Date().toISOString(), + author: null + } + setDrawerWorkItem(stub) + void window.api.gh + .workItem({ repoPath: selectedRepo.path, number: result.number }) + .then((full) => { + if (full) { + setDrawerWorkItem(full) + } + }) + .catch(() => {}) + } finally { + setNewIssueSubmitting(false) + } + }, [newIssueBody, newIssueSubmitting, newIssueTitle, selectedRepo]) + useEffect(() => { // Why: when the GitHub preview sheet is open, Radix's Dialog owns Esc — // it closes the sheet on its own. Page-level capture would otherwise fire // first and pop the tasks page while the user just meant to dismiss the // preview. - if (drawerWorkItem) { + if (drawerWorkItem || newIssueOpen) { return } @@ -407,7 +481,7 @@ export default function NewWorkspacePage(): React.JSX.Element { window.addEventListener('keydown', onKeyDown, { capture: true }) return () => window.removeEventListener('keydown', onKeyDown, { capture: true }) - }, [closeNewWorkspacePage, drawerWorkItem]) + }, [closeNewWorkspacePage, drawerWorkItem, newIssueOpen]) return (
@@ -514,6 +588,27 @@ export default function NewWorkspacePage(): React.JSX.Element {
+ + + + + + New GitHub issue + +
+ { + if (!newIssueSubmitting) { + setNewIssueOpen(open) + } + }} + > + { + if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) { + event.preventDefault() + void handleCreateNewIssue() + } + }} + > + + New GitHub issue + + Opens a new issue in {selectedRepo?.displayName ?? 'this repository'}. + + +
+
+ + setNewIssueTitle(e.target.value)} + placeholder="Short summary" + disabled={newIssueSubmitting} + /> +
+
+ +