From e33587b40603691dd3648e4ac3392c77b2be21d9 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Mon, 12 Feb 2024 16:39:51 -0500 Subject: [PATCH] feat: add functions to convert a release --- api/convert.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/api/convert.go b/api/convert.go index a28166e..ee64ae4 100644 --- a/api/convert.go +++ b/api/convert.go @@ -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), + } +}