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

Upgrade API dependencies #22

Merged
merged 1 commit into from
Sep 26, 2024
Merged
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
14 changes: 6 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@ module github.com/timoreimann/pdsync
go 1.23

require (
github.com/PagerDuty/go-pagerduty v1.1.2
github.com/google/go-cmp v0.5.4
github.com/PagerDuty/go-pagerduty v1.8.0
github.com/google/go-cmp v0.6.0
github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2
github.com/slack-go/slack v0.6.3
github.com/slack-go/slack v0.14.0
github.com/urfave/cli/v2 v2.1.1
gopkg.in/yaml.v2 v2.2.8
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/gorilla/websocket v1.2.0 // indirect
github.com/pkg/errors v0.8.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
)
45 changes: 14 additions & 31 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,56 +1,39 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/PagerDuty/go-pagerduty v1.1.2 h1:pTY5GKmmR88EeeI+9/LR+dKL2Chohz3L5yroqoUl+lQ=
github.com/PagerDuty/go-pagerduty v1.1.2/go.mod h1:ZKUzEnyuEMTCMwuzP5NyQIwPx+ThSKBNUva2/ns0Op8=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/PagerDuty/go-pagerduty v1.8.0 h1:MTFqTffIcAervB83U7Bx6HERzLbyaSPL/+oxH3zyluI=
github.com/PagerDuty/go-pagerduty v1.8.0/go.mod h1:nzIeAqyFSJAFkjWKvMzug0JtwDg+V+UoCWjFrfFH5mI=
github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927 h1:SKI1/fuSdodxmNNyVBR8d7X/HuLnRpvvFO0AgyQk764=
github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927/go.mod h1:h/aW8ynjgkuj+NQRlZcDbAbM1ORAbXjXX77sX7T289U=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/go-test/deep v1.0.4 h1:u2CU3YKy9I2pmu9pX0eq50wCgjfGIt539SqR7FbHiho=
github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/gorilla/websocket v1.2.0 h1:VJtLvh6VQym50czpZzx07z/kw9EgAxI3x1ZB8taTMQQ=
github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2 h1:JAEbJn3j/FrhdWA9jW8B5ajsLIjeuEHLi8xE4fk997o=
github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2/go.mod h1:0KeJpeMD6o+O4hW7qJOT7vyQPKrWmj26uf5wMc/IiIs=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/nlopes/slack v0.6.0/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk=
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/slack-go/slack v0.6.3 h1:qU037g8gQ71EuH6S9zYKnvYrEUj0fLFH4HFekFqBoRU=
github.com/slack-go/slack v0.6.3/go.mod h1:HE4RwNe7YpOg/F0vqo5PwXH3Hki31TplTvKRW9dGGaw=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/slack-go/slack v0.14.0 h1:6c0UTfbRnvRssZUsZ2qe0Iu07VAMPjRqOa6oX8ewF4k=
github.com/slack-go/slack v0.14.0/go.mod h1:hlGi5oXA+Gt+yWTPP0plCdRKmjsDxecdHxYQdlMQKOw=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/urfave/cli/v2 v2.1.1 h1:Qt8FeAtxE/vfdrLmR3rxR6JRE0RoVmbXu8+6kZtYU4k=
github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
27 changes: 14 additions & 13 deletions pagerduty.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"errors"
"fmt"
"net/http"
Expand Down Expand Up @@ -49,24 +50,24 @@ func newPagerDutyClient(token string) *pagerDutyClient {
}
}

func (cl *pagerDutyClient) getSchedule(id, name string) (*pdSchedule, error) {
func (cl *pagerDutyClient) getSchedule(ctx context.Context, id, name string) (*pdSchedule, error) {
if id != "" {
schedule, err := cl.getScheduleByID(id)
schedule, err := cl.getScheduleByID(ctx, id)
if err != nil {
return nil, fmt.Errorf("failed to get schedule by ID: %s", err)
}
return schedule, nil
}

schedule, err := cl.getScheduleByName(name)
schedule, err := cl.getScheduleByName(ctx, name)
if err != nil {
return nil, fmt.Errorf("failed to get schedules by name: %s", err)
}

return schedule, nil
}

func (cl *pagerDutyClient) getScheduleByID(scheduleID string) (*pdSchedule, error) {
func (cl *pagerDutyClient) getScheduleByID(ctx context.Context, scheduleID string) (*pdSchedule, error) {
if scheduleID == "" {
return nil, errors.New("schedule ID is missing")
}
Expand All @@ -75,7 +76,7 @@ func (cl *pagerDutyClient) getScheduleByID(scheduleID string) (*pdSchedule, erro
var schedule *pagerduty.Schedule
rErr := retryOnPagerDutyRateLimit(func() error {
var err error
schedule, err = cl.GetSchedule(scheduleID, pagerduty.GetScheduleOptions{})
schedule, err = cl.GetScheduleWithContext(ctx, scheduleID, pagerduty.GetScheduleOptions{})
return err
})
if rErr != nil {
Expand All @@ -92,14 +93,14 @@ func (cl *pagerDutyClient) getScheduleByID(scheduleID string) (*pdSchedule, erro
}, nil
}

func (cl *pagerDutyClient) getScheduleByName(scheduleName string) (*pdSchedule, error) {
func (cl *pagerDutyClient) getScheduleByName(ctx context.Context, scheduleName string) (*pdSchedule, error) {
if scheduleName == "" {
return nil, errors.New("schedule name is missing")
}

var err error
cl.pdSchedulesByNameOnce.Do(func() {
cl.pdSchedulesByName, err = cl.getAllSchedulesByName()
cl.pdSchedulesByName, err = cl.getAllSchedulesByName(ctx)
})
if err != nil {
return nil, fmt.Errorf("failed to get all schedules by name: %s", err)
Expand All @@ -113,9 +114,9 @@ func (cl *pagerDutyClient) getScheduleByName(scheduleName string) (*pdSchedule,
return &pdSchedule, nil
}

func (cl *pagerDutyClient) getAllSchedulesByName() (map[string]pdSchedule, error) {
func (cl *pagerDutyClient) getAllSchedulesByName(ctx context.Context) (map[string]pdSchedule, error) {
pdSchedules := map[string]pdSchedule{}
alo := pagerduty.APIListObject{
opts := pagerduty.ListSchedulesOptions{
Limit: 100,
}
fmt.Println("Collecting schedules")
Expand All @@ -124,7 +125,7 @@ func (cl *pagerDutyClient) getAllSchedulesByName() (map[string]pdSchedule, error
var schedulesResp *pagerduty.ListSchedulesResponse
rErr := retryOnPagerDutyRateLimit(func() error {
var err error
schedulesResp, err = cl.ListSchedules(pagerduty.ListSchedulesOptions{APIListObject: alo})
schedulesResp, err = cl.ListSchedulesWithContext(ctx, opts)
return err
})
if rErr != nil {
Expand All @@ -141,16 +142,16 @@ func (cl *pagerDutyClient) getAllSchedulesByName() (map[string]pdSchedule, error
if !schedulesResp.APIListObject.More {
break
}
alo.Offset = alo.Offset + alo.Limit
opts.Offset = opts.Offset + opts.Limit
}

return pdSchedules, nil
}

func (cl *pagerDutyClient) getOnCallUser(schedule pdSchedule) (pagerduty.User, error) {
func (cl *pagerDutyClient) getOnCallUser(ctx context.Context, schedule pdSchedule) (pagerduty.User, error) {
now := time.Now()
fmt.Printf("Getting on-call users for schedule %s\n", schedule)
onCallUsers, err := cl.ListOnCallUsers(schedule.id, pagerduty.ListOnCallUsersOptions{
onCallUsers, err := cl.ListOnCallUsersWithContext(ctx, schedule.id, pagerduty.ListOnCallUsersOptions{
Since: now.Add(-1 * time.Second).Format(time.RFC3339),
Until: now.Format(time.RFC3339),
})
Expand Down
7 changes: 5 additions & 2 deletions slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (metaClient *slackMetaClient) getChannels(ctx context.Context) (channelList
var err error
channels, nextCursor, err = metaClient.slackClient.GetConversationsContext(ctx, &slack.GetConversationsParameters{
Cursor: cursor,
ExcludeArchived: "true",
ExcludeArchived: true,
Limit: 200,
Types: metaClient.channelTypes,
})
Expand All @@ -136,7 +136,10 @@ func (metaClient *slackMetaClient) getChannels(ctx context.Context) (channelList
}

func (metaClient *slackMetaClient) getChannelByID(ctx context.Context, id string) (*slack.Channel, error) {
return metaClient.slackClient.GetConversationInfoContext(ctx, id, false)
return metaClient.slackClient.GetConversationInfoContext(ctx, &slack.GetConversationInfoInput{
ChannelID: id,
IncludeLocale: true,
})
}

func (metaClient *slackMetaClient) getUserGroups(ctx context.Context) ([]UserGroup, error) {
Expand Down
4 changes: 2 additions & 2 deletions syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (sp syncerParams) createSlackSyncs(ctx context.Context, cfg config) ([]runS
pdSchedules := pdSchedules{}
fmt.Printf("Slack sync %s: Getting PagerDuty schedules\n", slSync.name)
for _, schedule := range cfgSlSync.Schedules {
pdSchedule, err := sp.pdClient.getSchedule(schedule.ID, schedule.Name)
pdSchedule, err := sp.pdClient.getSchedule(ctx, schedule.ID, schedule.Name)
if err != nil {
return nil, fmt.Errorf("failed to create slack sync %q: failed to get schedule %s: %s", slSync.name, schedule, err)
}
Expand Down Expand Up @@ -146,7 +146,7 @@ func (s *syncer) runSlackSync(ctx context.Context, slackSync runSlackSync) error
slackUserIDByScheduleName := map[string]string{}
for _, schedule := range slackSync.pdSchedules {
fmt.Printf("Processing schedule %s\n", schedule)
onCallUser, err := s.pdClient.getOnCallUser(schedule)
onCallUser, err := s.pdClient.getOnCallUser(ctx, schedule)
if err != nil {
return fmt.Errorf("failed to get on call user for schedule %q: %s", schedule.name, err)
}
Expand Down
5 changes: 5 additions & 0 deletions vendor/github.com/PagerDuty/go-pagerduty/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading