2020-12-08 10:28:54 +00:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package print
|
|
|
|
|
|
|
|
import (
|
2021-09-05 17:11:17 +00:00
|
|
|
"fmt"
|
2020-12-08 10:28:54 +00:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"code.gitea.io/sdk/gitea"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NotificationsList prints a listing of notification threads
|
|
|
|
func NotificationsList(news []*gitea.NotificationThread, output string, showRepository bool) {
|
|
|
|
headers := []string{
|
2021-09-05 17:11:17 +00:00
|
|
|
"ID",
|
|
|
|
"Status",
|
2020-12-08 10:28:54 +00:00
|
|
|
"Type",
|
2021-08-16 13:23:16 +00:00
|
|
|
"State",
|
2020-12-08 10:28:54 +00:00
|
|
|
"Index",
|
|
|
|
"Title",
|
|
|
|
}
|
|
|
|
if showRepository {
|
|
|
|
headers = append(headers, "Repository")
|
|
|
|
}
|
|
|
|
|
2020-12-09 22:04:36 +00:00
|
|
|
t := table{headers: headers}
|
|
|
|
|
2020-12-08 10:28:54 +00:00
|
|
|
for _, n := range news {
|
|
|
|
if n.Subject == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
// if pull or Issue get Index
|
|
|
|
var index string
|
|
|
|
if n.Subject.Type == "Issue" || n.Subject.Type == "Pull" {
|
|
|
|
index = n.Subject.URL
|
|
|
|
urlParts := strings.Split(n.Subject.URL, "/")
|
|
|
|
if len(urlParts) != 0 {
|
|
|
|
index = urlParts[len(urlParts)-1]
|
|
|
|
}
|
|
|
|
index = "#" + index
|
|
|
|
}
|
|
|
|
|
2021-09-05 17:11:17 +00:00
|
|
|
status := "read"
|
|
|
|
if n.Pinned {
|
|
|
|
status = "pinned"
|
|
|
|
} else if n.Unread {
|
|
|
|
status = "unread"
|
|
|
|
}
|
|
|
|
|
|
|
|
item := []string{
|
|
|
|
fmt.Sprint(n.ID),
|
|
|
|
status,
|
|
|
|
string(n.Subject.Type),
|
|
|
|
string(n.Subject.State),
|
|
|
|
index,
|
|
|
|
n.Subject.Title,
|
|
|
|
}
|
2020-12-08 10:28:54 +00:00
|
|
|
if showRepository {
|
|
|
|
item = append(item, n.Repository.FullName)
|
|
|
|
}
|
2020-12-09 22:04:36 +00:00
|
|
|
t.addRowSlice(item)
|
2020-12-08 10:28:54 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 22:04:36 +00:00
|
|
|
if t.Len() != 0 {
|
|
|
|
t.print(output)
|
2020-12-08 10:28:54 +00:00
|
|
|
}
|
|
|
|
}
|