feat(comment): comment on issues and pull requests the gh way

tea issue comment 12 --body "LGTM" failed with "unknown flag: --body"; the
comment had to be created with issue comment create. issue comment and
pr comment now take the issue or pull request and -b/-F/-e directly,
plus --edit-last and --delete-last for your last comment. The
subcommands stay, create is also add, and a misspelled subcommand
suggests the right one.

Comments are written in the configured editor or a multi-line
"Comment (markdown):" field, which edits start from the current text,
without a confirmation afterwards. The new comment's URL goes to stdout
with a ✓ line; deletes ask "Delete comment 81 on alice/x#1?". comment
list shows each comment under a "#79 alice • about 2 hours ago"
heading on a terminal and as key/value blocks when piped, and comment
JSON gains issue_number.

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-12 00:16:09 +02:00
1 parent 0b6232087e
commit 10417049a1
7 files changed
+514 -143

No files matched your search

+14
View File
@@ -5,6 +5,8 @@ package services
import (
"context"
"path"
"strconv"
gitea "gitea.dev/sdk"
"gitea.dev/tea/internal/transport"
@@ -18,6 +20,8 @@ type Comment struct {
Author string `json:"author"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
// IssueNumber is the issue or pull request the comment is on.
IssueNumber int64 `json:"issue_number"`
// Pull reports a comment on a pull request rather than an issue.
Pull bool `json:"-"`
}
@@ -26,9 +30,19 @@ func commentFrom(comment *gitea.Comment) Comment {
return Comment{
ID: comment.ID, Body: comment.Body, URL: comment.HTMLURL, Author: login(comment.Poster),
CreatedAt: timestamp(comment.Created), UpdatedAt: timestamp(comment.Updated), Pull: comment.PRURL != "",
IssueNumber: discussionNumber(comment.IssueURL + comment.PRURL),
}
}
// discussionNumber reads the number from the web URL of an issue or pull request, or returns 0.
func discussionNumber(url string) int64 {
n, err := strconv.ParseInt(path.Base(url), 10, 64)
if err != nil {
return 0
}
return n
}
// Comments implements discussion comments under their owning repository resource.
type Comments struct {
Client *transport.Client