fix(discussion list): replace state with closed in domain types
Signed-off-by: Babak K. Shandiz <babakks@github.com>
This commit is contained in:
parent
3f52503a67
commit
236224dc44
5 changed files with 16 additions and 16 deletions
|
|
@ -67,17 +67,12 @@ type discussionNode struct {
|
|||
|
||||
// mapDiscussion converts a GraphQL discussionNode response into the domain Discussion type.
|
||||
func mapDiscussion(n discussionNode) Discussion {
|
||||
state := "OPEN"
|
||||
if n.Closed {
|
||||
state = "CLOSED"
|
||||
}
|
||||
|
||||
d := Discussion{
|
||||
ID: n.ID,
|
||||
Number: n.Number,
|
||||
Title: n.Title,
|
||||
URL: n.URL,
|
||||
State: state,
|
||||
Closed: n.Closed,
|
||||
StateReason: n.StateReason,
|
||||
Author: DiscussionAuthor{Login: n.Author.Login},
|
||||
Category: DiscussionCategory{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ type Discussion struct {
|
|||
Title string
|
||||
Body string
|
||||
URL string
|
||||
State string
|
||||
Closed bool
|
||||
StateReason string
|
||||
Author DiscussionAuthor
|
||||
Category DiscussionCategory
|
||||
|
|
@ -43,8 +43,8 @@ func (d Discussion) ExportData(fields []string) map[string]interface{} {
|
|||
data[f] = d.Body
|
||||
case "url":
|
||||
data[f] = d.URL
|
||||
case "state":
|
||||
data[f] = d.State
|
||||
case "closed":
|
||||
data[f] = d.Closed
|
||||
case "stateReason":
|
||||
data[f] = d.StateReason
|
||||
case "author":
|
||||
|
|
|
|||
|
|
@ -20,13 +20,16 @@ import (
|
|||
|
||||
const defaultLimit = 30
|
||||
|
||||
// discussionListFields lists the field names available for --json output
|
||||
// on the discussion list command. This excludes fields like "comments"
|
||||
// that are only populated by the view command.
|
||||
var discussionListFields = []string{
|
||||
"id",
|
||||
"number",
|
||||
"title",
|
||||
"body",
|
||||
"url",
|
||||
"state",
|
||||
"closed",
|
||||
"stateReason",
|
||||
"author",
|
||||
"category",
|
||||
|
|
@ -306,13 +309,17 @@ func printDiscussions(opts *ListOptions, discussions []client.Discussion, totalC
|
|||
for _, d := range discussions {
|
||||
if isTerminal {
|
||||
idColor := cs.Green
|
||||
if strings.EqualFold(d.State, "CLOSED") {
|
||||
if d.Closed {
|
||||
idColor = cs.Gray
|
||||
}
|
||||
tp.AddField(fmt.Sprintf("#%d", d.Number), tableprinter.WithColor(idColor))
|
||||
} else {
|
||||
tp.AddField(fmt.Sprintf("%d", d.Number))
|
||||
tp.AddField(d.State)
|
||||
if d.Closed {
|
||||
tp.AddField("CLOSED")
|
||||
} else {
|
||||
tp.AddField("OPEN")
|
||||
}
|
||||
}
|
||||
|
||||
tp.AddField(text.RemoveExcessiveWhitespace(d.Title))
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ func sampleDiscussions() []client.Discussion {
|
|||
Number: 42,
|
||||
Title: "Bug report discussion",
|
||||
URL: "https://github.com/OWNER/REPO/discussions/42",
|
||||
State: "OPEN",
|
||||
Author: client.DiscussionAuthor{Login: "monalisa"},
|
||||
Category: client.DiscussionCategory{
|
||||
ID: "CAT1",
|
||||
|
|
@ -41,7 +40,6 @@ func sampleDiscussions() []client.Discussion {
|
|||
Number: 41,
|
||||
Title: "Feature request",
|
||||
URL: "https://github.com/OWNER/REPO/discussions/41",
|
||||
State: "OPEN",
|
||||
Author: client.DiscussionAuthor{Login: "octocat"},
|
||||
Category: client.DiscussionCategory{
|
||||
ID: "CAT2",
|
||||
|
|
@ -576,7 +574,7 @@ func TestListRun_closedState(t *testing.T) {
|
|||
{
|
||||
Number: 10,
|
||||
Title: "Old discussion",
|
||||
State: "CLOSED",
|
||||
Closed: true,
|
||||
Category: client.DiscussionCategory{Name: "General"},
|
||||
Labels: []client.DiscussionLabel{},
|
||||
UpdatedAt: time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ var DiscussionFields = []string{
|
|||
"title",
|
||||
"body",
|
||||
"url",
|
||||
"state",
|
||||
"closed",
|
||||
"stateReason",
|
||||
"author",
|
||||
"category",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue