feat: add functions to convert a release

This commit is contained in:
Derrick Hammer 2024-02-12 16:39:51 -05:00
parent bf9e062644
commit e33587b406
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 45 additions and 0 deletions

View File

@ -435,3 +435,48 @@ func translatePrAction(action structs.HookIssueAction, prefix bool) string {
return translatedAction
}
func convertRelease(release *gitea.Release) *github.RepositoryRelease {
if release == nil {
return &github.RepositoryRelease{}
}
return &github.RepositoryRelease{
ID: int64Ptr(release.ID),
TagName: stringPtr(release.TagName),
TargetCommitish: stringPtr(release.Target),
Name: stringPtr(release.Title),
Body: stringPtr(release.Note),
Draft: boolPtr(release.IsDraft),
Prerelease: boolPtr(release.IsPrerelease),
CreatedAt: timePtr(release.CreatedAt),
PublishedAt: timePtr(release.PublishedAt),
Assets: convertReleaseAttachments(release.Attachments),
URL: stringPtr(release.URL),
ZipballURL: stringPtr(release.ZipURL),
TarballURL: stringPtr(release.TarURL),
HTMLURL: stringPtr(release.HTMLURL),
}
}
func convertReleaseAttachments(attachments []*gitea.Attachment) []*github.ReleaseAsset {
if attachments == nil {
return make([]*github.ReleaseAsset, 0)
}
var ghAttachments []*github.ReleaseAsset
for _, attachment := range attachments {
ghAttachments = append(ghAttachments, convertReleaseAttachment(attachment))
}
return ghAttachments
}
func convertReleaseAttachment(attachment *gitea.Attachment) *github.ReleaseAsset {
if attachment == nil {
return &github.ReleaseAsset{}
}
return &github.ReleaseAsset{
ID: int64Ptr(attachment.ID),
Name: stringPtr(attachment.Name),
Size: intPtr(int(attachment.Size)),
DownloadCount: intPtr(int(attachment.DownloadCount)),
BrowserDownloadURL: stringPtr(attachment.DownloadURL),
}
}