ci_yml_templates.go

 1package gitlab
 2
 3import (
 4	"fmt"
 5)
 6
 7// CIYMLTemplatesService handles communication with the gitlab
 8// CI YML templates related methods of the GitLab API.
 9//
10// GitLab API docs:
11// https://docs.gitlab.com/ce/api/templates/gitlab_ci_ymls.html
12type CIYMLTemplatesService struct {
13	client *Client
14}
15
16// CIYMLTemplate represents a GitLab CI YML template.
17//
18// GitLab API docs:
19// https://docs.gitlab.com/ce/api/templates/gitlab_ci_ymls.html
20type CIYMLTemplate struct {
21	Name    string `json:"name"`
22	Content string `json:"content"`
23}
24
25// ListCIYMLTemplatesOptions represents the available ListAllTemplates() options.
26//
27// GitLab API docs:
28// https://docs.gitlab.com/ce/api/templates/gitignores.html#list-gitignore-templates
29type ListCIYMLTemplatesOptions ListOptions
30
31// ListAllTemplates get all GitLab CI YML templates.
32//
33// GitLab API docs:
34// https://docs.gitlab.com/ce/api/templates/gitlab_ci_ymls.html#list-gitlab-ci-yml-templates
35func (s *CIYMLTemplatesService) ListAllTemplates(opt *ListCIYMLTemplatesOptions, options ...OptionFunc) ([]*CIYMLTemplate, *Response, error) {
36	req, err := s.client.NewRequest("GET", "templates/gitlab_ci_ymls", opt, options)
37	if err != nil {
38		return nil, nil, err
39	}
40
41	var cts []*CIYMLTemplate
42	resp, err := s.client.Do(req, &cts)
43	if err != nil {
44		return nil, resp, err
45	}
46
47	return cts, resp, err
48}
49
50// GetTemplate get a single GitLab CI YML template.
51//
52// GitLab API docs:
53// https://docs.gitlab.com/ce/api/templates/gitlab_ci_ymls.html#single-gitlab-ci-yml-template
54func (s *CIYMLTemplatesService) GetTemplate(key string, options ...OptionFunc) (*CIYMLTemplate, *Response, error) {
55	u := fmt.Sprintf("templates/gitlab_ci_ymls/%s", pathEscape(key))
56
57	req, err := s.client.NewRequest("GET", u, nil, options)
58	if err != nil {
59		return nil, nil, err
60	}
61
62	ct := new(CIYMLTemplate)
63	resp, err := s.client.Do(req, ct)
64	if err != nil {
65		return nil, resp, err
66	}
67
68	return ct, resp, err
69}