Skip to content

Commit 828ff25

Browse files
committed
Upgrade API dependencies
Move away from deprecated PagerDuty API calls in favor of those supporting context.Context as well.
1 parent cae2878 commit 828ff25

File tree

183 files changed

+12676
-4463
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

183 files changed

+12676
-4463
lines changed

go.mod

+6-8
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,19 @@ module github.com/timoreimann/pdsync
33
go 1.23
44

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

1414
require (
1515
github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927 // indirect
1616
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
17-
github.com/google/go-querystring v1.0.0 // indirect
18-
github.com/gorilla/websocket v1.2.0 // indirect
19-
github.com/pkg/errors v0.8.0 // indirect
17+
github.com/google/go-querystring v1.1.0 // indirect
18+
github.com/gorilla/websocket v1.4.2 // indirect
2019
github.com/russross/blackfriday/v2 v2.0.1 // indirect
2120
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
22-
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
2321
)

go.sum

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

pagerduty.go

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"context"
45
"errors"
56
"fmt"
67
"net/http"
@@ -49,24 +50,24 @@ func newPagerDutyClient(token string) *pagerDutyClient {
4950
}
5051
}
5152

52-
func (cl *pagerDutyClient) getSchedule(id, name string) (*pdSchedule, error) {
53+
func (cl *pagerDutyClient) getSchedule(ctx context.Context, id, name string) (*pdSchedule, error) {
5354
if id != "" {
54-
schedule, err := cl.getScheduleByID(id)
55+
schedule, err := cl.getScheduleByID(ctx, id)
5556
if err != nil {
5657
return nil, fmt.Errorf("failed to get schedule by ID: %s", err)
5758
}
5859
return schedule, nil
5960
}
6061

61-
schedule, err := cl.getScheduleByName(name)
62+
schedule, err := cl.getScheduleByName(ctx, name)
6263
if err != nil {
6364
return nil, fmt.Errorf("failed to get schedules by name: %s", err)
6465
}
6566

6667
return schedule, nil
6768
}
6869

69-
func (cl *pagerDutyClient) getScheduleByID(scheduleID string) (*pdSchedule, error) {
70+
func (cl *pagerDutyClient) getScheduleByID(ctx context.Context, scheduleID string) (*pdSchedule, error) {
7071
if scheduleID == "" {
7172
return nil, errors.New("schedule ID is missing")
7273
}
@@ -75,7 +76,7 @@ func (cl *pagerDutyClient) getScheduleByID(scheduleID string) (*pdSchedule, erro
7576
var schedule *pagerduty.Schedule
7677
rErr := retryOnPagerDutyRateLimit(func() error {
7778
var err error
78-
schedule, err = cl.GetSchedule(scheduleID, pagerduty.GetScheduleOptions{})
79+
schedule, err = cl.GetScheduleWithContext(ctx, scheduleID, pagerduty.GetScheduleOptions{})
7980
return err
8081
})
8182
if rErr != nil {
@@ -92,14 +93,14 @@ func (cl *pagerDutyClient) getScheduleByID(scheduleID string) (*pdSchedule, erro
9293
}, nil
9394
}
9495

95-
func (cl *pagerDutyClient) getScheduleByName(scheduleName string) (*pdSchedule, error) {
96+
func (cl *pagerDutyClient) getScheduleByName(ctx context.Context, scheduleName string) (*pdSchedule, error) {
9697
if scheduleName == "" {
9798
return nil, errors.New("schedule name is missing")
9899
}
99100

100101
var err error
101102
cl.pdSchedulesByNameOnce.Do(func() {
102-
cl.pdSchedulesByName, err = cl.getAllSchedulesByName()
103+
cl.pdSchedulesByName, err = cl.getAllSchedulesByName(ctx)
103104
})
104105
if err != nil {
105106
return nil, fmt.Errorf("failed to get all schedules by name: %s", err)
@@ -113,9 +114,9 @@ func (cl *pagerDutyClient) getScheduleByName(scheduleName string) (*pdSchedule,
113114
return &pdSchedule, nil
114115
}
115116

116-
func (cl *pagerDutyClient) getAllSchedulesByName() (map[string]pdSchedule, error) {
117+
func (cl *pagerDutyClient) getAllSchedulesByName(ctx context.Context) (map[string]pdSchedule, error) {
117118
pdSchedules := map[string]pdSchedule{}
118-
alo := pagerduty.APIListObject{
119+
opts := pagerduty.ListSchedulesOptions{
119120
Limit: 100,
120121
}
121122
fmt.Println("Collecting schedules")
@@ -124,7 +125,7 @@ func (cl *pagerDutyClient) getAllSchedulesByName() (map[string]pdSchedule, error
124125
var schedulesResp *pagerduty.ListSchedulesResponse
125126
rErr := retryOnPagerDutyRateLimit(func() error {
126127
var err error
127-
schedulesResp, err = cl.ListSchedules(pagerduty.ListSchedulesOptions{APIListObject: alo})
128+
schedulesResp, err = cl.ListSchedulesWithContext(ctx, opts)
128129
return err
129130
})
130131
if rErr != nil {
@@ -141,16 +142,16 @@ func (cl *pagerDutyClient) getAllSchedulesByName() (map[string]pdSchedule, error
141142
if !schedulesResp.APIListObject.More {
142143
break
143144
}
144-
alo.Offset = alo.Offset + alo.Limit
145+
opts.Offset = opts.Offset + opts.Limit
145146
}
146147

147148
return pdSchedules, nil
148149
}
149150

150-
func (cl *pagerDutyClient) getOnCallUser(schedule pdSchedule) (pagerduty.User, error) {
151+
func (cl *pagerDutyClient) getOnCallUser(ctx context.Context, schedule pdSchedule) (pagerduty.User, error) {
151152
now := time.Now()
152153
fmt.Printf("Getting on-call users for schedule %s\n", schedule)
153-
onCallUsers, err := cl.ListOnCallUsers(schedule.id, pagerduty.ListOnCallUsersOptions{
154+
onCallUsers, err := cl.ListOnCallUsersWithContext(ctx, schedule.id, pagerduty.ListOnCallUsersOptions{
154155
Since: now.Add(-1 * time.Second).Format(time.RFC3339),
155156
Until: now.Format(time.RFC3339),
156157
})

slack.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (metaClient *slackMetaClient) getChannels(ctx context.Context) (channelList
112112
var err error
113113
channels, nextCursor, err = metaClient.slackClient.GetConversationsContext(ctx, &slack.GetConversationsParameters{
114114
Cursor: cursor,
115-
ExcludeArchived: "true",
115+
ExcludeArchived: true,
116116
Limit: 200,
117117
Types: metaClient.channelTypes,
118118
})
@@ -136,7 +136,10 @@ func (metaClient *slackMetaClient) getChannels(ctx context.Context) (channelList
136136
}
137137

138138
func (metaClient *slackMetaClient) getChannelByID(ctx context.Context, id string) (*slack.Channel, error) {
139-
return metaClient.slackClient.GetConversationInfoContext(ctx, id, false)
139+
return metaClient.slackClient.GetConversationInfoContext(ctx, &slack.GetConversationInfoInput{
140+
ChannelID: id,
141+
IncludeLocale: true,
142+
})
140143
}
141144

142145
func (metaClient *slackMetaClient) getUserGroups(ctx context.Context) ([]UserGroup, error) {

syncer.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (sp syncerParams) createSlackSyncs(ctx context.Context, cfg config) ([]runS
6464
pdSchedules := pdSchedules{}
6565
fmt.Printf("Slack sync %s: Getting PagerDuty schedules\n", slSync.name)
6666
for _, schedule := range cfgSlSync.Schedules {
67-
pdSchedule, err := sp.pdClient.getSchedule(schedule.ID, schedule.Name)
67+
pdSchedule, err := sp.pdClient.getSchedule(ctx, schedule.ID, schedule.Name)
6868
if err != nil {
6969
return nil, fmt.Errorf("failed to create slack sync %q: failed to get schedule %s: %s", slSync.name, schedule, err)
7070
}
@@ -146,7 +146,7 @@ func (s *syncer) runSlackSync(ctx context.Context, slackSync runSlackSync) error
146146
slackUserIDByScheduleName := map[string]string{}
147147
for _, schedule := range slackSync.pdSchedules {
148148
fmt.Printf("Processing schedule %s\n", schedule)
149-
onCallUser, err := s.pdClient.getOnCallUser(schedule)
149+
onCallUser, err := s.pdClient.getOnCallUser(ctx, schedule)
150150
if err != nil {
151151
return fmt.Errorf("failed to get on call user for schedule %q: %s", schedule.name, err)
152152
}

vendor/github.com/PagerDuty/go-pagerduty/.gitignore

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)