forked from Shiloh/githaven
d1353e1f7c
* update code.gitea.io/sdk/gitea v0.13.1 -> v0.13.2 * update github.com/go-swagger/go-swagger v0.25.0 -> v0.26.0 * update github.com/google/uuid v1.1.2 -> v1.2.0 * update github.com/klauspost/compress v1.11.3 -> v1.11.7 * update github.com/lib/pq 083382b7e6fc -> v1.9.0 * update github.com/markbates/goth v1.65.0 -> v1.66.1 * update github.com/mattn/go-sqlite3 v1.14.4 -> v1.14.6 * update github.com/mgechev/revive 246eac737dc7 -> v1.0.3 * update github.com/minio/minio-go/v7 v7.0.6 -> v7.0.7 * update github.com/niklasfasching/go-org v1.3.2 -> v1.4.0 * update github.com/olivere/elastic/v7 v7.0.21 -> v7.0.22 * update github.com/pquerna/otp v1.2.0 -> v1.3.0 * update github.com/xanzy/go-gitlab v0.39.0 -> v0.42.0 * update github.com/yuin/goldmark v1.2.1 -> v1.3.1
217 lines
6.2 KiB
Go
Vendored
217 lines
6.2 KiB
Go
Vendored
package gitlab
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
// ReleasesService handles communication with the releases methods
|
|
// of the GitLab API.
|
|
//
|
|
// GitLab API docs: https://docs.gitlab.com/ce/api/releases/index.html
|
|
type ReleasesService struct {
|
|
client *Client
|
|
}
|
|
|
|
// Release represents a project release.
|
|
//
|
|
// GitLab API docs:
|
|
// https://docs.gitlab.com/ce/api/releases/index.html#list-releases
|
|
type Release struct {
|
|
TagName string `json:"tag_name"`
|
|
Name string `json:"name"`
|
|
Description string `json:"description,omitempty"`
|
|
DescriptionHTML string `json:"description_html,omitempty"`
|
|
CreatedAt *time.Time `json:"created_at,omitempty"`
|
|
Author struct {
|
|
ID int `json:"id"`
|
|
Name string `json:"name"`
|
|
Username string `json:"username"`
|
|
State string `json:"state"`
|
|
AvatarURL string `json:"avatar_url"`
|
|
WebURL string `json:"web_url"`
|
|
} `json:"author"`
|
|
Commit Commit `json:"commit"`
|
|
Assets struct {
|
|
Count int `json:"count"`
|
|
Sources []struct {
|
|
Format string `json:"format"`
|
|
URL string `json:"url"`
|
|
} `json:"sources"`
|
|
Links []*ReleaseLink `json:"links"`
|
|
} `json:"assets"`
|
|
}
|
|
|
|
// ListReleasesOptions represents ListReleases() options.
|
|
//
|
|
// GitLab API docs:
|
|
// https://docs.gitlab.com/ce/api/releases/index.html#list-releases
|
|
type ListReleasesOptions ListOptions
|
|
|
|
// ListReleases gets a pagenated of releases accessible by the authenticated user.
|
|
//
|
|
// GitLab API docs:
|
|
// https://docs.gitlab.com/ce/api/releases/index.html#list-releases
|
|
func (s *ReleasesService) ListReleases(pid interface{}, opt *ListReleasesOptions, options ...RequestOptionFunc) ([]*Release, *Response, error) {
|
|
project, err := parseID(pid)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
u := fmt.Sprintf("projects/%s/releases", pathEscape(project))
|
|
|
|
req, err := s.client.NewRequest("GET", u, opt, options)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
var rs []*Release
|
|
resp, err := s.client.Do(req, &rs)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return rs, resp, err
|
|
}
|
|
|
|
// GetRelease returns a single release, identified by a tag name.
|
|
//
|
|
// GitLab API docs:
|
|
// https://docs.gitlab.com/ce/api/releases/index.html#get-a-release-by-a-tag-name
|
|
func (s *ReleasesService) GetRelease(pid interface{}, tagName string, options ...RequestOptionFunc) (*Release, *Response, error) {
|
|
project, err := parseID(pid)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
u := fmt.Sprintf("projects/%s/releases/%s", pathEscape(project), tagName)
|
|
|
|
req, err := s.client.NewRequest("GET", u, nil, options)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
r := new(Release)
|
|
resp, err := s.client.Do(req, r)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return r, resp, err
|
|
}
|
|
|
|
// ReleaseAssets represents release assets in CreateRelease() options
|
|
//
|
|
// GitLab API docs:
|
|
// https://docs.gitlab.com/ce/api/releases/index.html#create-a-release
|
|
type ReleaseAssets struct {
|
|
Links []*ReleaseAssetLink `url:"links" json:"links"`
|
|
}
|
|
|
|
// ReleaseAssetLink represents release asset link in CreateRelease() options
|
|
//
|
|
// GitLab API docs:
|
|
// https://docs.gitlab.com/ce/api/releases/index.html#create-a-release
|
|
type ReleaseAssetLink struct {
|
|
Name string `url:"name" json:"name"`
|
|
URL string `url:"url" json:"url"`
|
|
}
|
|
|
|
// CreateReleaseOptions represents CreateRelease() options.
|
|
//
|
|
// GitLab API docs:
|
|
// https://docs.gitlab.com/ce/api/releases/index.html#create-a-release
|
|
type CreateReleaseOptions struct {
|
|
Name *string `url:"name" json:"name"`
|
|
TagName *string `url:"tag_name" json:"tag_name"`
|
|
Description *string `url:"description" json:"description"`
|
|
Ref *string `url:"ref,omitempty" json:"ref,omitempty"`
|
|
Milestones []string `url:"milestones,omitempty" json:"milestones,omitempty"`
|
|
Assets *ReleaseAssets `url:"assets,omitempty" json:"assets,omitempty"`
|
|
ReleasedAt *time.Time `url:"released_at,omitempty" json:"released_at,omitempty"`
|
|
}
|
|
|
|
// CreateRelease creates a release.
|
|
//
|
|
// GitLab API docs:
|
|
// https://docs.gitlab.com/ce/api/releases/index.html#create-a-release
|
|
func (s *ReleasesService) CreateRelease(pid interface{}, opts *CreateReleaseOptions, options ...RequestOptionFunc) (*Release, *Response, error) {
|
|
project, err := parseID(pid)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
u := fmt.Sprintf("projects/%s/releases", pathEscape(project))
|
|
|
|
req, err := s.client.NewRequest("POST", u, opts, options)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
r := new(Release)
|
|
resp, err := s.client.Do(req, r)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return r, resp, err
|
|
}
|
|
|
|
// UpdateReleaseOptions represents UpdateRelease() options.
|
|
//
|
|
// GitLab API docs:
|
|
// https://docs.gitlab.com/ce/api/releases/index.html#update-a-release
|
|
type UpdateReleaseOptions struct {
|
|
Name *string `url:"name" json:"name"`
|
|
Description *string `url:"description" json:"description"`
|
|
Milestones []string `url:"milestones,omitempty" json:"milestones,omitempty"`
|
|
ReleasedAt *time.Time `url:"released_at,omitempty" json:"released_at,omitempty"`
|
|
}
|
|
|
|
// UpdateRelease updates a release.
|
|
//
|
|
// GitLab API docs:
|
|
// https://docs.gitlab.com/ce/api/releases/index.html#update-a-release
|
|
func (s *ReleasesService) UpdateRelease(pid interface{}, tagName string, opts *UpdateReleaseOptions, options ...RequestOptionFunc) (*Release, *Response, error) {
|
|
project, err := parseID(pid)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
u := fmt.Sprintf("projects/%s/releases/%s", pathEscape(project), tagName)
|
|
|
|
req, err := s.client.NewRequest("PUT", u, opts, options)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
r := new(Release)
|
|
resp, err := s.client.Do(req, &r)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return r, resp, err
|
|
}
|
|
|
|
// DeleteRelease deletes a release.
|
|
//
|
|
// GitLab API docs:
|
|
// https://docs.gitlab.com/ce/api/releases/index.html#delete-a-release
|
|
func (s *ReleasesService) DeleteRelease(pid interface{}, tagName string, options ...RequestOptionFunc) (*Release, *Response, error) {
|
|
project, err := parseID(pid)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
u := fmt.Sprintf("projects/%s/releases/%s", pathEscape(project), tagName)
|
|
|
|
req, err := s.client.NewRequest("DELETE", u, nil, options)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
r := new(Release)
|
|
resp, err := s.client.Do(req, r)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return r, resp, err
|
|
}
|