github.com/daeMOn63/bitclient@v0.0.0-20190425080230-bfee94efac35/project_repository_pull-requests.go (about) 1 package bitclient 2 3 import ( 4 "fmt" 5 ) 6 7 func (bc *BitClient) GetPullRequestSettings(projectKey string, repositorySlug string) (PullRequestSettings, error) { 8 response := PullRequestSettings{} 9 10 _, err := bc.DoGet( 11 fmt.Sprintf("/projects/%s/repos/%s/settings/pull-requests", projectKey, repositorySlug), 12 nil, 13 &response, 14 ) 15 16 return response, err 17 } 18 19 func (bc *BitClient) SetPullRequestSettings(projectKey string, repositorySlug string, params PullRequestSettings) error { 20 21 // Remove disable mergeConfig strategies or they'll get enabled :/ 22 var filteredStrategies []PullRequestStrategy 23 for _, strategy := range params.MergeConfig.Strategies { 24 if strategy.Enabled == true { 25 filteredStrategies = append(filteredStrategies, strategy) 26 } 27 } 28 params.MergeConfig.Strategies = filteredStrategies 29 30 _, err := bc.DoPost( 31 fmt.Sprintf("/projects/%s/repos/%s/settings/pull-requests", projectKey, repositorySlug), 32 params, 33 nil, 34 ) 35 36 return err 37 } 38 39 // GetPullRequestsRequest defines the available parameters when requesting the list of pull requests 40 // from a repository. 41 type GetPullRequestsRequest struct { 42 PagedRequest 43 Direction string `url:"direction,omitempty"` 44 At string `url:"at,omitempty"` 45 State string `url:"state,omitempty"` 46 Order string `url:"order,omitempty"` 47 WithAttributes bool `url:"withAttributes,omitempty"` 48 WithProperties bool `url:"withProperties,omitempty"` 49 } 50 51 // GetPullRequestsResponse holds the API response data 52 type GetPullRequestsResponse struct { 53 PagedResponse 54 Values []PullRequest 55 } 56 57 // GetPullRequests lists the pull requests from given repository 58 func (bc *BitClient) GetPullRequests(projectKey string, repositorySlug string, params GetPullRequestsRequest) (GetPullRequestsResponse, error) { 59 response := new(GetPullRequestsResponse) 60 61 _, err := bc.DoGet( 62 fmt.Sprintf("/projects/%s/repos/%s/pull-requests", projectKey, repositorySlug), 63 nil, 64 response, 65 ) 66 67 return *response, err 68 }