Skip to content

Commit 412cc33

Browse files
authored
Merge pull request #58 from syndicut/create-comment-and-activities
Fix create comment and get activities methods
2 parents 15f2a16 + c08e635 commit 412cc33

File tree

5 files changed

+611
-8
lines changed

5 files changed

+611
-8
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ go:
66
- master
77
env:
88
- GO111MODULE=on
9+
GOLANGCI_LINT_VERSION=1.35.2
910

1011
services:
1112
- docker
@@ -20,6 +21,6 @@ script:
2021
- go test -coverprofile=coverage.txt -covermode=atomic
2122
- INTEGRATION=TRUE go test
2223
- go build -v ./
23-
- if [[ "$(go version)" =~ "go version go1.11" ]]; then exit 0; else go get -u github.com/golangci/golangci-lint/cmd/golangci-lint && golangci-lint run -v; fi
24+
- if [[ "$(go version)" =~ "go version go1.11" ]]; then exit 0; else curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin "v${GOLANGCI_LINT_VERSION}" && golangci-lint run -v; fi
2425
after_success:
2526
- bash <(curl -s https://codecov.io/bash)

api_response.go

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,112 @@ type SearchQuery struct {
406406
Limits Limits `json:"limits"`
407407
}
408408

409+
type Parent struct {
410+
ID int `json:"id"`
411+
}
412+
413+
type DiffType string
414+
415+
const (
416+
DiffTypeEffective DiffType = "EFFECTIVE"
417+
DiffTypeCommit DiffType = "COMMIT"
418+
DiffTypeRange DiffType = "RANGE"
419+
)
420+
421+
type LineType string
422+
423+
const (
424+
LineTypeAdded LineType = "ADDED"
425+
LineTypeRemoved LineType = "REMOVED"
426+
LineTypeContext LineType = "CONTEXT"
427+
)
428+
429+
type FileType string
430+
431+
const (
432+
FileTypeFrom FileType = "FROM"
433+
FileTypeTo FileType = "TO"
434+
)
435+
436+
type Anchor struct {
437+
DiffType DiffType `json:"diffType,omitempty"`
438+
Line int `json:"line,omitempty"`
439+
LineType LineType `json:"lineType,omitempty"`
440+
FileType FileType `json:"fileType,omitempty"`
441+
FromHash string `json:"fromHash,omitempty"`
442+
Path string `json:"path,omitempty"`
443+
SrcPath string `json:"srcPath,omitempty"`
444+
ToHash string `json:"toHash,omitempty"`
445+
}
446+
447+
type Comment struct {
448+
Text string `json:"text"`
449+
Parent *Parent `json:"parent,omitempty"`
450+
Anchor *Anchor `json:"anchor,omitempty"`
451+
}
452+
453+
type Properties struct {
454+
Key string `json:"key"`
455+
}
456+
457+
type PermittedOperations struct {
458+
Editable bool `json:"editable"`
459+
Deletable bool `json:"deletable"`
460+
}
461+
462+
type ActivityComment struct {
463+
Properties Properties `json:"properties"`
464+
ID int `json:"id"`
465+
Version int `json:"version"`
466+
Text string `json:"text"`
467+
Author User `json:"author"`
468+
CreatedDate int64 `json:"createdDate"`
469+
UpdatedDate int64 `json:"updatedDate"`
470+
Comments []ActivityComment `json:"comments"`
471+
PermittedOperations PermittedOperations `json:"permittedOperations"`
472+
}
473+
474+
type CommitsStats struct {
475+
Commits []Commit `json:"commits"`
476+
Total int `json:"total"`
477+
}
478+
479+
type Action string
480+
481+
const (
482+
ActionCommented Action = "COMMENTED"
483+
ActionRescoped Action = "RESCOPED"
484+
ActionMerged Action = "MERGED"
485+
ActionApproved Action = "APPROVED"
486+
ActionDeclined Action = "DECLINED"
487+
ActionOpened Action = "OPENED"
488+
)
489+
490+
type Activity struct {
491+
ID int `json:"id"`
492+
CreatedDate int `json:"createdDate"`
493+
User User `json:"user"`
494+
Action Action `json:"action"`
495+
CommentAction string `json:"commentAction"`
496+
Comment ActivityComment `json:"comment"`
497+
CommentAnchor Anchor `json:"commentAnchor"`
498+
FromHash string `json:"fromHash,omitempty"`
499+
PreviousFromHash string `json:"previousFromHash,omitempty"`
500+
PreviousToHash string `json:"previousToHash,omitempty"`
501+
ToHash string `json:"toHash,omitempty"`
502+
Added CommitsStats `json:"added"`
503+
Removed CommitsStats `json:"removed"`
504+
}
505+
506+
type Activities struct {
507+
NextPageStart int `json:"nextPageStart"`
508+
IsLastPage bool `json:"isLastPage"`
509+
Limit int `json:"limit"`
510+
Size int `json:"size"`
511+
Start int `json:"start"`
512+
Values []Activity `json:"values"`
513+
}
514+
409515
// String converts global permission to its string representation
410516
func (p PermissionGlobal) String() string {
411517
return string(p)
@@ -546,6 +652,13 @@ func GetSearchResultResponse(r *APIResponse) (SearchResult, error) {
546652
return h, err
547653
}
548654

655+
// GetActivitiesResponse cast Activities results into structure
656+
func GetActivitiesResponse(r *APIResponse) (Activities, error) {
657+
var h Activities
658+
err := json.Unmarshal(r.Payload, &h)
659+
return h, err
660+
}
661+
549662
// NewAPIResponse create new APIResponse from http.Response
550663
func NewAPIResponse(r *http.Response) *APIResponse {
551664

0 commit comments

Comments
 (0)