Skip to content

Commit 8d7be58

Browse files
authored
Merge pull request #74 from EyalDelarea/add_edit_pull_request
Add Edit Pull Request
2 parents baf7899 + 4bb9efd commit 8d7be58

File tree

5 files changed

+145
-0
lines changed

5 files changed

+145
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ Class | Method | HTTP request | Description
192192
*DefaultApi* | [**UpdateComment_0**](docs/DefaultApi.md#updatecomment_0) | **Put** /api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/comments/{commentId} |
193193
*DefaultApi* | [**UpdateProject**](docs/DefaultApi.md#updateproject) | **Put** /api/1.0/projects/{projectKey} |
194194
*DefaultApi* | [**UpdatePullRequestSettings**](docs/DefaultApi.md#updatepullrequestsettings) | **Post** /api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/pull-requests |
195+
*DefaultApi* | [**UpdatePullRequest**](docs/DefaultApi.md#updatepullrequest) | **Put** /api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId} |
195196
*DefaultApi* | [**UpdatePullRequestSettings_0**](docs/DefaultApi.md#updatepullrequestsettings_0) | **Post** /api/1.0/projects/{projectKey}/settings/pull-requests/{scmId} |
196197
*DefaultApi* | [**UpdateRepository**](docs/DefaultApi.md#updaterepository) | **Put** /api/1.0/projects/{projectKey}/repos/{repositorySlug} |
197198
*DefaultApi* | [**UpdateSettings**](docs/DefaultApi.md#updatesettings) | **Post** /api/1.0/users/{userSlug}/settings |

api_response.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,16 @@ type PullRequest struct {
223223
Links Links `json:"links"`
224224
}
225225

226+
// EditPullRequestOptions editable values of a pull request.
227+
type EditPullRequestOptions struct {
228+
Version string `json:"version"`
229+
ID int64 `json:"id,omitempty"`
230+
State string `json:"state,omitempty"`
231+
Title string `json:"title,omitempty"`
232+
Description string `json:"description,omitempty"`
233+
TargetBranchRef PullRequestRef `json:"targetBranchRef"`
234+
}
235+
226236
// SSHKey contains data from a SSHKey in the BitBucket Server
227237
type SSHKey struct {
228238
ID int `json:"id"`

default_api.go

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

664+
/*
665+
DefaultApiService
666+
667+
Update the title, description, reviewers or destination branch of an existing pull request. <p> <strong>Note:</strong> the <em>reviewers</em> list may be updated using this resource. However the <em>author</em> and <em>participants</em> list may not. <p> The authenticated user must either: <ul> <li>be the author of the pull request and have the <strong>REPO_READ</strong> permission for the repository that this pull request targets; or</li> <li>have the <strong>REPO_WRITE</strong> permission for the repository that this pull request targets</li> </ul> to call this resource.
668+
669+
@param pullRequestId the ID of the pull request within the repository
670+
@return
671+
*/
672+
func (a *DefaultApiService) UpdatePullRequest(projectKey, repositorySlug string, options *EditPullRequestOptions) (*APIResponse, error) {
673+
var (
674+
localVarHTTPMethod = strings.ToUpper("Put")
675+
localVarPostBody interface{}
676+
localVarFileName string
677+
localVarFileBytes []byte
678+
)
679+
680+
// create path and map variables
681+
localVarPath := a.client.cfg.BasePath + "/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}"
682+
localVarPath = strings.Replace(localVarPath, "{"+"projectKey"+"}", fmt.Sprintf("%v", projectKey), -1)
683+
localVarPath = strings.Replace(localVarPath, "{"+"repositorySlug"+"}", fmt.Sprintf("%v", repositorySlug), -1)
684+
localVarPath = strings.Replace(localVarPath, "{"+"pullRequestId"+"}", fmt.Sprintf("%v", options.ID), -1)
685+
686+
localVarHeaderParams := make(map[string]string)
687+
localVarQueryParams := url.Values{}
688+
localVarFormParams := url.Values{}
689+
690+
// to determine the Content-Type header
691+
localVarHTTPContentTypes := []string{"application/json"}
692+
693+
// set Content-Type header
694+
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
695+
if localVarHTTPContentType != "" {
696+
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
697+
}
698+
699+
// to determine the Accept header
700+
localVarHTTPHeaderAccepts := []string{}
701+
702+
// set Accept header
703+
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
704+
if localVarHTTPHeaderAccept != "" {
705+
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
706+
}
707+
localVarPostBody = &options
708+
r, err := a.client.prepareRequest(a.client.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
709+
if err != nil {
710+
return nil, err
711+
}
712+
713+
localVarHTTPResponse, err := a.client.callAPI(r)
714+
if err != nil || localVarHTTPResponse == nil {
715+
return NewAPIResponseWithError(localVarHTTPResponse, nil, err)
716+
}
717+
defer localVarHTTPResponse.Body.Close()
718+
if localVarHTTPResponse.StatusCode >= 300 {
719+
bodyBytes, _ := ioutil.ReadAll(localVarHTTPResponse.Body)
720+
return NewAPIResponseWithError(localVarHTTPResponse, bodyBytes, reportError("Status: %v, Description: %s", localVarHTTPResponse.Status, bodyBytes))
721+
}
722+
723+
return NewBitbucketAPIResponse(localVarHTTPResponse)
724+
}
725+
664726
/* DefaultApiService
665727
Creates a branch using the information provided in the {@link RestCreateBranchRequest request} <p> The authenticated user must have <strong>REPO_WRITE</strong> permission for the context repository to call this resource.
666728

default_api_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,49 @@ func TestDefaultApiService_CreatePullRequest(t *testing.T) {
619619
})
620620
}
621621
}
622+
623+
func TestDefaultApiService_UpdatePullRequest(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: "Put https://stash.domain.com/rest/api/1.0/projects/test/repos/repoTest/pull-requests/0: 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.UpdatePullRequest(tt.projectKey, tt.repositorySlug, tt.updatePullRequestOptions)
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+
622665
func TestDefaultApiService_CreateBranch(t *testing.T) {
623666
type fields struct {
624667
client *APIClient

docs/DefaultApi.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5754,6 +5754,35 @@ No authorization required
57545754

57555755
[[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)
57565756

5757+
# **UpdatePullRequest**
5758+
> UpdatePullRequest(ctx, &EditPullRequestOptions{} )
5759+
5760+
5761+
Update the title, description, reviewers or destination branch of an existing pull request.. <p> The authenticated user must have <strong>REPO_ADMIN</strong> permission for the context repository to call this resource. <p> This resource will call all RestFragments that are registered with the key <strong>bitbucket.repository.settings.pullRequests</strong>.<ul>
5762+
5763+
### Required Parameters
5764+
5765+
Name | Type | Description | Notes
5766+
------------- | ------------- | ------------- | -------------
5767+
**ctx** | **context.Context** | context for logging, tracing, authentication, etc.
5768+
**projectKey** | **string**| The project key |
5769+
**pullRequestId** | **string**| The ID of the pull request within the repository |
5770+
**repositorySlug** | **string**| The repository slug. |
5771+
5772+
5773+
### Return type
5774+
5775+
RestPullRequest
5776+
5777+
### Authorization
5778+
5779+
Authorization is required.
5780+
5781+
### HTTP request headers
5782+
5783+
- **Content-Type**: application/json
5784+
- **Accept**: Not defined
5785+
57575786
# **UpdatePullRequestSettings**
57585787
> UpdatePullRequestSettings(ctx, )
57595788

0 commit comments

Comments
 (0)