add edit pull request

This commit is contained in:
delarea 2023-06-26 20:53:54 +03:00
parent baf7899569
commit 37ffa8d403
3 changed files with 115 additions and 0 deletions

View File

@ -223,6 +223,16 @@ type PullRequest struct {
Links Links `json:"links"`
}
// EditPullRequestOptions editable values of a pull request.
type EditPullRequestOptions struct {
Version string `json:"version"`
ID int64 `json:"id,omitempty"`
State string `json:"state,omitempty"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
TargetBranchRef PullRequestRef `json:"targetBranchRef"`
}
// SSHKey contains data from a SSHKey in the BitBucket Server
type SSHKey struct {
ID int `json:"id"`

View File

@ -661,6 +661,68 @@ func (a *DefaultApiService) CreatePullRequest(projectKey, repositorySlug string,
return NewBitbucketAPIResponse(localVarHTTPResponse)
}
/*
DefaultApiService
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.
@param pullRequestId the ID of the pull request within the repository
@return
*/
func (a *DefaultApiService) UpdatePullRequest(projectKey, repositorySlug string, options *EditPullRequestOptions) (*APIResponse, error) {
var (
localVarHTTPMethod = strings.ToUpper("Put")
localVarPostBody interface{}
localVarFileName string
localVarFileBytes []byte
)
// create path and map variables
localVarPath := a.client.cfg.BasePath + "/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}"
localVarPath = strings.Replace(localVarPath, "{"+"projectKey"+"}", fmt.Sprintf("%v", projectKey), -1)
localVarPath = strings.Replace(localVarPath, "{"+"repositorySlug"+"}", fmt.Sprintf("%v", repositorySlug), -1)
localVarPath = strings.Replace(localVarPath, "{"+"pullRequestId"+"}", fmt.Sprintf("%v", options.ID), -1)
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
// 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
}
localVarPostBody = &options
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, _ := ioutil.ReadAll(localVarHTTPResponse.Body)
return NewAPIResponseWithError(localVarHTTPResponse, bodyBytes, reportError("Status: %v, Description: %s", localVarHTTPResponse.Status, bodyBytes))
}
return NewBitbucketAPIResponse(localVarHTTPResponse)
}
/* DefaultApiService
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.

View File

@ -619,6 +619,49 @@ func TestDefaultApiService_CreatePullRequest(t *testing.T) {
})
}
}
func TestDefaultApiService_UpdatePullRequest(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: "Put https://stash.domain.com/rest/api/1.0/projects/test/repos/repoTest/pull-requests/0: 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.UpdatePullRequest(tt.projectKey, tt.repositorySlug, tt.updatePullRequestOptions)
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_CreateBranch(t *testing.T) {
type fields struct {
client *APIClient