Check hasDiscussionsEnabled in ListCategories
When --category is used, ListCategories runs before the List query. On repos with discussions disabled, it silently returns empty categories, leading to a confusing "must be one of []" error. Now it checks hasDiscussionsEnabled and returns the standard "discussions disabled" error, matching the behavior of List and Search. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
a08f5f22f0
commit
17238050d7
1 changed files with 6 additions and 1 deletions
|
|
@ -414,7 +414,8 @@ func (c *discussionClient) GetWithComments(_ ghrepo.Interface, _ int, _ int, _ s
|
|||
func (c *discussionClient) ListCategories(repo ghrepo.Interface) ([]DiscussionCategory, error) {
|
||||
var query struct {
|
||||
Repository struct {
|
||||
DiscussionCategories struct {
|
||||
HasDiscussionsEnabled bool
|
||||
DiscussionCategories struct {
|
||||
Nodes []struct {
|
||||
ID string
|
||||
Name string
|
||||
|
|
@ -435,6 +436,10 @@ func (c *discussionClient) ListCategories(repo ghrepo.Interface) ([]DiscussionCa
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if !query.Repository.HasDiscussionsEnabled {
|
||||
return nil, fmt.Errorf("the '%s/%s' repository has discussions disabled", repo.RepoOwner(), repo.RepoName())
|
||||
}
|
||||
|
||||
categories := make([]DiscussionCategory, len(query.Repository.DiscussionCategories.Nodes))
|
||||
for i, n := range query.Repository.DiscussionCategories.Nodes {
|
||||
categories[i] = DiscussionCategory{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue