1
0
mirror of https://gitea.com/jolheiser/sip synced 2024-11-26 07:33:48 +01:00
sip/sdk/releases.go

47 lines
1.1 KiB
Go
Raw Normal View History

package sdk
import (
"code.gitea.io/sdk/gitea"
)
// GetReleases returns all matching Releases from a Gitea instance
func GetReleases(client *gitea.Client, owner, repo string, opts gitea.ListReleasesOptions) ([]*gitea.Release, error) {
releases := make([]*gitea.Release, 0)
p := 1
for {
opts.Page = p
list, _, err := client.ListReleases(owner, repo, opts)
if err != nil {
return releases, err
}
p++
releases = append(releases, list...)
if len(list) == 0 {
break
}
}
return releases, nil
}
// GetReleaseAttachments returns all attachments from a release
func GetReleaseAttachments(client *gitea.Client, owner, repo string, releaseID int64, opts gitea.ListReleaseAttachmentsOptions) ([]*gitea.Attachment, error) {
attachments := make([]*gitea.Attachment, 0)
p := 1
for {
opts.Page = p
list, _, err := client.ListReleaseAttachments(owner, repo, releaseID, opts)
if err != nil {
return attachments, err
}
p++
attachments = append(attachments, list...)
// FIXME Seems paging doesn't want to work with release attachments
if len(list) == 0 || len(list) < 50 {
break
}
}
return attachments, nil
}