( token: string, commentId: string )
| 767 | } |
| 768 | const repoData = result.data?.repository as { |
| 769 | id: string; |
| 770 | hasDiscussionsEnabled: boolean; |
| 771 | discussionCategories: { nodes: Array<{ id: string; name: string; isAnswerable: boolean }> }; |
| 772 | } | null; |
| 773 | if (!repoData) { |
| 774 | throw new Error('Could not fetch repository data. Check that the repo exists and the token has access.'); |
| 775 | } |
| 776 | return { |
| 777 | repoNodeId: repoData.id, |
| 778 | hasDiscussions: repoData.hasDiscussionsEnabled, |
| 779 | categories: repoData.discussionCategories.nodes.map(c => ({ |
| 780 | id: c.id, |
| 781 | name: c.name, |
| 782 | isAnswerable: c.isAnswerable, |
| 783 | })), |
| 784 | }; |
| 785 | } |
| 786 | |
| 787 | /** |
| 788 | * Create a discussion in a repo using GraphQL. |
| 789 | * Returns { discussionId, discussionNumber, discussionUrl }. |
| 790 | */ |
| 791 | export async function createDiscussion( |
| 792 | token: string, |
| 793 | repoNodeId: string, |
| 794 | categoryId: string, |
| 795 | title: string, |
| 796 | body: string |
| 797 | ): Promise<{ discussionId: string; discussionNumber: number; discussionUrl: string }> { |
| 798 | const mutation = ` |
| 799 | mutation($repoId: ID!, $categoryId: ID!, $title: String!, $body: String!) { |
nothing calls this directly
no test coverage detected