2020-09-30 05:11:33 +00:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2023-09-08 01:40:02 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-09-30 05:11:33 +00:00
|
|
|
|
|
|
|
package print
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"code.gitea.io/sdk/gitea"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MilestoneDetails print an milestone formatted to stdout
|
|
|
|
func MilestoneDetails(milestone *gitea.Milestone) {
|
|
|
|
fmt.Printf("%s\n",
|
|
|
|
milestone.Title,
|
|
|
|
)
|
|
|
|
if len(milestone.Description) != 0 {
|
|
|
|
fmt.Printf("\n%s\n", milestone.Description)
|
|
|
|
}
|
|
|
|
if milestone.Deadline != nil && !milestone.Deadline.IsZero() {
|
2022-03-28 22:37:13 +00:00
|
|
|
fmt.Printf("\nDeadline: %s\n", FormatTime(*milestone.Deadline, false))
|
2020-09-30 05:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-08 10:28:54 +00:00
|
|
|
|
|
|
|
// MilestonesList prints a listing of milestones
|
2022-09-13 19:08:18 +00:00
|
|
|
func MilestonesList(news []*gitea.Milestone, output string, fields []string) {
|
|
|
|
var printables = make([]printable, len(news))
|
|
|
|
for i, x := range news {
|
|
|
|
printables[i] = &printableMilestone{x}
|
2020-12-08 10:28:54 +00:00
|
|
|
}
|
2022-09-13 19:08:18 +00:00
|
|
|
t := tableFromItems(fields, printables, isMachineReadable(output))
|
|
|
|
t.sort(0, true)
|
|
|
|
t.print(output)
|
|
|
|
}
|
2020-12-08 10:28:54 +00:00
|
|
|
|
2022-09-13 19:08:18 +00:00
|
|
|
// MilestoneFields are all available fields to print with MilestonesList
|
|
|
|
var MilestoneFields = []string{
|
|
|
|
"title",
|
|
|
|
"state",
|
|
|
|
"items_open",
|
|
|
|
"items_closed",
|
|
|
|
"items",
|
|
|
|
"duedate",
|
|
|
|
"description",
|
|
|
|
"created",
|
|
|
|
"updated",
|
|
|
|
"closed",
|
|
|
|
"id",
|
|
|
|
}
|
2020-12-08 10:28:54 +00:00
|
|
|
|
2022-09-13 19:08:18 +00:00
|
|
|
type printableMilestone struct {
|
|
|
|
*gitea.Milestone
|
|
|
|
}
|
2020-12-08 10:28:54 +00:00
|
|
|
|
2022-09-13 19:08:18 +00:00
|
|
|
func (m printableMilestone) FormatField(field string, machineReadable bool) string {
|
|
|
|
switch field {
|
|
|
|
case "title":
|
|
|
|
return m.Title
|
|
|
|
case "state":
|
|
|
|
return string(m.State)
|
|
|
|
case "items_open":
|
|
|
|
return fmt.Sprintf("%d", m.OpenIssues)
|
|
|
|
case "items_closed":
|
|
|
|
return fmt.Sprintf("%d", m.ClosedIssues)
|
|
|
|
case "items":
|
|
|
|
return fmt.Sprintf("%d/%d", m.OpenIssues, m.ClosedIssues)
|
|
|
|
case "duedate":
|
2020-12-08 10:28:54 +00:00
|
|
|
if m.Deadline != nil && !m.Deadline.IsZero() {
|
2022-09-13 19:08:18 +00:00
|
|
|
return FormatTime(*m.Deadline, machineReadable)
|
2020-12-08 10:28:54 +00:00
|
|
|
}
|
2022-09-13 19:08:18 +00:00
|
|
|
case "id":
|
|
|
|
return fmt.Sprintf("%d", m.ID)
|
|
|
|
case "description":
|
|
|
|
return m.Description
|
|
|
|
case "created":
|
|
|
|
return FormatTime(m.Created, machineReadable)
|
|
|
|
case "updated":
|
|
|
|
if m.Updated != nil {
|
|
|
|
return FormatTime(*m.Updated, machineReadable)
|
2020-12-08 10:28:54 +00:00
|
|
|
}
|
2022-09-13 19:08:18 +00:00
|
|
|
case "closed":
|
|
|
|
if m.Closed != nil {
|
|
|
|
return FormatTime(*m.Closed, machineReadable)
|
2020-12-08 10:28:54 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-13 19:08:18 +00:00
|
|
|
return ""
|
2020-12-08 10:28:54 +00:00
|
|
|
}
|