Skip to content

Commit

Permalink
Fix on-call user detection
Browse files Browse the repository at this point in the history
  • Loading branch information
rorymalcolm committed Sep 13, 2024
1 parent d6ce539 commit a7cc983
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
6 changes: 4 additions & 2 deletions integrations/access/incidentio/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ func (a *App) run(ctx context.Context) error {
},
a.onWatcherEvent,
)
log.Info("Starting watcher job")

if err != nil {
return trace.Wrap(err)
}
Expand Down Expand Up @@ -450,7 +452,7 @@ func (a *App) tryApproveRequest(ctx context.Context, req types.AccessRequest) er
if err != nil {
return trace.Wrap(err)
}
for _, shift := range respondersResult.CurrentShifts {
for _, shift := range respondersResult.Schedule.CurrentShifts {
if shift.User != nil {
onCallUsers = append(onCallUsers, shift.User.Email)
}
Expand Down Expand Up @@ -517,7 +519,7 @@ func (a *App) resolveAlert(ctx context.Context, reqID string, resolution Resolut
return trace.Wrap(err)
}
if !ok {
logger.Get(ctx).Debug("Failed to resolve the alert: plugin data is missing")
logger.Get(ctx).Debugf("Failed to resolve the alert: plugin data is missing")
return nil
}

Expand Down
10 changes: 5 additions & 5 deletions integrations/access/incidentio/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,19 @@ func (inc AlertClient) ResolveAlert(ctx context.Context, alertID string, resolut
}

// GetOnCall returns the list of responders on-call for a schedule.
func (inc APIClient) GetOnCall(ctx context.Context, scheduleID string) (ScheduleResult, error) {
var result ScheduleResult
func (inc APIClient) GetOnCall(ctx context.Context, scheduleID string) (GetScheduleResponse, error) {
var result GetScheduleResponse
resp, err := inc.client.NewRequest().
SetContext(ctx).
SetPathParams(map[string]string{"scheduleID": scheduleID}).
SetResult(&result).
Get("v2/schedules/{scheduleID}")
Get("/v2/schedules/{scheduleID}")
if err != nil {
return ScheduleResult{}, trace.Wrap(err)
return GetScheduleResponse{}, trace.Wrap(err)
}
defer resp.RawResponse.Body.Close()
if resp.IsError() {
return ScheduleResult{}, errWrapper(resp.StatusCode(), string(resp.Body()))
return GetScheduleResponse{}, errWrapper(resp.StatusCode(), string(resp.Body()))
}
return result, nil
}
Expand Down
4 changes: 4 additions & 0 deletions integrations/access/incidentio/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ type AlertBody struct {
Metadata map[string]string `json:"metadata,omitempty"`
}

type GetScheduleResponse struct {
Schedule ScheduleResult `json:"schedule"`
}

type ScheduleResult struct {
Annotations map[string]string `json:"annotations"`
Config ScheduleConfig `json:"config"`
Expand Down

0 comments on commit a7cc983

Please sign in to comment.