fix(discussion/client): fetch author/answerChosenBy fields
Signed-off-by: Babak K. Shandiz <babakks@github.com>
This commit is contained in:
parent
15d3eeae06
commit
034e38f0e7
3 changed files with 24 additions and 12 deletions
|
|
@ -33,6 +33,8 @@ type discussionNode struct {
|
|||
StateReason string `json:"stateReason"`
|
||||
Author struct {
|
||||
Login string `json:"login"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
} `json:"author"`
|
||||
Category struct {
|
||||
ID string `json:"id"`
|
||||
|
|
@ -52,6 +54,8 @@ type discussionNode struct {
|
|||
AnswerChosenAt time.Time `json:"answerChosenAt"`
|
||||
AnswerChosenBy *struct {
|
||||
Login string `json:"login"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
} `json:"answerChosenBy"`
|
||||
ReactionGroups []struct {
|
||||
Content string `json:"content"`
|
||||
|
|
@ -74,7 +78,11 @@ func mapDiscussion(n discussionNode) Discussion {
|
|||
URL: n.URL,
|
||||
Closed: n.Closed,
|
||||
StateReason: n.StateReason,
|
||||
Author: DiscussionAuthor{Login: n.Author.Login},
|
||||
Author: DiscussionActor{
|
||||
ID: n.Author.ID,
|
||||
Login: n.Author.Login,
|
||||
Name: n.Author.Name,
|
||||
},
|
||||
Category: DiscussionCategory{
|
||||
ID: n.Category.ID,
|
||||
Name: n.Category.Name,
|
||||
|
|
@ -91,7 +99,11 @@ func mapDiscussion(n discussionNode) Discussion {
|
|||
}
|
||||
|
||||
if n.AnswerChosenBy != nil {
|
||||
d.AnswerChosenBy = &DiscussionAuthor{Login: n.AnswerChosenBy.Login}
|
||||
d.AnswerChosenBy = &DiscussionActor{
|
||||
ID: n.AnswerChosenBy.ID,
|
||||
Login: n.AnswerChosenBy.Login,
|
||||
Name: n.AnswerChosenBy.Name,
|
||||
}
|
||||
}
|
||||
|
||||
d.Labels = make([]DiscussionLabel, len(n.Labels.Nodes))
|
||||
|
|
@ -111,10 +123,10 @@ func mapDiscussion(n discussionNode) Discussion {
|
|||
// It is shared by both List (repository.discussions) and Search queries.
|
||||
const discussionFields = `
|
||||
id number title body url closed stateReason
|
||||
author { login }
|
||||
author { login ...on User { id name } ...on Bot { id } }
|
||||
category { id name slug emoji isAnswerable }
|
||||
labels(first: 20) { nodes { id name color } }
|
||||
isAnswered answerChosenAt answerChosenBy { login }
|
||||
isAnswered answerChosenAt answerChosenBy { login ...on User { id name } ...on Bot { id } }
|
||||
reactionGroups { content users { totalCount } }
|
||||
createdAt updatedAt closedAt locked
|
||||
`
|
||||
|
|
|
|||
|
|
@ -12,12 +12,12 @@ type Discussion struct {
|
|||
URL string
|
||||
Closed bool
|
||||
StateReason string
|
||||
Author DiscussionAuthor
|
||||
Author DiscussionActor
|
||||
Category DiscussionCategory
|
||||
Labels []DiscussionLabel
|
||||
Answered bool
|
||||
AnswerChosenAt time.Time
|
||||
AnswerChosenBy *DiscussionAuthor
|
||||
AnswerChosenBy *DiscussionActor
|
||||
Comments DiscussionCommentList
|
||||
ReactionGroups []ReactionGroup
|
||||
CreatedAt time.Time
|
||||
|
|
@ -103,15 +103,15 @@ func (d Discussion) ExportData(fields []string) map[string]interface{} {
|
|||
return data
|
||||
}
|
||||
|
||||
// DiscussionAuthor represents the author of a discussion or comment.
|
||||
type DiscussionAuthor struct {
|
||||
// DiscussionActor represents a GitHub actor (user or bot) associated with a discussion.
|
||||
type DiscussionActor struct {
|
||||
ID string
|
||||
Login string
|
||||
Name string
|
||||
}
|
||||
|
||||
// Export returns the author as a map for JSON output.
|
||||
func (a DiscussionAuthor) Export() map[string]interface{} {
|
||||
func (a DiscussionActor) Export() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"id": a.ID,
|
||||
"login": a.Login,
|
||||
|
|
@ -159,7 +159,7 @@ func (l DiscussionLabel) Export() map[string]interface{} {
|
|||
type DiscussionComment struct {
|
||||
ID string
|
||||
URL string
|
||||
Author DiscussionAuthor
|
||||
Author DiscussionActor
|
||||
Body string
|
||||
CreatedAt time.Time
|
||||
IsAnswer bool
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ func sampleDiscussions() []client.Discussion {
|
|||
Number: 42,
|
||||
Title: "Bug report discussion",
|
||||
URL: "https://github.com/OWNER/REPO/discussions/42",
|
||||
Author: client.DiscussionAuthor{Login: "monalisa"},
|
||||
Author: client.DiscussionActor{Login: "monalisa"},
|
||||
Category: client.DiscussionCategory{
|
||||
ID: "CAT1",
|
||||
Name: "General",
|
||||
|
|
@ -40,7 +40,7 @@ func sampleDiscussions() []client.Discussion {
|
|||
Number: 41,
|
||||
Title: "Feature request",
|
||||
URL: "https://github.com/OWNER/REPO/discussions/41",
|
||||
Author: client.DiscussionAuthor{Login: "octocat"},
|
||||
Author: client.DiscussionActor{Login: "octocat"},
|
||||
Category: client.DiscussionCategory{
|
||||
ID: "CAT2",
|
||||
Name: "Ideas",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue