2020-10-17 04:23:08 +00:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package convert
|
|
|
|
|
|
|
|
import (
|
2021-11-19 13:39:57 +00:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2020-10-17 04:23:08 +00:00
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
|
|
|
)
|
|
|
|
|
2022-08-25 02:31:57 +00:00
|
|
|
// ToRelease convert a repo_model.Release to api.Release
|
|
|
|
func ToRelease(r *repo_model.Release) *api.Release {
|
2020-10-17 04:23:08 +00:00
|
|
|
assets := make([]*api.Attachment, 0)
|
|
|
|
for _, att := range r.Attachments {
|
|
|
|
assets = append(assets, ToReleaseAttachment(att))
|
|
|
|
}
|
|
|
|
return &api.Release{
|
|
|
|
ID: r.ID,
|
|
|
|
TagName: r.TagName,
|
|
|
|
Target: r.Target,
|
|
|
|
Title: r.Title,
|
|
|
|
Note: r.Note,
|
|
|
|
URL: r.APIURL(),
|
|
|
|
HTMLURL: r.HTMLURL(),
|
|
|
|
TarURL: r.TarURL(),
|
|
|
|
ZipURL: r.ZipURL(),
|
|
|
|
IsDraft: r.IsDraft,
|
|
|
|
IsPrerelease: r.IsPrerelease,
|
|
|
|
CreatedAt: r.CreatedUnix.AsTime(),
|
|
|
|
PublishedAt: r.CreatedUnix.AsTime(),
|
2021-03-27 16:45:26 +00:00
|
|
|
Publisher: ToUser(r.Publisher, nil),
|
2020-10-17 04:23:08 +00:00
|
|
|
Attachments: assets,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToReleaseAttachment converts models.Attachment to api.Attachment
|
2021-11-19 13:39:57 +00:00
|
|
|
func ToReleaseAttachment(a *repo_model.Attachment) *api.Attachment {
|
2020-10-17 04:23:08 +00:00
|
|
|
return &api.Attachment{
|
|
|
|
ID: a.ID,
|
|
|
|
Name: a.Name,
|
|
|
|
Created: a.CreatedUnix.AsTime(),
|
|
|
|
DownloadCount: a.DownloadCount,
|
|
|
|
Size: a.Size,
|
|
|
|
UUID: a.UUID,
|
|
|
|
DownloadURL: a.DownloadURL(),
|
|
|
|
}
|
|
|
|
}
|