Commit b4f7417b authored by lillilli's avatar lillilli Committed by Sander van Harmelen

Implemented Gitlab CI YML templates API (#467)

parent 3c183b7d
......@@ -36,9 +36,9 @@ to add new and/or missing endpoints. Currently the following services are suppor
- [x] Feature flags
- [ ] Geo Nodes
- [x] Gitignores templates
- [ ] GitLab CI Config templates
- [x] GitLab CI Config templates
- [x] Groups
- [ ] Group Access Requests
- [x] Group Access Requests
- [x] Group Members
- [x] Issues
- [x] Issue Boards
......@@ -50,7 +50,7 @@ to add new and/or missing endpoints. Currently the following services are suppor
- [x] Merge Requests
- [x] Merge Request Approvals
- [x] Project Milestones
- [ ] Group Milestones
- [x] Group Milestones
- [x] Namespaces
- [x] Notes (comments)
- [ ] Discussions (threaded comments)
......
package gitlab
import (
"fmt"
"net/url"
)
// CIYMLTemplatesService handles communication with the gitlab
// CI YML templates related methods of the GitLab API.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/templates/gitlab_ci_ymls.html
type CIYMLTemplatesService struct {
client *Client
}
// CIYMLTemplate represents a GitLab CI YML template.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/templates/gitlab_ci_ymls.html
type CIYMLTemplate struct {
Name string `json:"name"`
Content string `json:"content"`
}
// ListCIYMLTemplatesOptions represents the available ListAllTemplates() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/templates/gitignores.html#list-gitignore-templates
type ListCIYMLTemplatesOptions ListOptions
// ListAllTemplates get all GitLab CI YML templates.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/templates/gitlab_ci_ymls.html#list-gitlab-ci-yml-templates
func (s *CIYMLTemplatesService) ListAllTemplates(opt *ListCIYMLTemplatesOptions, options ...OptionFunc) ([]*CIYMLTemplate, *Response, error) {
req, err := s.client.NewRequest("GET", "templates/gitlab_ci_ymls", opt, options)
if err != nil {
return nil, nil, err
}
var cts []*CIYMLTemplate
resp, err := s.client.Do(req, &cts)
if err != nil {
return nil, resp, err
}
return cts, resp, err
}
// GetTemplate get a single GitLab CI YML template.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/templates/gitlab_ci_ymls.html#single-gitlab-ci-yml-template
func (s *CIYMLTemplatesService) GetTemplate(key string, options ...OptionFunc) (*CIYMLTemplate, *Response, error) {
u := fmt.Sprintf("templates/gitlab_ci_ymls/%s", url.QueryEscape(key))
req, err := s.client.NewRequest("GET", u, nil, options)
if err != nil {
return nil, nil, err
}
ct := new(CIYMLTemplate)
resp, err := s.client.Do(req, ct)
if err != nil {
return nil, resp, err
}
return ct, resp, err
}
......@@ -278,6 +278,7 @@ type Client struct {
Branches *BranchesService
BuildVariables *BuildVariablesService
BroadcastMessage *BroadcastMessagesService
CIYMLTemplate *CIYMLTemplatesService
Commits *CommitsService
CustomAttribute *CustomAttributesService
DeployKeys *DeployKeysService
......@@ -415,6 +416,7 @@ func newClient(httpClient *http.Client) *Client {
c.Branches = &BranchesService{client: c}
c.BuildVariables = &BuildVariablesService{client: c}
c.BroadcastMessage = &BroadcastMessagesService{client: c}
c.CIYMLTemplate = &CIYMLTemplatesService{client: c}
c.Commits = &CommitsService{client: c}
c.CustomAttribute = &CustomAttributesService{client: c}
c.DeployKeys = &DeployKeysService{client: c}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment