1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
package api
import gitlab "gitlab.com/gitlab-org/api/client-go"
type ListLabelsOptions struct {
WithCounts *bool
PerPage int
Page int
}
func (opts *ListLabelsOptions) ListLabelsOptions() *gitlab.ListLabelsOptions {
projectOpts := &gitlab.ListLabelsOptions{}
projectOpts.WithCounts = opts.WithCounts
projectOpts.PerPage = opts.PerPage
projectOpts.Page = opts.Page
return projectOpts
}
func (opts *ListLabelsOptions) ListGroupLabelsOptions() *gitlab.ListGroupLabelsOptions {
groupOpts := &gitlab.ListGroupLabelsOptions{}
groupOpts.WithCounts = opts.WithCounts
groupOpts.PerPage = opts.PerPage
groupOpts.Page = opts.Page
return groupOpts
}
func getClient(client *gitlab.Client) *gitlab.Client {
if client == nil {
return apiClient.Lab()
}
return client
}
var CreateLabel = func(client *gitlab.Client, projectID interface{}, opts *gitlab.CreateLabelOptions) (*gitlab.Label, error) {
client = getClient(client)
label, _, err := client.Labels.CreateLabel(projectID, opts)
if err != nil {
return nil, err
}
return label, nil
}
var DeleteLabel = func(client *gitlab.Client, projectID interface{}, label string, opts *gitlab.DeleteLabelOptions) error {
client = getClient(client)
_, err := client.Labels.DeleteLabel(projectID, label, opts)
if err != nil {
return err
}
return nil
}
var ListLabels = func(client *gitlab.Client, projectID interface{}, opts *ListLabelsOptions) ([]*gitlab.Label, error) {
client = getClient(client)
if opts.PerPage == 0 {
opts.PerPage = DefaultListLimit
}
label, _, err := client.Labels.ListLabels(projectID, opts.ListLabelsOptions())
if err != nil {
return nil, err
}
return label, nil
}
var ListGroupLabels = func(client *gitlab.Client, groupID interface{}, opts *ListLabelsOptions) ([]*gitlab.GroupLabel, error) {
client = getClient(client)
if opts.PerPage == 0 {
opts.PerPage = DefaultListLimit
}
labels, _, err := client.GroupLabels.ListGroupLabels(groupID, opts.ListGroupLabelsOptions())
if err != nil {
return nil, err
}
return labels, nil
}
|