From c74bd86e2f7ebc645800161a4b6e6b449465e06c Mon Sep 17 00:00:00 2001 From: "Chris D. Halverson" Date: Thu, 15 Oct 2020 15:34:48 -0500 Subject: [PATCH] Add UpdateDeployKey. Added UpdateDeployKey to match Gitlab API to modify the properties of an existing DeployKey. --- deploy_keys.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/deploy_keys.go b/deploy_keys.go index adb50bdbf..9d71bffe5 100644 --- a/deploy_keys.go +++ b/deploy_keys.go @@ -198,3 +198,37 @@ func (s *DeployKeysService) EnableDeployKey(pid interface{}, deployKey int, opti return k, resp, err } + +// UpdateDeployKeyOptions represents the available UpdateDeployKey() options. +// +// GitLab API docs: +// https://docs.gitlab.com/ce/api/deploy_keys.html#update-deploy-key +type UpdateDeployKeyOptions struct { + Title *string `url:"title,omitempty" json:"title,omitempty"` + CanPush *bool `url:"can_push,omitempty" json:"can_push,omitempty"` +} + +// UpdateDeployKey updates a deploy key for a project. +// +// GitLab API docs: +// https://docs.gitlab.com/ce/api/deploy_keys.html#update-deploy-key +func (s *DeployKeysService) UpdateDeployKey(pid interface{}, deployKey int, opt *UpdateDeployKeyOptions, options ...RequestOptionFunc) (*DeployKey, *Response, error) { + project, err := parseID(pid) + if err != nil { + return nil, nil, err + } + u := fmt.Sprintf("projects/%s/deploy_keys/%d", pathEscape(project), deployKey) + + req, err := s.client.NewRequest("PUT", u, opt, 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 +}