fix(pr): refuse pr comment and pr attachment on issues

Gitea serves pull request comments and attachments through issue
endpoints, so tea pr comment create 1 posted on issue #1. pr comment and
pr attachment commands now check that the number is a pull request, and
comment IDs that the comment is on one, and point at the issue command
otherwise: "#1 in alice/project is an issue, not a pull request; use tea
issue comment create 1". Issues gain a kind field (issue or pull) in JSON.

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-12 00:14:30 +02:00
1 parent 883264512c
commit c1d51c386d
9 files changed
+150 -10

No files matched your search

+38 -1
View File
@@ -19,7 +19,25 @@ func commentRecord(item services.Comment) terminal.Record {
return terminal.Record{Heading: terminal.Row(strconv.FormatInt(item.ID, 10), item.Author), Lines: []string{item.Body, item.URL}}
}
func (a *application) commentCommand() *cobra.Command {
// requirePull fails unless issue n is a pull request, for pr commands that Gitea serves through
// issue endpoints and would otherwise apply to the issue with that number.
func requirePull(cmd *cobra.Command, t target, n int64) error {
item, err := (services.Issues{Client: t.client, Repository: t.Repo}).View(cmd.Context(), n)
if err != nil {
return err
}
if item.Kind != services.KindPull {
return fmt.Errorf("#%d in %s is an issue, not a pull request; use %s %d", n, t.Repo, issueCommandPath(cmd), n)
}
return nil
}
// issueCommandPath names the issue command that matches a pr command, such as "tea issue comment".
func issueCommandPath(cmd *cobra.Command) string {
return strings.Replace(cmd.CommandPath(), " pr ", " issue ", 1)
}
func (a *application) commentCommand(kind refKind) *cobra.Command {
group := &cobra.Command{Use: "comment", Short: "Manage discussion comments"}
var limit, page int
list := &cobra.Command{Use: "list <number>", Short: "List comments on an issue or pull request", Args: argsExact(1), RunE: func(cmd *cobra.Command, args []string) error {
@@ -31,6 +49,11 @@ func (a *application) commentCommand() *cobra.Command {
if err != nil {
return err
}
if kind == pullRef {
if err := requirePull(cmd, target, n); err != nil {
return err
}
}
items, err := (services.Comments{Client: target.client, Repository: target.Repo}).Page(cmd.Context(), n, limit, page)
if err != nil {
return err
@@ -77,6 +100,20 @@ func (a *application) commentCommand() *cobra.Command {
return err
}
service := services.Comments{Client: target.client, Repository: target.Repo}
if kind == pullRef && verb == "create" {
if err := requirePull(cmd, target, id); err != nil {
return err
}
}
if kind == pullRef && verb != "create" {
current, err := service.View(cmd.Context(), id)
if err != nil {
return err
}
if !current.Pull {
return fmt.Errorf("comment %d in %s is on an issue, not a pull request; use %s %d", id, target.Repo, issueCommandPath(cmd), id)
}
}
if verb == "create" || verb == "edit" {
if useEditor {
initial := ""