| 779 | } |
| 780 | |
| 781 | func (c *discussionClient) ListCategories(repo ghrepo.Interface) ([]DiscussionCategory, error) { |
| 782 | var query struct { |
| 783 | Repository struct { |
| 784 | HasDiscussionsEnabled bool |
| 785 | DiscussionCategories struct { |
| 786 | Nodes []struct { |
| 787 | ID string |
| 788 | Name string |
| 789 | Slug string |
| 790 | Emoji string |
| 791 | IsAnswerable bool |
| 792 | } |
| 793 | } `graphql:"discussionCategories(first: 100)"` |
| 794 | } `graphql:"repository(owner: $owner, name: $name)"` |
| 795 | } |
| 796 | |
| 797 | variables := map[string]interface{}{ |
| 798 | "owner": githubv4.String(repo.RepoOwner()), |
| 799 | "name": githubv4.String(repo.RepoName()), |
| 800 | } |
| 801 | |
| 802 | if err := c.gql.Query(repo.RepoHost(), "DiscussionCategoryList", &query, variables); err != nil { |
| 803 | return nil, err |
| 804 | } |
| 805 | |
| 806 | if !query.Repository.HasDiscussionsEnabled { |
| 807 | return nil, fmt.Errorf("the '%s/%s' repository has discussions disabled", repo.RepoOwner(), repo.RepoName()) |
| 808 | } |
| 809 | |
| 810 | categories := make([]DiscussionCategory, len(query.Repository.DiscussionCategories.Nodes)) |
| 811 | for i, n := range query.Repository.DiscussionCategories.Nodes { |
| 812 | categories[i] = DiscussionCategory{ |
| 813 | ID: n.ID, |
| 814 | Name: n.Name, |
| 815 | Slug: n.Slug, |
| 816 | Emoji: n.Emoji, |
| 817 | IsAnswerable: n.IsAnswerable, |
| 818 | } |
| 819 | } |
| 820 | |
| 821 | return categories, nil |
| 822 | } |
| 823 | |
| 824 | // repositoryMeta holds the node ID, database ID, and feature flags fetched for a repository. |
| 825 | type repositoryMeta struct { |