Skip to content

Commit

Permalink
Update to new API
Browse files Browse the repository at this point in the history
  • Loading branch information
dz0ny committed Apr 17, 2023
1 parent 1f0f4ae commit 8fac0e8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 6 additions & 4 deletions cron/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cron

import (
"fmt"
"net/url"
"os"

"github.com/imroc/req"
Expand All @@ -21,7 +22,8 @@ func (c *Cron) header() req.Header {
}

func (c *Cron) url(verb string) string {
return fmt.Sprintf("https://sentry.io/api/0/organizations/%s/monitors/%s/%s/", c.Team, c.Monitor, verb)
s, _ := url.JoinPath("https://sentry.io/api/0/organizations/", c.Team, "monitors", c.Monitor, verb)
return s
}

func NewMonitor(team, monitor string) Cron {
Expand All @@ -35,18 +37,18 @@ func NewMonitor(team, monitor string) Cron {
}

func (m *Cron) Start() error {
_, err := req.Post(m.url("checkins"), m.header(), started.json())
_, err := req.Post(m.url("/checkins/"), m.header(), started.json())
return err
}

func (m *Cron) Stop() error {

// handle crash
if err := recover(); err != nil {
req.Put(m.url("latest"), m.header(), errored.json())
req.Put(m.url("/checkins/latest"), m.header(), errored.json())
return nil
}

_, err := req.Put(m.url("latest"), m.header(), finished.json())
_, err := req.Put(m.url("/checkins/latest"), m.header(), finished.json())
return err
}
5 changes: 2 additions & 3 deletions cron/cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ func TestCron_url(t *testing.T) {
verb string
want string
}{
{"started", Cron{"team", "dsn", "monitor"}, "checkins", "https://sentry.io/api/0/organizations/team/monitors/monitor/checkins/"},
{"ok", Cron{"team", "dsn", "monitor"}, "latest", "https://sentry.io/api/0/organizations/team/monitors/monitor/latest/"},
{"errored", Cron{"team", "dsn", "monitor"}, "latest", "https://sentry.io/api/0/organizations/team/monitors/monitor/latest/"},
{"started", Cron{"team", "dsn", "monitor"}, "/checkins/", "https://sentry.io/api/0/organizations/team/monitors/monitor/checkins/"},
{"ok", Cron{"team", "dsn", "monitor"}, "/checkins/latest/", "https://sentry.io/api/0/organizations/team/monitors/monitor/checkins/latest/"},
}

for _, tt := range tests {
Expand Down

0 comments on commit 8fac0e8

Please sign in to comment.