Skip to content
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

Adjust issue events endpoint #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion events.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type Event struct {
Size *int `json:"size,omitempty"`
Platform *string `json:"platform,omitempty"`
Type *string `json:"type,omitempty"`
Metadata *map[string]string `json:"metadata,omitempty"`
Metadata *map[string]interface{} `json:"metadata,omitempty"`
Tags *[]Tag `json:"tags,omitempty"`
DateCreated *time.Time `json:"dateCreated,omitempty"`
DateReceived *time.Time `json:"dateReceived,omitempty"`
Expand Down
23 changes: 21 additions & 2 deletions issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,19 @@ func (i *issueQuery) ToQueryString() string {
return query.Encode()
}

type issueEventQuery struct {
Full *bool
}

func (e *issueEventQuery) ToQueryString() string {
query := url.Values{}
if e.Full != nil {
query.Add("full", strconv.FormatBool(*e.Full))
}

return query.Encode()
}

//GetIssues will fetch all issues for organization and project
func (c *Client) GetIssues(o Organization, p Project, StatsPeriod *string, ShortIDLookup *bool, query *string) ([]Issue, *Link, error) {
var issues []Issue
Expand Down Expand Up @@ -185,9 +198,15 @@ func (c *Client) GetIssueTagValues(i Issue, tag IssueTag) ([]IssueTagValue, *Lin
}

//GetIssueEvents will fetch all events for a issue
func (c *Client) GetIssueEvents(i Issue) ([]Event, *Link, error) {
func (c *Client) GetIssueEvents(i Issue, full *bool) ([]Event, *Link, error) {
var events []Event
link, err := c.doWithPagination("GET", fmt.Sprintf("issues/%s/events", *i.ID), &events, nil)

issueEventFilter := &issueEventQuery{
Full: full,
}

link, err := c.doWithPaginationQuery(
"GET", fmt.Sprintf("issues/%s/events", *i.ID), &events, nil, issueEventFilter)
return events, link, err
}

Expand Down
13 changes: 12 additions & 1 deletion issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,18 @@ func TestIssueResource(t *testing.T) {
})

t.Run("Get events for this issue", func(t *testing.T) {
events, _, err := client.GetIssueEvents(issues[0])
events, _, err := client.GetIssueEvents(issues[0], nil)
if err != nil {
t.Error(err)
}
if len(events) == 0 {
t.Errorf("Should be at least more than 1 event %v", events)
}
})

t.Run("Get events for this issue with all details", func(t *testing.T) {
full := true
events, _, err := client.GetIssueEvents(issues[0], &full)
if err != nil {
t.Error(err)
}
Expand Down
2 changes: 1 addition & 1 deletion userfeedback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestUserFeedbackResource(t *testing.T) {

issue := issues[0]

events, _, _ := client.GetIssueEvents(issue)
events, _, _ := client.GetIssueEvents(issue, nil)
if len(events) == 0 {
t.Fatal("no events found")
}
Expand Down