Merge branch 'main' into lunny/add_reply_code_review

This commit is contained in:
Lunny Xiao
2026-05-31 22:21:02 +00:00
13 changed files with 695 additions and 92 deletions
+50
View File
@@ -29,6 +29,56 @@ func Comments(comments []*gitea.Comment) {
), baseURL)
}
// CommentsList prints comments in tabular form, including IDs so they can be
// passed to 'tea comments edit' / 'tea comments delete'.
func CommentsList(comments []*gitea.Comment, output string) error {
if len(comments) == 0 {
fmt.Println("No comments found")
return nil
}
t := tableWithHeader(
"ID",
"Author",
"Created",
"Updated",
"Body",
)
for _, c := range comments {
updated := ""
if c.Updated.After(c.Created) {
updated = FormatTime(c.Updated, false)
}
t.addRow(
fmt.Sprintf("%d", c.ID),
"@"+c.Poster.UserName,
FormatTime(c.Created, false),
updated,
summarizeBody(c.Body),
)
}
return t.print(output)
}
func summarizeBody(body string) string {
const max = 80
var b strings.Builder
for _, r := range body {
if r == '\n' || r == '\r' {
b.WriteByte(' ')
} else {
b.WriteRune(r)
}
}
s := b.String()
if len(s) > max {
return s[:max-1] + "…"
}
return s
}
// Comment renders a comment to stdout
func Comment(c *gitea.Comment) {
_ = outputMarkdown(formatComment(c), getRepoURL(c.HTMLURL))
+31
View File
@@ -0,0 +1,31 @@
// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package utils
import "regexp"
// draftPrefixRe matches the prefixes Gitea recognizes as marking a pull
// request as a draft: a leading "WIP:" or "[WIP]" (case-insensitive),
// followed by any whitespace.
var draftPrefixRe = regexp.MustCompile(`(?i)^(wip:\s*|\[wip\]\s*)`)
// HasDraftPrefix reports whether title already starts with a draft marker.
func HasDraftPrefix(title string) bool {
return draftPrefixRe.MatchString(title)
}
// AddDraftPrefix returns title with a "WIP: " prefix, or title unchanged
// if it already carries a recognized draft prefix.
func AddDraftPrefix(title string) string {
if HasDraftPrefix(title) {
return title
}
return "WIP: " + title
}
// StripDraftPrefix returns title with any recognized leading draft prefix
// removed, or title unchanged if no prefix is present.
func StripDraftPrefix(title string) string {
return draftPrefixRe.ReplaceAllString(title, "")
}
+34
View File
@@ -0,0 +1,34 @@
// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package utils
import "testing"
func TestDraftPrefix(t *testing.T) {
cases := []struct {
in string
has bool
stripped string
withDraft string
}{
{"plain title", false, "plain title", "WIP: plain title"},
{"WIP: already", true, "already", "WIP: already"},
{"wip: lowercase", true, "lowercase", "wip: lowercase"},
{"[WIP] bracketed", true, "bracketed", "[WIP] bracketed"},
{"[wip] extra space", true, "extra space", "[wip] extra space"},
{"Draft: not recognized", false, "Draft: not recognized", "WIP: Draft: not recognized"},
{"", false, "", "WIP: "},
}
for _, c := range cases {
if got := HasDraftPrefix(c.in); got != c.has {
t.Errorf("HasDraftPrefix(%q) = %v, want %v", c.in, got, c.has)
}
if got := StripDraftPrefix(c.in); got != c.stripped {
t.Errorf("StripDraftPrefix(%q) = %q, want %q", c.in, got, c.stripped)
}
if got := AddDraftPrefix(c.in); got != c.withDraft {
t.Errorf("AddDraftPrefix(%q) = %q, want %q", c.in, got, c.withDraft)
}
}
}