Платформа ЦРНП "Мирокод" для разработки проектов
https://git.mirocod.ru
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.4 KiB
49 lines
1.4 KiB
// 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 ( |
|
"code.gitea.io/gitea/models" |
|
repo_model "code.gitea.io/gitea/models/repo" |
|
api "code.gitea.io/gitea/modules/structs" |
|
) |
|
|
|
// ToRelease convert a models.Release to api.Release |
|
func ToRelease(r *models.Release) *api.Release { |
|
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(), |
|
Publisher: ToUser(r.Publisher, nil), |
|
Attachments: assets, |
|
} |
|
} |
|
|
|
// ToReleaseAttachment converts models.Attachment to api.Attachment |
|
func ToReleaseAttachment(a *repo_model.Attachment) *api.Attachment { |
|
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(), |
|
} |
|
}
|
|
|