mirror of
https://gitea.com/gitea/tea.git
synced 2025-09-02 18:08:30 +02:00
Add --fields
to notification & milestone listings (#422)
Together with #415 this finally adds the field flag to all entity listings. closes #342 ### ⚠️ breaking changes ⚠️ This changes the column names of `tea milestones ls`: ```diff - TITLE | OPEN/CLOSED ISSUES | DUEDATE + TITLE | ITEMS | DUEDATE ``` Co-authored-by: Norwin <git@nroo.de> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/422 Reviewed-by: delvh <dev.lh@web.de> Reviewed-by: 6543 <6543@obermui.de> Co-authored-by: Norwin <noerw@noreply.gitea.io> Co-committed-by: Norwin <noerw@noreply.gitea.io>
This commit is contained in:
@ -12,26 +12,51 @@ import (
|
||||
)
|
||||
|
||||
// NotificationsList prints a listing of notification threads
|
||||
func NotificationsList(news []*gitea.NotificationThread, output string, showRepository bool) {
|
||||
headers := []string{
|
||||
"ID",
|
||||
"Status",
|
||||
"Type",
|
||||
"State",
|
||||
"Index",
|
||||
"Title",
|
||||
}
|
||||
if showRepository {
|
||||
headers = append(headers, "Repository")
|
||||
func NotificationsList(news []*gitea.NotificationThread, output string, fields []string) {
|
||||
var printables = make([]printable, len(news))
|
||||
for i, x := range news {
|
||||
printables[i] = &printableNotification{x}
|
||||
}
|
||||
t := tableFromItems(fields, printables, isMachineReadable(output))
|
||||
t.print(output)
|
||||
}
|
||||
|
||||
t := table{headers: headers}
|
||||
// NotificationFields are all available fields to print with NotificationsList
|
||||
var NotificationFields = []string{
|
||||
"id",
|
||||
"status",
|
||||
"updated",
|
||||
|
||||
for _, n := range news {
|
||||
if n.Subject == nil {
|
||||
continue
|
||||
// these are about the notification subject
|
||||
"index",
|
||||
"type",
|
||||
"state",
|
||||
"title",
|
||||
"repository",
|
||||
}
|
||||
|
||||
type printableNotification struct {
|
||||
*gitea.NotificationThread
|
||||
}
|
||||
|
||||
func (n printableNotification) FormatField(field string, machineReadable bool) string {
|
||||
switch field {
|
||||
case "id":
|
||||
return fmt.Sprintf("%d", n.ID)
|
||||
|
||||
case "status":
|
||||
status := "read"
|
||||
if n.Pinned {
|
||||
status = "pinned"
|
||||
} else if n.Unread {
|
||||
status = "unread"
|
||||
}
|
||||
// if pull or Issue get Index
|
||||
return status
|
||||
|
||||
case "updated":
|
||||
return FormatTime(n.UpdatedAt, machineReadable)
|
||||
|
||||
case "index":
|
||||
var index string
|
||||
if n.Subject.Type == "Issue" || n.Subject.Type == "Pull" {
|
||||
index = n.Subject.URL
|
||||
@ -39,31 +64,20 @@ func NotificationsList(news []*gitea.NotificationThread, output string, showRepo
|
||||
if len(urlParts) != 0 {
|
||||
index = urlParts[len(urlParts)-1]
|
||||
}
|
||||
index = "#" + index
|
||||
}
|
||||
return index
|
||||
|
||||
status := "read"
|
||||
if n.Pinned {
|
||||
status = "pinned"
|
||||
} else if n.Unread {
|
||||
status = "unread"
|
||||
}
|
||||
case "type":
|
||||
return string(n.Subject.Type)
|
||||
|
||||
item := []string{
|
||||
fmt.Sprint(n.ID),
|
||||
status,
|
||||
string(n.Subject.Type),
|
||||
string(n.Subject.State),
|
||||
index,
|
||||
n.Subject.Title,
|
||||
}
|
||||
if showRepository {
|
||||
item = append(item, n.Repository.FullName)
|
||||
}
|
||||
t.addRowSlice(item)
|
||||
}
|
||||
|
||||
if t.Len() != 0 {
|
||||
t.print(output)
|
||||
case "state":
|
||||
return string(n.Subject.State)
|
||||
|
||||
case "title":
|
||||
return n.Subject.Title
|
||||
|
||||
case "repo", "repository":
|
||||
return n.Repository.FullName
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
Reference in New Issue
Block a user