mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
fix(issue): name missing issues and attachments in errors
tea issue close 999 printed "issue 999: not found (HTTP 404 GET …)" and issue attachment view 1 9 blamed issue #1 for a missing attachment. Batch commands (issue close, reopen, edit, milestone issue add and remove) now report "issue 999: not found in alice/x", and attachment commands "attachment 9 not found in alice/x#1". Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
5 files changed
+64
-15
No files matched your search
@@ -7,6 +7,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
|
||||
gitea "gitea.dev/sdk"
|
||||
)
|
||||
@@ -36,9 +37,16 @@ func (s Issues) Attachment(ctx context.Context, number, id int64) (IssueAttachme
|
||||
}
|
||||
|
||||
func (s Issues) attachment(ctx context.Context, number, id int64) (*gitea.Attachment, error) {
|
||||
return repoCall(ctx, s.Client, s.Repository, func(ctx context.Context, c *gitea.Client, owner, repo string) (*gitea.Attachment, *gitea.Response, error) {
|
||||
attachment, err := repoCall(ctx, s.Client, s.Repository, func(ctx context.Context, c *gitea.Client, owner, repo string) (*gitea.Attachment, *gitea.Response, error) {
|
||||
return c.Issues.GetIssueAttachment(ctx, owner, repo, number, id)
|
||||
})
|
||||
return attachment, s.attachmentError(err, number, id)
|
||||
}
|
||||
|
||||
// attachmentError names attachment id of issue number in a failure; Gitea answers 404 both for a
|
||||
// missing issue and a missing attachment.
|
||||
func (s Issues) attachmentError(err error, number, id int64) error {
|
||||
return Classify(err, "attachment", strconv.FormatInt(id, 10), fmt.Sprintf("%s#%d", s.Repository, number))
|
||||
}
|
||||
|
||||
// RenameAttachment changes the filename without replacing its content.
|
||||
@@ -47,16 +55,16 @@ func (s Issues) RenameAttachment(ctx context.Context, number, id int64, name str
|
||||
return c.Issues.EditIssueAttachment(ctx, owner, repo, number, id, gitea.EditAttachmentOptions{Name: name})
|
||||
})
|
||||
if err != nil {
|
||||
return IssueAttachment{}, err
|
||||
return IssueAttachment{}, s.attachmentError(err, number, id)
|
||||
}
|
||||
return IssueAttachment(assetFrom(attachment)), nil
|
||||
}
|
||||
|
||||
// DeleteAttachment removes one attachment from its owning issue.
|
||||
func (s Issues) DeleteAttachment(ctx context.Context, number, id int64) error {
|
||||
return repoDo(ctx, s.Client, s.Repository, func(ctx context.Context, c *gitea.Client, owner, repo string) (*gitea.Response, error) {
|
||||
return s.attachmentError(repoDo(ctx, s.Client, s.Repository, func(ctx context.Context, c *gitea.Client, owner, repo string) (*gitea.Response, error) {
|
||||
return c.Issues.DeleteIssueAttachment(ctx, owner, repo, number, id)
|
||||
})
|
||||
}), number, id)
|
||||
}
|
||||
|
||||
// UploadAttachment streams a file to its owning issue or pull request.
|
||||
|
||||
Reference in new issue
Block a user