From f42fe44f2e73d30e323d706ea994ef3c540889a3 Mon Sep 17 00:00:00 2001 From: dblencowe Date: Wed, 13 Sep 2023 11:33:16 +0100 Subject: [PATCH 1/3] feat: adds GetRepositoryPullRequests function for getting pull requests at a repository level --- README.md | 1 + default_api_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ docs/DefaultApi.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) diff --git a/README.md b/README.md index 1690816..108cadf 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,7 @@ Class | Method | HTTP request | Description *DefaultApi* | [**GetRepositoryHook_0**](docs/DefaultApi.md#getrepositoryhook_0) | **Get** /api/1.0/projects/{projectKey}/settings/hooks/{hookKey} | *DefaultApi* | [**GetRepositoryHooks**](docs/DefaultApi.md#getrepositoryhooks) | **Get** /api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/hooks | *DefaultApi* | [**GetRepositoryHooks_0**](docs/DefaultApi.md#getrepositoryhooks_0) | **Get** /api/1.0/projects/{projectKey}/settings/hooks | +*DefaultApi* | [**GetRepositoryPullRequests**](docs/DefaultApi.md#getrepositorypullrequests) | **Get** /api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests *DefaultApi* | [**GetRootLevel**](docs/DefaultApi.md#getrootlevel) | **Get** /api/1.0/logs/rootLogger | *DefaultApi* | [**GetSenderAddress**](docs/DefaultApi.md#getsenderaddress) | **Get** /api/1.0/admin/mail-server/sender-address | *DefaultApi* | [**GetSettings**](docs/DefaultApi.md#getsettings) | **Get** /api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/hooks/{hookKey}/settings | diff --git a/default_api_test.go b/default_api_test.go index 9350e0a..7d31030 100644 --- a/default_api_test.go +++ b/default_api_test.go @@ -630,6 +630,48 @@ func TestDefaultApiService_CreatePullRequest(t *testing.T) { } } +func TestDefaultApiService_GetRepositoryPullRequests(t *testing.T) { + type fields struct { + client *APIClient + } + tests := []struct { + name string + projectKey string + repositorySlug string + want *APIResponse + updatePullRequestOptions *EditPullRequestOptions + wantErr bool + fields fields + }{ + { + projectKey: "test", + repositorySlug: "repoTest", + want: &APIResponse{Message: "Get https://stash.domain.com/rest/api/1.0/projects/test/repos/repoTest/pull-requests: context canceled"}, + updatePullRequestOptions: &EditPullRequestOptions{}, + wantErr: true, + fields: fields{client: generateConfigFake()}, + }, + } + for _, tt := range tests { + client := &DefaultApiService{ + client: tt.fields.client, + } + t.Run(tt.name, func(t *testing.T) { + got, err := client.GetRepositoryPullRequests(tt.projectKey, tt.repositorySlug, nil) + if (err != nil) != tt.wantErr { + t.Errorf("DefaultApiService.Create() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != nil { + got.Response = nil + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("DefaultApiService.Create() = %v, want %v", got, tt.want) + } + }) + } +} + func TestDefaultApiService_UpdatePullRequest(t *testing.T) { type fields struct { client *APIClient diff --git a/docs/DefaultApi.md b/docs/DefaultApi.md index 48241c1..01801f8 100644 --- a/docs/DefaultApi.md +++ b/docs/DefaultApi.md @@ -103,6 +103,7 @@ Method | HTTP request | Description [**GetRepositoryHook_0**](DefaultApi.md#GetRepositoryHook_0) | **Get** /api/1.0/projects/{projectKey}/settings/hooks/{hookKey} | [**GetRepositoryHooks**](DefaultApi.md#GetRepositoryHooks) | **Get** /api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/hooks | [**GetRepositoryHooks_0**](DefaultApi.md#GetRepositoryHooks_0) | **Get** /api/1.0/projects/{projectKey}/settings/hooks | +[**GetRepositoryPullRequests**](DefaultApi.md#getrepositorypullrequests) | **Get** /api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests [**GetRootLevel**](DefaultApi.md#GetRootLevel) | **Get** /api/1.0/logs/rootLogger | [**GetSenderAddress**](DefaultApi.md#GetSenderAddress) | **Get** /api/1.0/admin/mail-server/sender-address | [**GetSettings**](DefaultApi.md#GetSettings) | **Get** /api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/hooks/{hookKey}/settings | @@ -3317,6 +3318,47 @@ No authorization required [[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) +# **GetRepositoryPullRequests** +> GetRepositoryPullRequests(projectKey, repositoryKey, optional) + + +Retrieve a page of pull requests to or from the specified repository.

The authenticated user must have REPO_READ permission for the specified repository to call this resource. + +### Required Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **projectKey** | **string** | context for logging, tracing, authentication, etc. + **repositoryKey** | **string** | optional parameters | nil if no parameters + **optional** | **map[string]interface{}** | optional parameters | nil if no parameters + +### Optional Parameters +Optional parameters are passed through a map[string]interface{}. + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **direction** | **string**| the direction relative to the specified repository. Either INCOMING or OUTGOING. | [default to INCOMING ] + **at** | **string**| a fully-qualified branch ID to find pull requests to or from, such as {@code refs/heads/master}c | [default to ] + **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 ] + **order** | **string**| the order to return pull requests in, either OLDEST (as in: "oldest first") or NEWEST. | [default to NEWEST ] + **withAttributes** | **boolean**| whether to return additional pull request attributes | [default to true ] + **withProperties** | **boolean**| whether to return additional pull request properties | [default to true ] + +### Return type + + (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: Not defined + +[[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) + # **GetRootLevel** > GetRootLevel(ctx, ) From 9508de7c30c85fa8257df604783ac121b82a1d4a Mon Sep 17 00:00:00 2001 From: dblencowe Date: Wed, 13 Sep 2023 11:37:24 +0100 Subject: [PATCH 2/3] chore: rename module --- go.mod | 2 +- go.sum | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index e9d465c..c13d634 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/gfleury/go-bitbucket-v1 +module github.com/dblencowe/go-bitbucket-v1 go 1.14 diff --git a/go.sum b/go.sum index c626b56..c96a3a4 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,5 @@ cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/gfleury/go-bitbucket-v1/test/bb-mock-server v0.0.0-20230825095122-9bc1711434ab/go.mod h1:VssB0kb1cETNaFFC/0mHVCj+7i5TS2xraYq+tl9JLwE= github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc= From d15aa4932d9b34df6bfe709358371d6f2ef4fc7a Mon Sep 17 00:00:00 2001 From: dblencowe Date: Wed, 29 Nov 2023 12:39:45 +0000 Subject: [PATCH 3/3] feat: adds functionality for fetching pull requests at repo level --- cmd/main.go | 2 +- default_api.go | 112 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 1 deletion(-) diff --git a/cmd/main.go b/cmd/main.go index 1d06104..42cff5d 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - "github.com/gfleury/go-bitbucket-v1" + "github.com/dblencowe/go-bitbucket-v1" ) func main() { diff --git a/default_api.go b/default_api.go index e664649..cf3d113 100644 --- a/default_api.go +++ b/default_api.go @@ -9,6 +9,7 @@ import ( "fmt" "io" "net/url" + "strconv" "strings" "github.com/mitchellh/mapstructure" @@ -695,6 +696,117 @@ func (a *DefaultApiService) CreatePullRequest(projectKey, repositorySlug string, return NewBitbucketAPIResponse(localVarHTTPResponse) } +/* + */ +func (a *DefaultApiService) GetRepositoryPullRequests(projectKey, repositorySlug string, localVarOptionals map[string]interface{}) (*APIResponse, error) { + var ( + localVarHTTPMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + ) + + if localVarOptionals == nil { + localVarOptionals = make(map[string]interface{}) + } + + localVarPath := a.client.cfg.BasePath + fmt.Sprintf("/api/1.0/projects/%s/repos/%s/pull-requests", + projectKey, + repositorySlug, + ) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["direction"], "string", "direction"); err != nil { + return nil, err + } + + if err := typeCheckParameter(localVarOptionals["at"], "string", "at"); err != nil { + return nil, err + } + + if err := typeCheckParameter(localVarOptionals["state"], "string", "state"); err != nil { + return nil, err + } + + if err := typeCheckParameter(localVarOptionals["order"], "string", "order"); err != nil { + return nil, err + } + + if err := typeCheckParameter(localVarOptionals["withAttributes"], "bool", "withAttributes"); err != nil { + return nil, err + } + + if err := typeCheckParameter(localVarOptionals["withProperties"], "bool", "withProperties"); err != nil { + return nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["direction"].(string); localVarOk { + localVarQueryParams.Add("direction", parameterToString(localVarTempParam, "")) + } + + if localVarTempParam, localVarOk := localVarOptionals["at"].(string); localVarOk { + localVarQueryParams.Add("direatction", parameterToString(localVarTempParam, "")) + } + + if localVarTempParam, localVarOk := localVarOptionals["state"].(string); localVarOk { + localVarQueryParams.Add("state", parameterToString(localVarTempParam, "")) + } + + if localVarTempParam, localVarOk := localVarOptionals["order"].(string); localVarOk { + localVarQueryParams.Add("order", parameterToString(localVarTempParam, "")) + } + + if localVarTempParam, localVarOk := localVarOptionals["withAttributes"].(string); localVarOk { + if _, err := strconv.ParseBool(localVarTempParam); err == nil { + localVarQueryParams.Add("withAttributes", localVarTempParam) + } + } + + if localVarTempParam, localVarOk := localVarOptionals["withProperties"].(string); localVarOk { + if _, err := strconv.ParseBool(localVarTempParam); err == nil { + localVarQueryParams.Add("withProperties", localVarTempParam) + } + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + + r, err := a.client.prepareRequest(a.client.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(r) + if err != nil || localVarHTTPResponse == nil { + return NewAPIResponseWithError(localVarHTTPResponse, nil, err) + } + defer localVarHTTPResponse.Body.Close() + if localVarHTTPResponse.StatusCode >= 300 { + bodyBytes, _ := io.ReadAll(localVarHTTPResponse.Body) + return NewAPIResponseWithError(localVarHTTPResponse, bodyBytes, reportError("Status: %v, Body: %s", localVarHTTPResponse.Status, bodyBytes)) + } + + return NewBitbucketAPIResponse(localVarHTTPResponse) +} + /* DefaultApiService