Create GitHub issues with markdown and metadata (#3947)

* Create GitHub issues with markdown and metadata

- Add a reusable rich markdown composer for GitHub issue bodies and comments
- Let new GitHub issues include selected labels and assignees through IPC/RPC
- Preserve created issue metadata in the task list and cover the new API path with tests

* fix: address review findings
This commit is contained in:
Jinjing
2026-05-30 18:25:31 -07:00
committed by GitHub
parent bb6b872386
commit 9ca42f5582
16 changed files with 857 additions and 434 deletions
+40
View File
@@ -126,6 +126,46 @@ describe('issue source operations', () => {
)
})
it('creates issues with labels and assignees', async () => {
getIssueOwnerRepoMock.mockResolvedValueOnce({ owner: 'stablyai', repo: 'orca' })
ghExecFileAsyncMock.mockResolvedValueOnce({
stdout: JSON.stringify({
number: 925,
html_url: 'https://github.com/stablyai/orca/issues/925'
})
})
await expect(
createIssue('/repo-root', 'New issue', 'Body', undefined, undefined, {
labels: ['bug', 'frontend'],
assignees: ['octo']
})
).resolves.toEqual({
ok: true,
number: 925,
url: 'https://github.com/stablyai/orca/issues/925'
})
expect(ghExecFileAsyncMock).toHaveBeenCalledWith(
[
'api',
'-X',
'POST',
'repos/stablyai/orca/issues',
'--raw-field',
'title=New issue',
'--raw-field',
'body=Body',
'--raw-field',
'labels[]=bug',
'--raw-field',
'labels[]=frontend',
'--raw-field',
'assignees[]=octo'
],
{ cwd: '/repo-root' }
)
})
it('updates issue body through the REST issue endpoint', async () => {
getIssueOwnerRepoMock.mockResolvedValueOnce({ owner: 'stablyai', repo: 'orca' })
ghExecFileAsyncMock.mockResolvedValueOnce({ stdout: '' })
+21 -14
View File
@@ -5,6 +5,7 @@ surface is broad. */
import type {
ClassifiedError,
GitHubAssignableUser,
GitHubCreateIssueFields,
GitHubCommentResult,
GitHubIssueUpdate,
IssueInfo,
@@ -150,7 +151,8 @@ export async function createIssue(
title: string,
body: string,
preference?: IssueSourcePreference,
connectionId?: string | null
connectionId?: string | null,
fields?: GitHubCreateIssueFields
): Promise<{ ok: true; number: number; url: string } | { ok: false; error: string }> {
const trimmedTitle = title.trim()
if (!trimmedTitle) {
@@ -164,19 +166,24 @@ export async function createIssue(
}
await acquire()
try {
const { stdout } = await ghExecFileAsync(
[
'api',
'-X',
'POST',
`repos/${ownerRepo.owner}/${ownerRepo.repo}/issues`,
'--raw-field',
`title=${trimmedTitle}`,
'--raw-field',
`body=${body}`
],
ghOptions
)
const args = [
'api',
'-X',
'POST',
`repos/${ownerRepo.owner}/${ownerRepo.repo}/issues`,
'--raw-field',
`title=${trimmedTitle}`,
'--raw-field',
`body=${body}`
]
for (const label of fields?.labels ?? []) {
args.push('--raw-field', `labels[]=${label}`)
}
for (const assignee of fields?.assignees ?? []) {
args.push('--raw-field', `assignees[]=${assignee}`)
}
const { stdout } = await ghExecFileAsync(args, ghOptions)
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' }