Skip to content

Commit f58379a

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 561361b + 953bcb9 commit f58379a

File tree

8 files changed

+88
-37
lines changed

8 files changed

+88
-37
lines changed

client.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"io"
1010
"io/ioutil"
1111
"net/http"
12+
"strings"
1213
"time"
1314
)
1415

@@ -124,7 +125,12 @@ func (c *Client) newRequest(method, endpoint string, in interface{}) (*http.Requ
124125
bodyreader = newbodyreader
125126
}
126127

127-
req, err := http.NewRequest(method, c.Endpoint+endpoint+"/", bodyreader)
128+
finalEndpoint := c.Endpoint + endpoint
129+
if !strings.HasSuffix(endpoint, "/") {
130+
finalEndpoint = finalEndpoint + "/"
131+
}
132+
133+
req, err := http.NewRequest(method, finalEndpoint, bodyreader)
128134
if err != nil {
129135
return nil, err
130136
}

client_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,19 @@ func TestClientKnownGoodEndpoint(t *testing.T) {
6262
t.Errorf("Endpoint is not https://sentry.io/api/0 got %s", bclient.Endpoint)
6363
}
6464
}
65+
66+
func TestNewRequestWillNotAddExtraTrailingSlashToEndpoint(t *testing.T) {
67+
endpoint := "some-endpoint/"
68+
bclient, berr := NewClient("testauthclient", nil, nil)
69+
if berr != nil {
70+
t.Error(berr)
71+
}
72+
req, err := bclient.newRequest("get", endpoint, nil)
73+
if req == nil || err != nil {
74+
t.Errorf("can't generate request: %v", err)
75+
}
76+
77+
if req.URL.String() != "https://sentry.io/api/0/some-endpoint/" {
78+
t.Errorf("Endpoint is not https://sentry.io/api/0/some-endpoint/ got %s", req.URL.String())
79+
}
80+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.13
44

55
require (
66
github.com/certifi/gocertifi v0.0.0-20200104152315-a6d78f326758 // indirect
7-
github.com/getsentry/raven-go v0.2.0
7+
github.com/getsentry/raven-go v0.2.0 // indirect
88
github.com/getsentry/sentry-go v0.4.0
99
github.com/pkg/errors v0.9.1 // indirect
1010
)

issue.go

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type Status string
2727
// IssueStats is the stats of a issue
2828
type IssueStats struct {
2929
TwentyFourHour *[]Stat `json:"24h,omitempty"`
30+
FourteenDays *[]Stat `json:"14d,omitempty"`
3031
ThirtyDays *[]Stat `json:"30d,omitempty"`
3132
}
3233

@@ -81,35 +82,35 @@ type Activity struct {
8182

8283
// Issue returns a issue found in sentry
8384
type Issue struct {
84-
Annotations *[]string `json:"annotations,omitempty"`
85-
AssignedTo *InternalUser `json:"assignedTo,omitempty"`
86-
Activity *[]Activity `json:"activity,omitempty"`
87-
Count *string `json:"count,omitempty"`
88-
Culprit *string `json:"culprit,omitempty"`
89-
FirstSeen *time.Time `json:"firstSeen,omitempty"`
90-
HasSeen *bool `json:"hasSeen,omitempty"`
91-
ID *string `json:"id,omitempty"`
92-
IsBookmarked *bool `json:"isBookmarked,omitempty"`
93-
IsPublic *bool `json:"isPublic,omitempty"`
94-
IsSubscribed *bool `json:"isSubscribed,omitempty"`
95-
LastSeen *time.Time `json:"lastSeen,omitempty"`
96-
Level *string `json:"level,omitempty"`
97-
Logger *string `json:"logger,omitempty"`
98-
Metadata *map[string]string `json:"metadata,omitempty"`
99-
NumComments *int `json:"numComments,omitempty"`
100-
Permalink *string `json:"permalink,omitempty"`
101-
Project *Project `json:"project,omitempty"`
102-
ShareID *string `json:"shareId,omitempty"`
103-
ShortID *string `json:"shortId,omitempty"`
104-
Stats *IssueStats `json:"stats,omitempty"`
105-
Status *Status `json:"status,omitempty"`
106-
StatusDetails *map[string]string `json:"statusDetails,omitempty"`
107-
SubscriptionDetails *map[string]string `json:"subscriptionDetails,omitempty"`
108-
Tags *[]IssueTag `json:"tags,omitempty"`
109-
Title *string `json:"title,omitempty"`
110-
Type *string `json:"type,omitempty"`
111-
UserCount *int `json:"userCount,omitempty"`
112-
UserReportCount *int `json:"userReportCount,omitempty"`
85+
Annotations *[]string `json:"annotations,omitempty"`
86+
AssignedTo *InternalUser `json:"assignedTo,omitempty"`
87+
Activity *[]Activity `json:"activity,omitempty"`
88+
Count *string `json:"count,omitempty"`
89+
Culprit *string `json:"culprit,omitempty"`
90+
FirstSeen *time.Time `json:"firstSeen,omitempty"`
91+
HasSeen *bool `json:"hasSeen,omitempty"`
92+
ID *string `json:"id,omitempty"`
93+
IsBookmarked *bool `json:"isBookmarked,omitempty"`
94+
IsPublic *bool `json:"isPublic,omitempty"`
95+
IsSubscribed *bool `json:"isSubscribed,omitempty"`
96+
LastSeen *time.Time `json:"lastSeen,omitempty"`
97+
Level *string `json:"level,omitempty"`
98+
Logger *string `json:"logger,omitempty"`
99+
Metadata *map[string]string `json:"metadata,omitempty"`
100+
NumComments *int `json:"numComments,omitempty"`
101+
Permalink *string `json:"permalink,omitempty"`
102+
Project *Project `json:"project,omitempty"`
103+
ShareID *string `json:"shareId,omitempty"`
104+
ShortID *string `json:"shortId,omitempty"`
105+
Stats *IssueStats `json:"stats,omitempty"`
106+
Status *Status `json:"status,omitempty"`
107+
StatusDetails *map[string]interface{} `json:"statusDetails,omitempty"`
108+
SubscriptionDetails *map[string]string `json:"subscriptionDetails,omitempty"`
109+
Tags *[]IssueTag `json:"tags,omitempty"`
110+
Title *string `json:"title,omitempty"`
111+
Type *string `json:"type,omitempty"`
112+
UserCount *int `json:"userCount,omitempty"`
113+
UserReportCount *int `json:"userReportCount,omitempty"`
113114
}
114115

115116
type issueQuery struct {

issue_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,22 @@ func TestIssueResource(t *testing.T) {
7272
t.Error("Should be no new results")
7373
}
7474

75+
t.Run("Get issues with statsPeriod of 14 days", func(t *testing.T) {
76+
period := "14d"
77+
issues, _, err := client.GetIssues(org, project, &period, nil, nil)
78+
if err != nil {
79+
t.Error(err)
80+
}
81+
if len(issues) <= 0 {
82+
t.Fatal("No issues found for this project")
83+
}
84+
for _, issue := range issues {
85+
if issue.Stats.FourteenDays == nil {
86+
t.Fatal("We should be able to get 14 days of stats for this issue but didn't")
87+
}
88+
}
89+
})
90+
7591
t.Run("Get hashes for issue", func(t *testing.T) {
7692
hashes, link, err := client.GetIssueHashes(issues[0])
7793
if err != nil {
@@ -111,6 +127,9 @@ func TestIssueResource(t *testing.T) {
111127

112128
resolved := Resolved
113129
firstIssue.Status = &resolved
130+
firstIssue.StatusDetails = &map[string]interface{}{
131+
"inNextRelease": true,
132+
}
114133

115134
if err := client.UpdateIssue(firstIssue); err != nil {
116135
t.Error(err)
@@ -120,6 +139,15 @@ func TestIssueResource(t *testing.T) {
120139
t.Error("Status did not get updated")
121140
}
122141

142+
details, ok := (*firstIssue.StatusDetails)["inNextRelease"].(bool)
143+
if !ok {
144+
t.Error("Status details did not get updated")
145+
}
146+
147+
if !details {
148+
t.Error("Status details did not get updated")
149+
}
150+
123151
t.Run("Delete the first issue in this project", func(t *testing.T) {
124152
err := client.DeleteIssue(firstIssue)
125153
if err != nil {

makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ devenv:
1919
docker run -d --name sentry-worker-1 -e SENTRY_SECRET_KEY='${STUPIDSECRET}' --link sentry-postgres:postgres --link sentry-redis:redis sentry:latest run worker
2020

2121
devclean:
22-
docker kill $$(docker ps -q)
23-
docker rm $$(docker ps -a -q)
22+
docker kill $$(docker ps -q -a --no-trunc --filter name=^sentry)
23+
docker rm $$(docker ps -q -a --no-trunc --filter name=^sentry)

project.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (c *Client) GetProjects() ([]Project, *Link, error) {
8181
// GetOrgProjects fetchs all projects belonging to a organization
8282
func (c *Client) GetOrgProjects(o Organization) ([]Project, *Link, error) {
8383
var proj []Project
84-
link, err := c.doWithPagination("GET", fmt.Sprintf("organizations/%s/projects/", *o.Slug), &proj, nil)
84+
link, err := c.doWithPagination("GET", fmt.Sprintf("organizations/%s/projects", *o.Slug), &proj, nil)
8585
return proj, link, err
8686
}
8787

stat.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ func (o *statRequest) ToQueryString() string {
2727
query.Add("stat", string(o.Stat))
2828
query.Add("since", strconv.FormatInt(o.Since, 10))
2929
query.Add("until", strconv.FormatInt(o.Until, 10))
30-
30+
3131
if o.Resolution != nil {
32-
query.Add("resolution", string(*o.Resolution))
32+
query.Add("resolution", string(*o.Resolution))
3333
}
34-
34+
3535
return query.Encode()
3636
}
3737

0 commit comments

Comments
 (0)