aboutsummaryrefslogtreecommitdiffstats
path: root/services/convert/issue.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2023-07-10 17:31:19 +0800
committerGitHub <noreply@github.com>2023-07-10 09:31:19 +0000
commit0fd1672ae49a5f69fca7d90336ae75be83a21014 (patch)
tree21b651c5ae3bf4db7434ef44de1ac9b4c7865703 /services/convert/issue.go
parent5489962aac6faf3260176a0f53cbb78c44c421a5 (diff)
downloadgitea-0fd1672ae49a5f69fca7d90336ae75be83a21014.tar.gz
gitea-0fd1672ae49a5f69fca7d90336ae75be83a21014.zip
For API attachments, use API URL (#25639)
Fix #25257 --------- Co-authored-by: Giteabot <teabot@gitea.io>
Diffstat (limited to 'services/convert/issue.go')
-rw-r--r--services/convert/issue.go19
1 files changed, 18 insertions, 1 deletions
diff --git a/services/convert/issue.go b/services/convert/issue.go
index bcb1618e8f..d81840f025 100644
--- a/services/convert/issue.go
+++ b/services/convert/issue.go
@@ -19,11 +19,19 @@ import (
api "code.gitea.io/gitea/modules/structs"
)
+func ToIssue(ctx context.Context, issue *issues_model.Issue) *api.Issue {
+ return toIssue(ctx, issue, WebAssetDownloadURL)
+}
+
// ToAPIIssue converts an Issue to API format
// it assumes some fields assigned with values:
// Required - Poster, Labels,
// Optional - Milestone, Assignee, PullRequest
func ToAPIIssue(ctx context.Context, issue *issues_model.Issue) *api.Issue {
+ return toIssue(ctx, issue, APIAssetDownloadURL)
+}
+
+func toIssue(ctx context.Context, issue *issues_model.Issue, getDownloadURL func(repo *repo_model.Repository, attach *repo_model.Attachment) string) *api.Issue {
if err := issue.LoadLabels(ctx); err != nil {
return &api.Issue{}
}
@@ -40,7 +48,7 @@ func ToAPIIssue(ctx context.Context, issue *issues_model.Issue) *api.Issue {
Poster: ToUser(ctx, issue.Poster, nil),
Title: issue.Title,
Body: issue.Content,
- Attachments: ToAttachments(issue.Attachments),
+ Attachments: toAttachments(issue.Repo, issue.Attachments, getDownloadURL),
Ref: issue.Ref,
State: issue.State(),
IsLocked: issue.IsLocked,
@@ -105,6 +113,15 @@ func ToAPIIssue(ctx context.Context, issue *issues_model.Issue) *api.Issue {
return apiIssue
}
+// ToIssueList converts an IssueList to API format
+func ToIssueList(ctx context.Context, il issues_model.IssueList) []*api.Issue {
+ result := make([]*api.Issue, len(il))
+ for i := range il {
+ result[i] = ToIssue(ctx, il[i])
+ }
+ return result
+}
+
// ToAPIIssueList converts an IssueList to API format
func ToAPIIssueList(ctx context.Context, il issues_model.IssueList) []*api.Issue {
result := make([]*api.Issue, len(il))