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

+26 -1
View File
@@ -16,7 +16,7 @@ import (
"github.com/spf13/cobra"
)
func (a *application) issueAttachmentCommand() *cobra.Command {
func (a *application) issueAttachmentCommand(kind refKind) *cobra.Command {
group := &cobra.Command{Use: "attachment", Short: "Inspect issue or pull request attachments"}
var limit, page int
list := &cobra.Command{Use: "list <number>", Short: "List attachments", Args: argsExact(1), RunE: func(cmd *cobra.Command, args []string) error {
@@ -28,6 +28,11 @@ func (a *application) issueAttachmentCommand() *cobra.Command {
if err != nil {
return err
}
if kind == pullRef {
if err := requirePull(cmd, target, n); err != nil {
return err
}
}
items, err := (services.Issues{Client: target.client, Repository: target.Repo}).Attachments(cmd.Context(), n, limit, page)
if err != nil {
return err
@@ -48,6 +53,11 @@ func (a *application) issueAttachmentCommand() *cobra.Command {
if err != nil {
return err
}
if kind == pullRef {
if err := requirePull(cmd, target, n); err != nil {
return err
}
}
item, err := (services.Issues{Client: target.client, Repository: target.Repo}).Attachment(cmd.Context(), n, id)
if err != nil {
return err
@@ -72,6 +82,11 @@ func (a *application) issueAttachmentCommand() *cobra.Command {
if err != nil {
return err
}
if kind == pullRef {
if err := requirePull(cmd, target, n); err != nil {
return err
}
}
service := services.Issues{Client: target.client, Repository: target.Repo}
if verb == "delete" {
if err := a.confirm(cmd, fmt.Sprintf("Delete attachment %d on %s#%d", id, target.Repo, n)); err != nil {
@@ -115,6 +130,11 @@ func (a *application) issueAttachmentCommand() *cobra.Command {
if err != nil {
return err
}
if kind == pullRef {
if err := requirePull(cmd, target, n); err != nil {
return err
}
}
item, err := (services.Issues{Client: target.client, Repository: target.Repo}).UploadAttachment(cmd.Context(), n, name, files[0])
if err != nil {
return err
@@ -139,6 +159,11 @@ func (a *application) issueAttachmentCommand() *cobra.Command {
if err != nil {
return err
}
if kind == pullRef {
if err := requirePull(cmd, target, n); err != nil {
return err
}
}
body, err := (services.Issues{Client: target.client, Repository: target.Repo}).DownloadAttachment(cmd.Context(), n, id)
if err != nil {
return err