Fix create comment method for commit

This commit is contained in:
Rashit Azizbaev 2021-01-14 12:20:07 +03:00
parent 15f2a16ca8
commit 219e8c92ad
3 changed files with 52 additions and 2 deletions

View File

@ -406,6 +406,27 @@ type SearchQuery struct {
Limits Limits `json:"limits"` Limits Limits `json:"limits"`
} }
type Parent struct {
ID int `json:"id"`
}
type Anchor struct {
DiffType string `json:"diffType,omitempty"`
Line int `json:"line,omitempty"`
LineType string `json:"lineType,omitempty"`
FileType string `json:"fileType,omitempty"`
FromHash string `json:"fromHash,omitempty"`
Path string `json:"path,omitempty"`
SrcPath string `json:"srcPath,omitempty"`
ToHash string `json:"toHash,omitempty"`
}
type Comment struct {
Text string `json:"text"`
Parent *Parent `json:"parent,omitempty"`
Anchor *Anchor `json:"anchor,omitempty"`
}
// String converts global permission to its string representation // String converts global permission to its string representation
func (p PermissionGlobal) String() string { func (p PermissionGlobal) String() string {
return string(p) return string(p)

View File

@ -724,7 +724,7 @@ func (a *DefaultApiService) CreateBranch(projectKey, repositorySlug string) (*AP
@param optional (nil or map[string]interface{}) with one or more of: @param optional (nil or map[string]interface{}) with one or more of:
@param "since" (string) For a merge commit, a parent can be provided to specify which diff the comments should be on. For a commit range, a {@code sinceId} can be provided to specify where the comments should be anchored from. @param "since" (string) For a merge commit, a parent can be provided to specify which diff the comments should be on. For a commit range, a {@code sinceId} can be provided to specify where the comments should be anchored from.
@return */ @return */
func (a *DefaultApiService) CreateComment(projectKey, repositorySlug string, commitId string, localVarOptionals map[string]interface{}) (*APIResponse, error) { func (a *DefaultApiService) CreateComment(projectKey, repositorySlug string, commitId string, comment Comment, localVarOptionals map[string]interface{}) (*APIResponse, error) {
var ( var (
localVarHTTPMethod = strings.ToUpper("Post") localVarHTTPMethod = strings.ToUpper("Post")
localVarPostBody interface{} localVarPostBody interface{}
@ -732,6 +732,12 @@ func (a *DefaultApiService) CreateComment(projectKey, repositorySlug string, com
localVarFileBytes []byte localVarFileBytes []byte
) )
var err error
localVarPostBody, err = json.Marshal(comment)
if err != nil {
return nil, err
}
// create path and map variables // create path and map variables
localVarPath := a.client.cfg.BasePath + "/api/1.0/projects/{projectKey}/repos/{repositorySlug}/commits/{commitId}/comments" localVarPath := a.client.cfg.BasePath + "/api/1.0/projects/{projectKey}/repos/{repositorySlug}/commits/{commitId}/comments"
localVarPath = strings.Replace(localVarPath, "{"+"projectKey"+"}", fmt.Sprintf("%v", projectKey), -1) localVarPath = strings.Replace(localVarPath, "{"+"projectKey"+"}", fmt.Sprintf("%v", projectKey), -1)

View File

@ -661,6 +661,7 @@ func TestDefaultApiService_CreateComment(t *testing.T) {
projectKey string projectKey string
repositorySlug string repositorySlug string
commitId string commitId string
comment Comment
localVarOptionals map[string]interface{} localVarOptionals map[string]interface{}
} }
tests := []struct { tests := []struct {
@ -671,6 +672,25 @@ func TestDefaultApiService_CreateComment(t *testing.T) {
wantErr, integrationTest bool wantErr, integrationTest bool
}{ }{
{"networkErrorContextExceeded", fields{client: generateConfigFake()}, args{}, &APIResponse{Message: "Post https://stash.domain.com/rest/api/1.0/projects//repos//commits//comments: context canceled"}, true, false}, {"networkErrorContextExceeded", fields{client: generateConfigFake()}, args{}, &APIResponse{Message: "Post https://stash.domain.com/rest/api/1.0/projects//repos//commits//comments: context canceled"}, true, false},
{"simpleComment", fields{client: generateConfigRealLocalServer()},
args{projectKey: "PROJ",
repositorySlug: "repo1",
commitId: "657f55ce41710f9bfde15c374837136728fae9d9e0eca0b97cb7bfea5095af30",
comment: Comment{Text: "Simple comment"},
},
&APIResponse{Message: `Status: 404 , Body: {errors:[{context:null,message:Commit '657f55ce41710f9bfde15c374837136728fae9d9e0eca0b97cb7bfea5095af30' does not exist in repository 'repo1'.,exceptionName:com.atlassian.bitbucket.commit.NoSuchCommitException}]}`,
Values: map[string]interface{}{
"errors": []interface{}{
map[string]interface{}{
"context": nil,
"message": "Commit '657f55ce41710f9bfde15c374837136728fae9d9e0eca0b97cb7bfea5095af30' does not exist in repository 'repo1'.",
"exceptionName": "com.atlassian.bitbucket.commit.NoSuchCommitException",
},
},
},
},
true, true,
},
} }
for _, tt := range tests { for _, tt := range tests {
if tt.integrationTest != runIntegrationTests { if tt.integrationTest != runIntegrationTests {
@ -680,11 +700,14 @@ func TestDefaultApiService_CreateComment(t *testing.T) {
a := &DefaultApiService{ a := &DefaultApiService{
client: tt.fields.client, client: tt.fields.client,
} }
got, err := a.CreateComment(tt.args.projectKey, tt.args.repositorySlug, tt.args.commitId, tt.args.localVarOptionals) got, err := a.CreateComment(tt.args.projectKey, tt.args.repositorySlug, tt.args.commitId, tt.args.comment, tt.args.localVarOptionals)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("DefaultApiService.CreateComment() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("DefaultApiService.CreateComment() error = %v, wantErr %v", err, tt.wantErr)
return return
} }
if got != nil {
got.Response = nil
}
if !reflect.DeepEqual(got, tt.want) { if !reflect.DeepEqual(got, tt.want) {
t.Errorf("DefaultApiService.CreateComment() = %v, want %v", got, tt.want) t.Errorf("DefaultApiService.CreateComment() = %v, want %v", got, tt.want)
} }