Commit 8baead57 authored by Pablo Carranza's avatar Pablo Carranza 🦄

List oncall people moved to a oncall function

parent 64431113
Pipeline #13311381 passed with stage
in 50 seconds
......@@ -7,6 +7,19 @@ import (
pagerduty "github.com/PagerDuty/go-pagerduty"
)
// ListOncallPeople returns a list of the people that is going to be oncall for the next X days
func ListOncallPeople(c *Config, days int) ([]pagerduty.OnCall, error) {
client := pagerduty.NewClient(c.PDToken)
resp, err := client.ListOnCalls(pagerduty.ListOnCallOptions{
ScheduleIDs: []string{c.OncallPriID, c.OncallSecID},
Until: fmt.Sprintf("%sT16:00:00Z", time.Now().Add(24*time.Duration(days)*time.Hour).Format("2006-01-02")),
})
if err != nil {
return nil, fmt.Errorf("could not list oncall people for the next week: %s", err)
}
return resp.OnCalls, nil
}
// GetOncallPerson returns the person who happens to be on call
func GetOncallPerson(c *Config, shift string, period string) (string, error) {
// if we ask for current oncall period, there is no offset to apply.
......
......@@ -5,8 +5,6 @@ import (
"os"
"testing"
"time"
"github.com/PagerDuty/go-pagerduty"
)
func TestOncallDates(t *testing.T) {
......@@ -50,15 +48,17 @@ func TestOncallDates(t *testing.T) {
}
func TestPagerDutyStuff(t *testing.T) {
APIKey := os.Getenv("PD_API_KEY")
PrimaryOnCall := "PQ9W7ID"
SecondaryOnCall := "P23P5AE"
client := pagerduty.NewClient(APIKey)
resp, _ := client.ListOnCalls(pagerduty.ListOnCallOptions{
ScheduleIDs: []string{PrimaryOnCall, SecondaryOnCall},
Until: fmt.Sprintf("%sT16:00:00Z", time.Now().Add(24*7*time.Hour).Format("2006-01-02")),
})
for _, o := range resp.OnCalls {
fmt.Printf("On Call Now: %+v\n", o)
c := &Config{
PDToken: os.Getenv("PD_API_KEY"),
OncallPriID: os.Getenv("PD_PRIMARY_SCHEDULE"),
OncallSecID: os.Getenv("PD_SECONDARY_SCHEDULE"),
}
people, err := ListOncallPeople(c, 7)
if err != nil {
t.Fatalf("could not list the oncall people: %s", err)
}
for _, o := range people {
fmt.Printf("On Call from %s to %s for %s: %s\n", o.Start, o.End, o.Schedule.Summary, o.User.Summary)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment