gitignore_templates.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // Copyright 2018, Sander van Harmelen
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. package gitlab
  17. import (
  18. "fmt"
  19. "net/url"
  20. )
  21. // GitIgnoreTemplatesService handles communication with the gitignore
  22. // templates related methods of the GitLab API.
  23. //
  24. // GitLab API docs: https://docs.gitlab.com/ce/api/templates/gitignores.html
  25. type GitIgnoreTemplatesService struct {
  26. client *Client
  27. }
  28. // GitIgnoreTemplate represents a GitLab gitignore template.
  29. //
  30. // GitLab API docs: https://docs.gitlab.com/ce/api/templates/gitignores.html
  31. type GitIgnoreTemplate struct {
  32. Name string `json:"name"`
  33. Content string `json:"content"`
  34. }
  35. // ListTemplatesOptions represents the available ListAllTemplates() options.
  36. //
  37. // GitLab API docs:
  38. // https://docs.gitlab.com/ce/api/templates/gitignores.html#list-gitignore-templates
  39. type ListTemplatesOptions ListOptions
  40. // ListTemplates get a list of available git ignore templates
  41. //
  42. // GitLab API docs:
  43. // https://docs.gitlab.com/ce/api/templates/gitignores.html#list-gitignore-templates
  44. func (s *GitIgnoreTemplatesService) ListTemplates(opt *ListTemplatesOptions, options ...OptionFunc) ([]*GitIgnoreTemplate, *Response, error) {
  45. req, err := s.client.NewRequest("GET", "templates/gitignores", opt, options)
  46. if err != nil {
  47. return nil, nil, err
  48. }
  49. var gs []*GitIgnoreTemplate
  50. resp, err := s.client.Do(req, &gs)
  51. if err != nil {
  52. return nil, resp, err
  53. }
  54. return gs, resp, err
  55. }
  56. // GetTemplate get a git ignore template
  57. //
  58. // GitLab API docs:
  59. // https://docs.gitlab.com/ce/api/templates/gitignores.html#single-gitignore-template
  60. func (s *GitIgnoreTemplatesService) GetTemplate(key string, options ...OptionFunc) (*GitIgnoreTemplate, *Response, error) {
  61. u := fmt.Sprintf("templates/gitignores/%s", url.QueryEscape(key))
  62. req, err := s.client.NewRequest("GET", u, nil, options)
  63. if err != nil {
  64. return nil, nil, err
  65. }
  66. g := new(GitIgnoreTemplate)
  67. resp, err := s.client.Do(req, g)
  68. if err != nil {
  69. return nil, resp, err
  70. }
  71. return g, resp, err
  72. }