mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
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:
9 files changed
+150
-10
No files matched your search
@@ -18,12 +18,14 @@ type Comment struct {
|
||||
Author string `json:"author"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
// Pull reports a comment on a pull request rather than an issue.
|
||||
Pull bool `json:"-"`
|
||||
}
|
||||
|
||||
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),
|
||||
CreatedAt: timestamp(comment.Created), UpdatedAt: timestamp(comment.Updated), Pull: comment.PRURL != "",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ type Issue struct {
|
||||
Ref string `json:"ref"`
|
||||
ID int64 `json:"id"`
|
||||
Number int64 `json:"number"`
|
||||
Kind string `json:"kind"`
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
URL string `json:"url"`
|
||||
@@ -32,6 +33,22 @@ type Issue struct {
|
||||
Comments int64 `json:"comments"`
|
||||
}
|
||||
|
||||
// Kinds of Issue: Gitea lists pull requests among issues.
|
||||
const (
|
||||
KindIssue = "issue"
|
||||
KindPull = "pull"
|
||||
)
|
||||
|
||||
// discussionFrom converts an issue or a pull request listed among issues.
|
||||
func discussionFrom(issue *gitea.Issue) Issue {
|
||||
item := issueFrom(issue)
|
||||
item.Kind = KindIssue
|
||||
if issue.PullRequest != nil {
|
||||
item.Kind = KindPull
|
||||
}
|
||||
return item
|
||||
}
|
||||
|
||||
// IssueMilestone identifies the milestone associated with an issue or pull request.
|
||||
type IssueMilestone struct {
|
||||
ID int64 `json:"id"`
|
||||
@@ -99,7 +116,7 @@ func (s Issues) List(ctx context.Context, opts ListOptions) ([]Issue, bool, erro
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
return convertAll(issues, issueFrom), more, nil
|
||||
return convertAll(issues, discussionFrom), more, nil
|
||||
}
|
||||
|
||||
// filterValues splits a comma-separated filter, which the SDK joins again.
|
||||
@@ -112,14 +129,14 @@ func filterValues(value string) []string {
|
||||
|
||||
// View retrieves one issue.
|
||||
func (s Issues) View(ctx context.Context, number int64) (Issue, error) {
|
||||
return repoConvert(ctx, s.Client, s.Repository, issueFrom, func(ctx context.Context, c *gitea.Client, owner, repo string) (*gitea.Issue, *gitea.Response, error) {
|
||||
return repoConvert(ctx, s.Client, s.Repository, discussionFrom, func(ctx context.Context, c *gitea.Client, owner, repo string) (*gitea.Issue, *gitea.Response, error) {
|
||||
return c.Issues.GetIssue(ctx, owner, repo, number)
|
||||
})
|
||||
}
|
||||
|
||||
// Create opens an issue.
|
||||
func (s Issues) Create(ctx context.Context, options IssueOptions) (Issue, error) {
|
||||
return repoConvert(ctx, s.Client, s.Repository, issueFrom, func(ctx context.Context, c *gitea.Client, owner, repo string) (*gitea.Issue, *gitea.Response, error) {
|
||||
return repoConvert(ctx, s.Client, s.Repository, discussionFrom, func(ctx context.Context, c *gitea.Client, owner, repo string) (*gitea.Issue, *gitea.Response, error) {
|
||||
return c.Issues.CreateIssue(ctx, owner, repo, gitea.CreateIssueOption{
|
||||
Title: options.Title, Body: options.Body, Ref: options.Ref, Assignees: options.Assignees,
|
||||
Deadline: options.Deadline, Milestone: options.Milestone, Labels: options.Labels,
|
||||
@@ -134,7 +151,7 @@ func (s Issues) SetState(ctx context.Context, number int64, state string) (Issue
|
||||
}
|
||||
|
||||
func (s Issues) edit(ctx context.Context, number int64, opts gitea.EditIssueOption) (Issue, error) {
|
||||
return repoConvert(ctx, s.Client, s.Repository, issueFrom, func(ctx context.Context, c *gitea.Client, owner, repo string) (*gitea.Issue, *gitea.Response, error) {
|
||||
return repoConvert(ctx, s.Client, s.Repository, discussionFrom, func(ctx context.Context, c *gitea.Client, owner, repo string) (*gitea.Issue, *gitea.Response, error) {
|
||||
return c.Issues.EditIssue(ctx, owner, repo, number, opts)
|
||||
})
|
||||
}
|
||||
@@ -27,7 +27,7 @@ func TestIssueListSendsTypePageSizeAndFilters(t *testing.T) {
|
||||
items, more, err := service.List(context.Background(), ListOptions{State: "open", Limit: 1, Page: 3})
|
||||
require.NoError(t, err)
|
||||
require.False(t, more)
|
||||
require.Equal(t, []Issue{{Author: "bob", ID: 1, Number: 2, Title: "Bug", Labels: []Label{}, Assignees: []string{}}}, items)
|
||||
require.Equal(t, []Issue{{Author: "bob", ID: 1, Number: 2, Kind: KindIssue, Title: "Bug", Labels: []Label{}, Assignees: []string{}}}, items)
|
||||
since := time.Date(2026, 10, 1, 8, 0, 0, 0, time.UTC)
|
||||
_, _, err = service.List(context.Background(), ListOptions{
|
||||
Kind: "all", Limit: 30, Page: 1, Search: "crash", Assignee: "carol", Labels: "bug,ui", Milestones: "v1",
|
||||
|
||||
Reference in new issue
Block a user