1 // Copyright 2022, Daniela Filipe Bento 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 package gitlab 15 16 import ( 17 "fmt" 18 "net/http" 19 ) 20 21 // DeploymentMergeRequestsService handles communication with the deployment's 22 // merge requests related methods of the GitLab API. 23 // 24 // GitLab API docs: 25 // https://docs.gitlab.com/ee/api/deployments.html#list-of-merge-requests-associated-with-a-deployment 26 type DeploymentMergeRequestsService struct { 27 client *Client 28 } 29 30 // ListDeploymentMergeRequests get the merge requests associated with deployment. 31 // 32 // GitLab API docs: 33 // https://docs.gitlab.com/ee/api/deployments.html#list-of-merge-requests-associated-with-a-deployment 34 func (s *DeploymentMergeRequestsService) ListDeploymentMergeRequests(pid interface{}, deployment int, opts *ListMergeRequestsOptions, options ...RequestOptionFunc) ([]*MergeRequest, *Response, error) { 35 project, err := parseID(pid) 36 if err != nil { 37 return nil, nil, err 38 } 39 u := fmt.Sprintf("projects/%s/deployments/%d/merge_requests", PathEscape(project), deployment) 40 41 req, err := s.client.NewRequest(http.MethodGet, u, opts, options) 42 if err != nil { 43 return nil, nil, err 44 } 45 46 var mrs []*MergeRequest 47 resp, err := s.client.Do(req, &mrs) 48 if err != nil { 49 return nil, resp, err 50 } 51 52 return mrs, resp, nil 53 } 54