Skip to content

feat: adds GetRepositoryPullRequests function for getting pull requests at a repository level #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"time"

"github.com/gfleury/go-bitbucket-v1"
"github.com/dblencowe/go-bitbucket-v1"
)

func main() {
Expand Down
112 changes: 112 additions & 0 deletions default_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"io"
"net/url"
"strconv"
"strings"

"github.com/mitchellh/mapstructure"
Expand Down Expand Up @@ -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

Expand Down
42 changes: 42 additions & 0 deletions default_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions docs/DefaultApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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. <p> The authenticated user must have <strong>REPO_READ</strong> 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, )

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/gfleury/go-bitbucket-v1
module github.com/dblencowe/go-bitbucket-v1

go 1.14

Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down