Skip to content

Commit

Permalink
All 8.17 related V4 API changes (xanzy#161)
Browse files Browse the repository at this point in the history
* Change `IID` to `IIDs` where applicable

* Remove the `/project/search` endpoint

Instead `/project?search=query` should be used to search a project. This endpoint already exists as the `ListProjects` function already contains a `search` option.

* Do not return deprecated field `expired_at`

* Change `keys` to `deploy_keys`

And add all missing `deploy_keys` endpoints.
  • Loading branch information
Sander van Harmelen committed Aug 25, 2017
1 parent 9dc6e9e commit d1c986c
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 215 deletions.
75 changes: 59 additions & 16 deletions deploy_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import (
// DeployKeysService handles communication with the keys related methods
// of the GitLab API.
//
// GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/deploy_keys.md
// GitLab API docs: https://docs.gitlab.com/ce/api/deploy_keys.html
type DeployKeysService struct {
client *Client
}
Expand All @@ -44,41 +43,60 @@ func (k DeployKey) String() string {
return Stringify(k)
}

// ListDeployKeys gets a list of a project's deploy keys
// ListAllDeployKeys gets a list of all deploy keys
//
// GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/deploy_keys.md#list-deploy-keys
func (s *DeployKeysService) ListDeployKeys(pid interface{}, options ...OptionFunc) ([]*DeployKey, *Response, error) {
// https://docs.gitlab.com/ce/api/deploy_keys.html#list-all-deploy-keys
func (s *DeployKeysService) ListAllDeployKeys(options ...OptionFunc) ([]*DeployKey, *Response, error) {
req, err := s.client.NewRequest("GET", "deploy_keys", nil, options)
if err != nil {
return nil, nil, err
}

var ks []*DeployKey
resp, err := s.client.Do(req, &ks)
if err != nil {
return nil, resp, err
}

return ks, resp, err
}

// ListProjectDeployKeys gets a list of a project's deploy keys
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/deploy_keys.html#list-project-deploy-keys
func (s *DeployKeysService) ListProjectDeployKeys(pid interface{}, options ...OptionFunc) ([]*DeployKey, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/keys", url.QueryEscape(project))
u := fmt.Sprintf("projects/%s/deploy_keys", url.QueryEscape(project))

req, err := s.client.NewRequest("GET", u, nil, options)
if err != nil {
return nil, nil, err
}

var k []*DeployKey
resp, err := s.client.Do(req, &k)
var ks []*DeployKey
resp, err := s.client.Do(req, &ks)
if err != nil {
return nil, resp, err
}

return k, resp, err
return ks, resp, err
}

// GetDeployKey gets a single deploy key.
//
// GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/deploy_keys.md#single-deploy-key
// https://docs.gitlab.com/ce/api/deploy_keys.html#single-deploy-key
func (s *DeployKeysService) GetDeployKey(pid interface{}, deployKey int, options ...OptionFunc) (*DeployKey, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/keys/%d", url.QueryEscape(project), deployKey)
u := fmt.Sprintf("projects/%s/deploy_keys/%d", url.QueryEscape(project), deployKey)

req, err := s.client.NewRequest("GET", u, nil, options)
if err != nil {
Expand All @@ -97,7 +115,7 @@ func (s *DeployKeysService) GetDeployKey(pid interface{}, deployKey int, options
// AddDeployKeyOptions represents the available ADDDeployKey() options.
//
// GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/deploy_keys.md#add-deploy-key
// https://docs.gitlab.com/ce/api/deploy_keys.html#add-deploy-key
type AddDeployKeyOptions struct {
Title *string `url:"title,omitempty" json:"title,omitempty"`
Key *string `url:"key,omitempty" json:"key,omitempty"`
Expand All @@ -109,13 +127,13 @@ type AddDeployKeyOptions struct {
// original one was is accessible by same user.
//
// GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/deploy_keys.md#add-deploy-key
// https://docs.gitlab.com/ce/api/deploy_keys.html#add-deploy-key
func (s *DeployKeysService) AddDeployKey(pid interface{}, opt *AddDeployKeyOptions, options ...OptionFunc) (*DeployKey, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/keys", url.QueryEscape(project))
u := fmt.Sprintf("projects/%s/deploy_keys", url.QueryEscape(project))

req, err := s.client.NewRequest("POST", u, opt, options)
if err != nil {
Expand All @@ -134,13 +152,13 @@ func (s *DeployKeysService) AddDeployKey(pid interface{}, opt *AddDeployKeyOptio
// DeleteDeployKey deletes a deploy key from a project.
//
// GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/deploy_keys.md#delete-deploy-key
// https://docs.gitlab.com/ce/api/deploy_keys.html#delete-deploy-key
func (s *DeployKeysService) DeleteDeployKey(pid interface{}, deployKey int, options ...OptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/keys/%d", url.QueryEscape(project), deployKey)
u := fmt.Sprintf("projects/%s/deploy_keys/%d", url.QueryEscape(project), deployKey)

req, err := s.client.NewRequest("DELETE", u, nil, options)
if err != nil {
Expand All @@ -149,3 +167,28 @@ func (s *DeployKeysService) DeleteDeployKey(pid interface{}, deployKey int, opti

return s.client.Do(req, nil)
}

// EnableDeployKey enables a deploy key.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/deploy_keys.html#enable-deploy-key
func (s *DeployKeysService) EnableDeployKey(pid interface{}, deployKey int, options ...OptionFunc) (*DeployKey, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/deploy_keys/%d/enable", url.QueryEscape(project), deployKey)

req, err := s.client.NewRequest("POST", u, nil, options)
if err != nil {
return nil, nil, err
}

k := new(DeployKey)
resp, err := s.client.Do(req, k)
if err != nil {
return nil, resp, err
}

return k, resp, err
}
86 changes: 57 additions & 29 deletions issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@ import (
// IssuesService handles communication with the issue related methods
// of the GitLab API.
//
// GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/issues.md
// GitLab API docs: https://docs.gitlab.com/ce/api/issues.html
type IssuesService struct {
client *Client
}

// Issue represents a GitLab issue.
//
// GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/issues.md
// GitLab API docs: https://docs.gitlab.com/ce/api/issues.html
type Issue struct {
ID int `json:"id"`
IID int `json:"iid"`
Expand Down Expand Up @@ -85,21 +83,21 @@ func (l *Labels) MarshalJSON() ([]byte, error) {

// ListIssuesOptions represents the available ListIssues() options.
//
// GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/issues.md#list-issues
// GitLab API docs: https://docs.gitlab.com/ce/api/issues.html#list-issues
type ListIssuesOptions struct {
ListOptions
State *string `url:"state,omitempty" json:"state,omitempty"`
Labels Labels `url:"labels,comma,omitempty" json:"labels,omitempty"`
OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
IIDs []int `url:"iids[],omitempty" json:"iids,omitempty"`
State *string `url:"state,omitempty" json:"state,omitempty"`
Labels Labels `url:"labels,comma,omitempty" json:"labels,omitempty"`
Milestone *string `url:"milestone,omitempty" json:"milestone,omitempty"`
OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
}

// ListIssues gets all issues created by authenticated user. This function
// takes pagination parameters page and per_page to restrict the list of issues.
//
// GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/issues.md#list-issues
// GitLab API docs: https://docs.gitlab.com/ce/api/issues.html#list-issues
func (s *IssuesService) ListIssues(opt *ListIssuesOptions, options ...OptionFunc) ([]*Issue, *Response, error) {
req, err := s.client.NewRequest("GET", "issues", opt, options)
if err != nil {
Expand All @@ -115,13 +113,50 @@ func (s *IssuesService) ListIssues(opt *ListIssuesOptions, options ...OptionFunc
return i, resp, err
}

// ListGroupIssuesOptions represents the available ListGroupIssues() options.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/issues.html#list-group-issues
type ListGroupIssuesOptions struct {
ListOptions
IIDs []int `url:"iids[],omitempty" json:"iids,omitempty"`
State *string `url:"state,omitempty" json:"state,omitempty"`
Labels Labels `url:"labels,comma,omitempty" json:"labels,omitempty"`
Milestone *string `url:"milestone,omitempty" json:"milestone,omitempty"`
OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
}

// ListGroupIssues gets a list of group issues. This function accepts
// pagination parameters page and per_page to return the list of group issues.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/issues.html#list-group-issues
func (s *IssuesService) ListGroupIssues(pid interface{}, opt *ListGroupIssuesOptions, options ...OptionFunc) ([]*Issue, *Response, error) {
group, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("group/%s/issues", url.QueryEscape(group))

req, err := s.client.NewRequest("GET", u, opt, options)
if err != nil {
return nil, nil, err
}

var i []*Issue
resp, err := s.client.Do(req, &i)
if err != nil {
return nil, resp, err
}

return i, resp, err
}

// ListProjectIssuesOptions represents the available ListProjectIssues() options.
//
// GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/issues.md#list-issues
// GitLab API docs: https://docs.gitlab.com/ce/api/issues.html#list-project-issues
type ListProjectIssuesOptions struct {
ListOptions
IID *int `url:"iid,omitempty" json:"iid,omitempty"`
IIDs []int `url:"iids[],omitempty" json:"iids,omitempty"`
State *string `url:"state,omitempty" json:"state,omitempty"`
Labels Labels `url:"labels,comma,omitempty" json:"labels,omitempty"`
Milestone *string `url:"milestone,omitempty" json:"milestone,omitempty"`
Expand All @@ -132,8 +167,7 @@ type ListProjectIssuesOptions struct {
// ListProjectIssues gets a list of project issues. This function accepts
// pagination parameters page and per_page to return the list of project issues.
//
// GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/issues.md#list-project-issues
// GitLab API docs: https://docs.gitlab.com/ce/api/issues.html#list-project-issues
func (s *IssuesService) ListProjectIssues(pid interface{}, opt *ListProjectIssuesOptions, options ...OptionFunc) ([]*Issue, *Response, error) {
project, err := parseID(pid)
if err != nil {
Expand All @@ -157,8 +191,7 @@ func (s *IssuesService) ListProjectIssues(pid interface{}, opt *ListProjectIssue

// GetIssue gets a single project issue.
//
// GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/issues.md#single-issues
// GitLab API docs: https://docs.gitlab.com/ce/api/issues.html#single-issues
func (s *IssuesService) GetIssue(pid interface{}, issue int, options ...OptionFunc) (*Issue, *Response, error) {
project, err := parseID(pid)
if err != nil {
Expand All @@ -182,8 +215,7 @@ func (s *IssuesService) GetIssue(pid interface{}, issue int, options ...OptionFu

// CreateIssueOptions represents the available CreateIssue() options.
//
// GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/issues.md#new-issues
// GitLab API docs: https://docs.gitlab.com/ce/api/issues.html#new-issues
type CreateIssueOptions struct {
Title *string `url:"title,omitempty" json:"title,omitempty"`
Description *string `url:"description,omitempty" json:"description,omitempty"`
Expand All @@ -194,8 +226,7 @@ type CreateIssueOptions struct {

// CreateIssue creates a new project issue.
//
// GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/issues.md#new-issues
// GitLab API docs: https://docs.gitlab.com/ce/api/issues.html#new-issues
func (s *IssuesService) CreateIssue(pid interface{}, opt *CreateIssueOptions, options ...OptionFunc) (*Issue, *Response, error) {
project, err := parseID(pid)
if err != nil {
Expand All @@ -219,8 +250,7 @@ func (s *IssuesService) CreateIssue(pid interface{}, opt *CreateIssueOptions, op

// UpdateIssueOptions represents the available UpdateIssue() options.
//
// GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/issues.md#edit-issues
// GitLab API docs: https://docs.gitlab.com/ce/api/issues.html#edit-issues
type UpdateIssueOptions struct {
Title *string `url:"title,omitempty" json:"title,omitempty"`
Description *string `url:"description,omitempty" json:"description,omitempty"`
Expand All @@ -233,8 +263,7 @@ type UpdateIssueOptions struct {
// UpdateIssue updates an existing project issue. This function is also used
// to mark an issue as closed.
//
// GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/issues.md#edit-issues
// GitLab API docs: https://docs.gitlab.com/ce/api/issues.html#edit-issues
func (s *IssuesService) UpdateIssue(pid interface{}, issue int, opt *UpdateIssueOptions, options ...OptionFunc) (*Issue, *Response, error) {
project, err := parseID(pid)
if err != nil {
Expand All @@ -258,8 +287,7 @@ func (s *IssuesService) UpdateIssue(pid interface{}, issue int, opt *UpdateIssue

// DeleteIssue deletes a single project issue.
//
// GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/issues.md#delete-an-issue
// GitLab API docs: https://docs.gitlab.com/ce/api/issues.html#delete-an-issue
func (s *IssuesService) DeleteIssue(pid interface{}, issue int, options ...OptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion merge_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (m MergeRequest) String() string {
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/merge_requests.md#list-merge-requests
type ListMergeRequestsOptions struct {
ListOptions
IID *int `url:"iid,omitempty" json:"iid,omitempty"`
IIDs []int `url:"iids[],omitempty" json:"iids,omitempty"`
State *string `url:"state,omitempty" json:"state,omitempty"`
OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
Expand Down
1 change: 0 additions & 1 deletion project_snippets.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ type Snippet struct {
State string `json:"state"`
CreatedAt *time.Time `json:"created_at"`
} `json:"author"`
ExpiresAt *time.Time `json:"expires_at"`
UpdatedAt *time.Time `json:"updated_at"`
CreatedAt *time.Time `json:"created_at"`
}
Expand Down
Loading

0 comments on commit d1c986c

Please sign in to comment.