| 277 | } |
| 278 | |
| 279 | export async function createIssue( |
| 280 | title: string, |
| 281 | body: string, |
| 282 | labels?: string[], |
| 283 | ): Promise<{ |
| 284 | issue?: { id: string; number: number; url: string }; |
| 285 | error?: string; |
| 286 | }> { |
| 287 | const token = getToken(); |
| 288 | if (!token) { |
| 289 | return { error: "GitHub token not configured" }; |
| 290 | } |
| 291 | |
| 292 | const repoQuery = ` |
| 293 | query($owner: String!, $name: String!) { |
| 294 | repository(owner: $owner, name: $name) { |
| 295 | id |
| 296 | labels(first: 50) { |
| 297 | nodes { |
| 298 | id |
| 299 | name |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | `; |
| 305 | |
| 306 | const repoData = (await graphql( |
| 307 | repoQuery, |
| 308 | { owner: MARKETING_REPO_OWNER, name: MARKETING_REPO_NAME }, |
| 309 | token, |
| 310 | )) as { |
| 311 | repository: { |
| 312 | id: string; |
| 313 | labels: { nodes: Array<{ id: string; name: string }> }; |
| 314 | }; |
| 315 | }; |
| 316 | |
| 317 | const labelIds = labels |
| 318 | ? repoData.repository.labels.nodes |
| 319 | .filter((l) => labels.includes(l.name)) |
| 320 | .map((l) => l.id) |
| 321 | : []; |
| 322 | |
| 323 | const mutation = ` |
| 324 | mutation($repositoryId: ID!, $title: String!, $body: String!, $labelIds: [ID!]) { |
| 325 | createIssue(input: { |
| 326 | repositoryId: $repositoryId, |
| 327 | title: $title, |
| 328 | body: $body, |
| 329 | labelIds: $labelIds |
| 330 | }) { |
| 331 | issue { |
| 332 | id |
| 333 | number |
| 334 | url |
| 335 | } |
| 336 | } |