Skip to content

Commit 0ead0d3

Browse files
committed
feat: adds GetRepositoryPullRequests function for getting pull requests at a repository level
1 parent 8d7be58 commit 0ead0d3

File tree

4 files changed

+188
-0
lines changed

4 files changed

+188
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ Class | Method | HTTP request | Description
116116
*DefaultApi* | [**GetRepositoryHook_0**](docs/DefaultApi.md#getrepositoryhook_0) | **Get** /api/1.0/projects/{projectKey}/settings/hooks/{hookKey} |
117117
*DefaultApi* | [**GetRepositoryHooks**](docs/DefaultApi.md#getrepositoryhooks) | **Get** /api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/hooks |
118118
*DefaultApi* | [**GetRepositoryHooks_0**](docs/DefaultApi.md#getrepositoryhooks_0) | **Get** /api/1.0/projects/{projectKey}/settings/hooks |
119+
*DefaultApi* | [**GetRepositoryPullRequests**](docs/DefaultApi.md#getrepositorypullrequests) | **Get** /api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests
119120
*DefaultApi* | [**GetRootLevel**](docs/DefaultApi.md#getrootlevel) | **Get** /api/1.0/logs/rootLogger |
120121
*DefaultApi* | [**GetSenderAddress**](docs/DefaultApi.md#getsenderaddress) | **Get** /api/1.0/admin/mail-server/sender-address |
121122
*DefaultApi* | [**GetSettings**](docs/DefaultApi.md#getsettings) | **Get** /api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/hooks/{hookKey}/settings |

default_api.go

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,109 @@ func (a *DefaultApiService) CreatePullRequest(projectKey, repositorySlug string,
661661
return NewBitbucketAPIResponse(localVarHTTPResponse)
662662
}
663663

664+
/*
665+
*/
666+
func (a *DefaultApiService) GetRepositoryPullRequests(projectKey, repositorySlug string, localVarOptionals map[string]interface{}) (*APIResponse, error) {
667+
var (
668+
localVarHTTPMethod = strings.ToUpper("Get")
669+
localVarPostBody interface{}
670+
localVarFileName string
671+
localVarFileBytes []byte
672+
)
673+
674+
localVarPath := a.client.cfg.BasePath + fmt.Sprintf("/api/1.0/projects/%s/repos/%s/pull-requests",
675+
projectKey,
676+
repositorySlug,
677+
)
678+
679+
localVarHeaderParams := make(map[string]string)
680+
localVarQueryParams := url.Values{}
681+
localVarFormParams := url.Values{}
682+
683+
if err := typeCheckParameter(localVarOptionals["direction"], "string", "direction"); err != nil {
684+
return nil, err
685+
}
686+
687+
if err := typeCheckParameter(localVarOptionals["at"], "string", "at"); err != nil {
688+
return nil, err
689+
}
690+
691+
if err := typeCheckParameter(localVarOptionals["state"], "string", "state"); err != nil {
692+
return nil, err
693+
}
694+
695+
if err := typeCheckParameter(localVarOptionals["order"], "string", "order"); err != nil {
696+
return nil, err
697+
}
698+
699+
if err := typeCheckParameter(localVarOptionals["withAttributes"], "bool", "withAttributes"); err != nil {
700+
return nil, err
701+
}
702+
703+
if err := typeCheckParameter(localVarOptionals["withProperties"], "bool", "withProperties"); err != nil {
704+
return nil, err
705+
}
706+
707+
if localVarTempParam, localVarOk := localVarOptionals["direction"].(string); localVarOk {
708+
localVarQueryParams.Add("direction", parameterToString(localVarTempParam, ""))
709+
}
710+
711+
if localVarTempParam, localVarOk := localVarOptionals["at"].(string); localVarOk {
712+
localVarQueryParams.Add("direatction", parameterToString(localVarTempParam, ""))
713+
}
714+
715+
if localVarTempParam, localVarOk := localVarOptionals["state"].(string); localVarOk {
716+
localVarQueryParams.Add("state", parameterToString(localVarTempParam, ""))
717+
}
718+
719+
if localVarTempParam, localVarOk := localVarOptionals["order"].(string); localVarOk {
720+
localVarQueryParams.Add("order", parameterToString(localVarTempParam, ""))
721+
}
722+
723+
if localVarTempParam, localVarOk := localVarOptionals["withAttributes"].(string); localVarOk {
724+
localVarQueryParams.Add("withAttributes", bool(localVarTempParam))
725+
}
726+
727+
if localVarTempParam, localVarOk := localVarOptionals["withProperties"].(string); localVarOk {
728+
localVarQueryParams.Add("withProperties", bool(localVarTempParam))
729+
}
730+
731+
// to determine the Content-Type header
732+
localVarHTTPContentTypes := []string{"application/json"}
733+
734+
// set Content-Type header
735+
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
736+
if localVarHTTPContentType != "" {
737+
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
738+
}
739+
740+
// to determine the Accept header
741+
localVarHTTPHeaderAccepts := []string{}
742+
743+
// set Accept header
744+
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
745+
if localVarHTTPHeaderAccept != "" {
746+
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
747+
}
748+
749+
r, err := a.client.prepareRequest(a.client.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
750+
if err != nil {
751+
return nil, err
752+
}
753+
754+
localVarHTTPResponse, err := a.client.callAPI(r)
755+
if err != nil || localVarHTTPResponse == nil {
756+
return NewAPIResponseWithError(localVarHTTPResponse, nil, err)
757+
}
758+
defer localVarHTTPResponse.Body.Close()
759+
if localVarHTTPResponse.StatusCode >= 300 {
760+
bodyBytes, _ := ioutil.ReadAll(localVarHTTPResponse.Body)
761+
return NewAPIResponseWithError(localVarHTTPResponse, bodyBytes, reportError("Status: %v, Body: %s", localVarHTTPResponse.Status, bodyBytes))
762+
}
763+
764+
return NewBitbucketAPIResponse(localVarHTTPResponse)
765+
}
766+
664767
/*
665768
DefaultApiService
666769

default_api_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,48 @@ func TestDefaultApiService_CreatePullRequest(t *testing.T) {
620620
}
621621
}
622622

623+
func TestDefaultApiService_GetRepositoryPullRequests(t *testing.T) {
624+
type fields struct {
625+
client *APIClient
626+
}
627+
tests := []struct {
628+
name string
629+
projectKey string
630+
repositorySlug string
631+
want *APIResponse
632+
updatePullRequestOptions *EditPullRequestOptions
633+
wantErr bool
634+
fields fields
635+
}{
636+
{
637+
projectKey: "test",
638+
repositorySlug: "repoTest",
639+
want: &APIResponse{Message: "Get https://stash.domain.com/rest/api/1.0/projects/test/repos/repoTest/pull-requests: context canceled"},
640+
updatePullRequestOptions: &EditPullRequestOptions{},
641+
wantErr: true,
642+
fields: fields{client: generateConfigFake()},
643+
},
644+
}
645+
for _, tt := range tests {
646+
client := &DefaultApiService{
647+
client: tt.fields.client,
648+
}
649+
t.Run(tt.name, func(t *testing.T) {
650+
got, err := client.GetRepositoryPullRequests(tt.projectKey, tt.repositorySlug)
651+
if (err != nil) != tt.wantErr {
652+
t.Errorf("DefaultApiService.Create() error = %v, wantErr %v", err, tt.wantErr)
653+
return
654+
}
655+
if got != nil {
656+
got.Response = nil
657+
}
658+
if !reflect.DeepEqual(got, tt.want) {
659+
t.Errorf("DefaultApiService.Create() = %v, want %v", got, tt.want)
660+
}
661+
})
662+
}
663+
}
664+
623665
func TestDefaultApiService_UpdatePullRequest(t *testing.T) {
624666
type fields struct {
625667
client *APIClient

docs/DefaultApi.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ Method | HTTP request | Description
103103
[**GetRepositoryHook_0**](DefaultApi.md#GetRepositoryHook_0) | **Get** /api/1.0/projects/{projectKey}/settings/hooks/{hookKey} |
104104
[**GetRepositoryHooks**](DefaultApi.md#GetRepositoryHooks) | **Get** /api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/hooks |
105105
[**GetRepositoryHooks_0**](DefaultApi.md#GetRepositoryHooks_0) | **Get** /api/1.0/projects/{projectKey}/settings/hooks |
106+
[**GetRepositoryPullRequests**](DefaultApi.md#getrepositorypullrequests) | **Get** /api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests
106107
[**GetRootLevel**](DefaultApi.md#GetRootLevel) | **Get** /api/1.0/logs/rootLogger |
107108
[**GetSenderAddress**](DefaultApi.md#GetSenderAddress) | **Get** /api/1.0/admin/mail-server/sender-address |
108109
[**GetSettings**](DefaultApi.md#GetSettings) | **Get** /api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/hooks/{hookKey}/settings |
@@ -3317,6 +3318,47 @@ No authorization required
33173318

33183319
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
33193320

3321+
# **GetRepositoryPullRequests**
3322+
> GetRepositoryPullRequests(projectKey, repositoryKey, optional)
3323+
3324+
3325+
Retrieve a page of pull requests to or from the specified repository. <p> The authenticated user must have <strong>REPO_READ</strong> permission for the specified repository to call this resource.
3326+
3327+
### Required Parameters
3328+
3329+
Name | Type | Description | Notes
3330+
------------- | ------------- | ------------- | -------------
3331+
**projectKey** | **string** | context for logging, tracing, authentication, etc.
3332+
**repositoryKey** | **string** | optional parameters | nil if no parameters
3333+
**optional** | **map[string]interface{}** | optional parameters | nil if no parameters
3334+
3335+
### Optional Parameters
3336+
Optional parameters are passed through a map[string]interface{}.
3337+
3338+
Name | Type | Description | Notes
3339+
------------- | ------------- | ------------- | -------------
3340+
**direction** | **string**| the direction relative to the specified repository. Either INCOMING or OUTGOING. | [default to INCOMING ]
3341+
**at** | **string**| a fully-qualified branch ID to find pull requests to or from, such as {@code refs/heads/master}c | [default to ]
3342+
**state** | **string**| supply ALL to return pull request in any state. If a state is supplied only pull requests in the specified state will be returned. Either OPEN, DECLINED or MERGED | [default to OPEN ]
3343+
**order** | **string**| the order to return pull requests in, either OLDEST (as in: "oldest first") or NEWEST. | [default to NEWEST ]
3344+
**withAttributes** | **boolean**| whether to return additional pull request attributes | [default to true ]
3345+
**withProperties** | **boolean**| whether to return additional pull request properties | [default to true ]
3346+
3347+
### Return type
3348+
3349+
(empty response body)
3350+
3351+
### Authorization
3352+
3353+
No authorization required
3354+
3355+
### HTTP request headers
3356+
3357+
- **Content-Type**: Not defined
3358+
- **Accept**: Not defined
3359+
3360+
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
3361+
33203362
# **GetRootLevel**
33213363
> GetRootLevel(ctx, )
33223364

0 commit comments

Comments
 (0)