ci_yml_templates.go 1.9 KB

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