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

+53
View File
@@ -32,3 +32,56 @@ func TestCommentConfirmationNamesTheTarget(t *testing.T) {
require.NoError(t, Execute(context.Background(), deps, []string{"issue", "comment", "delete", "12", "-R", "alice/project"}))
require.Equal(t, []string{"Comment on alice/project#3", "Delete comment 12 on alice/project"}, prompt.confirmations)
}
func TestPullCommentsAndAttachmentsRequirePullRequests(t *testing.T) {
var changed []string
server := newAuthenticatedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.Method + " " + r.URL.Path {
case "GET /api/v1/repos/alice/project/issues/1":
_, _ = w.Write([]byte(`{"number":1,"title":"An issue"}`))
case "GET /api/v1/repos/alice/project/issues/13":
_, _ = w.Write([]byte(`{"number":13,"title":"A pull request","pull_request":{"merged":false}}`))
case "GET /api/v1/repos/alice/project/issues/comments/5":
_, _ = w.Write([]byte(`{"id":5,"body":"on an issue","issue_url":"http://x/alice/project/issues/1"}`))
case "GET /api/v1/repos/alice/project/issues/comments/6":
_, _ = w.Write([]byte(`{"id":6,"body":"on a pull request","pull_request_url":"http://x/alice/project/pulls/13"}`))
case "GET /api/v1/repos/alice/project/issues/13/comments", "GET /api/v1/repos/alice/project/issues/13/assets":
_, _ = w.Write([]byte(`[]`))
default:
changed = append(changed, r.Method+" "+r.URL.Path)
_, _ = w.Write([]byte(`{"id":7,"body":"x"}`))
}
}))
defer server.Close()
deps, out, _ := serverDeps(t, server.URL)
for _, test := range []struct {
args []string
want string
}{
{[]string{"pr", "comment", "create", "1", "--body", "x"}, "#1 in alice/project is an issue, not a pull request; use tea issue comment create 1"},
{[]string{"pr", "comment", "list", "1"}, "#1 in alice/project is an issue"},
{[]string{"pr", "comment", "edit", "5", "--body", "x"}, "comment 5 in alice/project is on an issue, not a pull request; use tea issue comment edit 5"},
{[]string{"pr", "comment", "delete", "5", "--yes"}, "comment 5 in alice/project is on an issue"},
{[]string{"pr", "attachment", "list", "1"}, "#1 in alice/project is an issue, not a pull request; use tea issue attachment list 1"},
{[]string{"pr", "attachment", "delete", "1", "2", "--yes"}, "#1 in alice/project is an issue"},
} {
err := Execute(context.Background(), deps, append(test.args, "-R", "alice/project"))
require.ErrorContains(t, err, test.want)
}
require.Empty(t, changed)
require.Empty(t, out.String())
for _, args := range [][]string{
{"pr", "comment", "create", "13", "--body", "x"},
{"pr", "comment", "edit", "6", "--body", "x"},
{"pr", "comment", "list", "13"},
{"pr", "attachment", "list", "13"},
{"issue", "comment", "create", "1", "--body", "x"},
} {
require.NoError(t, Execute(context.Background(), deps, append(args, "-R", "alice/project", "--json")))
}
require.Equal(t, []string{
"POST /api/v1/repos/alice/project/issues/13/comments",
"PATCH /api/v1/repos/alice/project/issues/comments/6",
"POST /api/v1/repos/alice/project/issues/1/comments",
}, changed)
}