Skip to content

Commit c8de9da

Browse files
Keon AminiStartrekzky
andauthored
fix: PagerDuty incident conversion query by service ID (#5281) (#5287)
--------- Co-authored-by: Louis.z <louis.s4372121@gmail.com>
1 parent 50207e9 commit c8de9da

File tree

5 files changed

+75
-285
lines changed

5 files changed

+75
-285
lines changed

backend/plugins/pagerduty/api/remote.go

Lines changed: 6 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ import (
2626
"github.com/apache/incubator-devlake/core/plugin"
2727
"github.com/apache/incubator-devlake/helpers/pluginhelper/api"
2828
"github.com/apache/incubator-devlake/plugins/pagerduty/models"
29+
"github.com/apache/incubator-devlake/plugins/pagerduty/models/raw"
2930
"net/http"
3031
"net/url"
3132
"strconv"
32-
"time"
3333
)
3434

3535
type RemoteScopesChild struct {
@@ -56,110 +56,16 @@ type PageData struct {
5656
PerPage int `json:"per_page"`
5757
}
5858

59-
type TeamResponse struct {
60-
Offset int `json:"offset"`
61-
Limit int `json:"limit"`
62-
More bool `json:"more"`
63-
Total int `json:"total"`
64-
Teams []struct {
65-
Id string `json:"id"`
66-
Name string `json:"name"`
67-
} `json:"teams"`
68-
}
69-
70-
type WorkspaceItem struct {
71-
//Type string `json:"type"`
72-
//Uuid string `json:"uuid"`
73-
Slug string `json:"slug"`
74-
Name string `json:"name"`
75-
}
76-
77-
type ReposResponse struct {
78-
Pagelen int `json:"pagelen"`
79-
Page int `json:"page"`
80-
Size int `json:"size"`
81-
Values []models.Service `json:"values"`
82-
}
83-
8459
type ServiceResponse struct {
85-
Offset int `json:"offset"`
86-
Limit int `json:"limit"`
87-
More bool `json:"more"`
88-
Total int `json:"total"`
89-
Services []struct {
90-
Id string `json:"id"`
91-
Summary string `json:"summary"`
92-
Type string `json:"type"`
93-
Self string `json:"self"`
94-
HtmlUrl string `json:"html_url"`
95-
Name string `json:"name"`
96-
AutoResolveTimeout int `json:"auto_resolve_timeout"`
97-
AcknowledgementTimeout int `json:"acknowledgement_timeout"`
98-
CreatedAt time.Time `json:"created_at"`
99-
Status string `json:"status"`
100-
AlertCreation string `json:"alert_creation"`
101-
AlertGroupingParameters struct {
102-
Type string `json:"type"`
103-
} `json:"alert_grouping_parameters"`
104-
Integrations []struct {
105-
Id string `json:"id"`
106-
Type string `json:"type"`
107-
Summary string `json:"summary"`
108-
Self string `json:"self"`
109-
HtmlUrl string `json:"html_url"`
110-
} `json:"integrations"`
111-
EscalationPolicy struct {
112-
Id string `json:"id"`
113-
Type string `json:"type"`
114-
Summary string `json:"summary"`
115-
Self string `json:"self"`
116-
HtmlUrl string `json:"html_url"`
117-
} `json:"escalation_policy"`
118-
Teams []struct {
119-
Id string `json:"id"`
120-
Type string `json:"type"`
121-
Summary string `json:"summary"`
122-
Self string `json:"self"`
123-
HtmlUrl string `json:"html_url"`
124-
} `json:"teams"`
125-
IncidentUrgencyRule struct {
126-
Type string `json:"type"`
127-
DuringSupportHours struct {
128-
Type string `json:"type"`
129-
Urgency string `json:"urgency"`
130-
} `json:"during_support_hours"`
131-
OutsideSupportHours struct {
132-
Type string `json:"type"`
133-
Urgency string `json:"urgency"`
134-
} `json:"outside_support_hours"`
135-
} `json:"incident_urgency_rule"`
136-
SupportHours struct {
137-
Type string `json:"type"`
138-
TimeZone string `json:"time_zone"`
139-
StartTime string `json:"start_time"`
140-
EndTime string `json:"end_time"`
141-
DaysOfWeek []int `json:"days_of_week"`
142-
} `json:"support_hours"`
143-
ScheduledActions []struct {
144-
Type string `json:"type"`
145-
At struct {
146-
Type string `json:"type"`
147-
Name string `json:"name"`
148-
} `json:"at"`
149-
ToUrgency string `json:"to_urgency"`
150-
} `json:"scheduled_actions"`
151-
AutoPauseNotificationsParameters struct {
152-
Enabled bool `json:"enabled"`
153-
Timeout int `json:"timeout"`
154-
} `json:"auto_pause_notifications_parameters"`
155-
}
60+
Offset int `json:"offset"`
61+
Limit int `json:"limit"`
62+
More bool `json:"more"`
63+
Total int `json:"total"`
64+
Services []raw.Service `json:"services"`
15665
}
15766

15867
const RemoteScopesPerPage int = 100
15968
const TypeScope string = "scope"
160-
const TypeGroup string = "group"
161-
162-
//const TypeGroup string = "group"
16369

16470
// RemoteScopes list all available scopes (services) for this connection
16571
// @Summary list all available scopes (services) for this connection

backend/plugins/pagerduty/models/raw/incidents.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package raw
1919

2020
import "time"
2121

22-
type Incidents struct {
22+
type Incident struct {
2323
// Acknowledgements corresponds to the JSON schema field "acknowledgements".
2424
Acknowledgements []IncidentsAcknowledgementsElem `json:"acknowledgements,omitempty"`
2525

backend/plugins/pagerduty/models/raw/services.go

Lines changed: 66 additions & 182 deletions
Original file line numberDiff line numberDiff line change
@@ -19,186 +19,70 @@ package raw
1919

2020
import "time"
2121

22-
type Services struct {
23-
// AcknowledgementTimeout corresponds to the JSON schema field
24-
// "acknowledgement_timeout".
25-
AcknowledgementTimeout *int `json:"acknowledgement_timeout,omitempty"`
26-
27-
// AlertCreation corresponds to the JSON schema field "alert_creation".
28-
AlertCreation *string `json:"alert_creation,omitempty"`
29-
30-
// AlertGrouping corresponds to the JSON schema field "alert_grouping".
31-
AlertGrouping *string `json:"alert_grouping,omitempty"`
32-
33-
// AlertGroupingTimeout corresponds to the JSON schema field
34-
// "alert_grouping_timeout".
35-
AlertGroupingTimeout *int `json:"alert_grouping_timeout,omitempty"`
36-
37-
// AutoResolveTimeout corresponds to the JSON schema field "auto_resolve_timeout".
38-
AutoResolveTimeout *int `json:"auto_resolve_timeout,omitempty"`
39-
40-
// CreatedAt corresponds to the JSON schema field "created_at".
41-
CreatedAt *time.Time `json:"created_at,omitempty"`
42-
43-
// Description corresponds to the JSON schema field "description".
44-
Description *string `json:"description,omitempty"`
45-
46-
// EscalationPolicy corresponds to the JSON schema field "escalation_policy".
47-
EscalationPolicy *ServicesEscalationPolicy `json:"escalation_policy,omitempty"`
48-
49-
// HtmlUrl corresponds to the JSON schema field "html_url".
50-
HtmlUrl *string `json:"html_url,omitempty"`
51-
52-
// Id corresponds to the JSON schema field "id".
53-
Id *string `json:"id,omitempty"`
54-
55-
// IncidentUrgencyRule corresponds to the JSON schema field
56-
// "incident_urgency_rule".
57-
IncidentUrgencyRule *ServicesIncidentUrgencyRule `json:"incident_urgency_rule,omitempty"`
58-
59-
// Integrations corresponds to the JSON schema field "integrations".
60-
Integrations []ServicesIntegrationsElem `json:"integrations,omitempty"`
61-
62-
// LastIncidentTimestamp corresponds to the JSON schema field
63-
// "last_incident_timestamp".
64-
LastIncidentTimestamp *time.Time `json:"last_incident_timestamp,omitempty"`
65-
66-
// Name corresponds to the JSON schema field "name".
67-
Name *string `json:"name,omitempty"`
68-
69-
// ScheduledActions corresponds to the JSON schema field "scheduled_actions".
70-
ScheduledActions []ServicesScheduledActionsElem `json:"scheduled_actions,omitempty"`
71-
72-
// Self corresponds to the JSON schema field "self".
73-
Self *string `json:"self,omitempty"`
74-
75-
// Status corresponds to the JSON schema field "status".
76-
Status *string `json:"status,omitempty"`
77-
78-
// Summary corresponds to the JSON schema field "summary".
79-
Summary *string `json:"summary,omitempty"`
80-
81-
// SupportHours corresponds to the JSON schema field "support_hours".
82-
SupportHours *ServicesSupportHours `json:"support_hours,omitempty"`
83-
84-
// Teams corresponds to the JSON schema field "teams".
85-
Teams []ServicesTeamsElem `json:"teams,omitempty"`
86-
87-
// Type corresponds to the JSON schema field "type".
88-
Type *string `json:"type,omitempty"`
89-
}
90-
91-
type ServicesEscalationPolicy struct {
92-
// HtmlUrl corresponds to the JSON schema field "html_url".
93-
HtmlUrl *string `json:"html_url,omitempty"`
94-
95-
// Id corresponds to the JSON schema field "id".
96-
Id *string `json:"id,omitempty"`
97-
98-
// Self corresponds to the JSON schema field "self".
99-
Self *string `json:"self,omitempty"`
100-
101-
// Summary corresponds to the JSON schema field "summary".
102-
Summary *string `json:"summary,omitempty"`
103-
104-
// Type corresponds to the JSON schema field "type".
105-
Type *string `json:"type,omitempty"`
106-
}
107-
108-
type ServicesIncidentUrgencyRule struct {
109-
// DuringSupportHours corresponds to the JSON schema field "during_support_hours".
110-
DuringSupportHours *ServicesIncidentUrgencyRuleDuringSupportHours `json:"during_support_hours,omitempty"`
111-
112-
// OutsideSupportHours corresponds to the JSON schema field
113-
// "outside_support_hours".
114-
OutsideSupportHours *ServicesIncidentUrgencyRuleOutsideSupportHours `json:"outside_support_hours,omitempty"`
115-
116-
// Type corresponds to the JSON schema field "type".
117-
Type *string `json:"type,omitempty"`
118-
}
119-
120-
type ServicesIncidentUrgencyRuleDuringSupportHours struct {
121-
// Type corresponds to the JSON schema field "type".
122-
Type *string `json:"type,omitempty"`
123-
124-
// Urgency corresponds to the JSON schema field "urgency".
125-
Urgency *string `json:"urgency,omitempty"`
126-
}
127-
128-
type ServicesIncidentUrgencyRuleOutsideSupportHours struct {
129-
// Type corresponds to the JSON schema field "type".
130-
Type *string `json:"type,omitempty"`
131-
132-
// Urgency corresponds to the JSON schema field "urgency".
133-
Urgency *string `json:"urgency,omitempty"`
134-
}
135-
136-
type ServicesIntegrationsElem struct {
137-
// HtmlUrl corresponds to the JSON schema field "html_url".
138-
HtmlUrl *string `json:"html_url,omitempty"`
139-
140-
// Id corresponds to the JSON schema field "id".
141-
Id *string `json:"id,omitempty"`
142-
143-
// Self corresponds to the JSON schema field "self".
144-
Self *string `json:"self,omitempty"`
145-
146-
// Summary corresponds to the JSON schema field "summary".
147-
Summary *string `json:"summary,omitempty"`
148-
149-
// Type corresponds to the JSON schema field "type".
150-
Type *string `json:"type,omitempty"`
151-
}
152-
153-
type ServicesScheduledActionsElem struct {
154-
// At corresponds to the JSON schema field "at".
155-
At *ServicesScheduledActionsElemAt `json:"at,omitempty"`
156-
157-
// ToUrgency corresponds to the JSON schema field "to_urgency".
158-
ToUrgency *string `json:"to_urgency,omitempty"`
159-
160-
// Type corresponds to the JSON schema field "type".
161-
Type *string `json:"type,omitempty"`
162-
}
163-
164-
type ServicesScheduledActionsElemAt struct {
165-
// Name corresponds to the JSON schema field "name".
166-
Name *string `json:"name,omitempty"`
167-
168-
// Type corresponds to the JSON schema field "type".
169-
Type *string `json:"type,omitempty"`
170-
}
171-
172-
type ServicesSupportHours struct {
173-
// DaysOfWeek corresponds to the JSON schema field "days_of_week".
174-
DaysOfWeek []int `json:"days_of_week,omitempty"`
175-
176-
// EndTime corresponds to the JSON schema field "end_time".
177-
EndTime *string `json:"end_time,omitempty"`
178-
179-
// StartTime corresponds to the JSON schema field "start_time".
180-
StartTime *string `json:"start_time,omitempty"`
181-
182-
// TimeZone corresponds to the JSON schema field "time_zone".
183-
TimeZone *string `json:"time_zone,omitempty"`
184-
185-
// Type corresponds to the JSON schema field "type".
186-
Type *string `json:"type,omitempty"`
187-
}
188-
189-
type ServicesTeamsElem struct {
190-
// HtmlUrl corresponds to the JSON schema field "html_url".
191-
HtmlUrl *string `json:"html_url,omitempty"`
192-
193-
// Id corresponds to the JSON schema field "id".
194-
Id *string `json:"id,omitempty"`
195-
196-
// Self corresponds to the JSON schema field "self".
197-
Self *string `json:"self,omitempty"`
198-
199-
// Summary corresponds to the JSON schema field "summary".
200-
Summary *string `json:"summary,omitempty"`
201-
202-
// Type corresponds to the JSON schema field "type".
203-
Type *string `json:"type,omitempty"`
22+
type Service struct {
23+
Id string `json:"id"`
24+
Summary string `json:"summary"`
25+
Type string `json:"type"`
26+
Self string `json:"self"`
27+
HtmlUrl string `json:"html_url"`
28+
Name string `json:"name"`
29+
AutoResolveTimeout int `json:"auto_resolve_timeout"`
30+
AcknowledgementTimeout int `json:"acknowledgement_timeout"`
31+
CreatedAt time.Time `json:"created_at"`
32+
Status string `json:"status"`
33+
AlertCreation string `json:"alert_creation"`
34+
AlertGroupingParameters struct {
35+
Type string `json:"type"`
36+
} `json:"alert_grouping_parameters"`
37+
Integrations []struct {
38+
Id string `json:"id"`
39+
Type string `json:"type"`
40+
Summary string `json:"summary"`
41+
Self string `json:"self"`
42+
HtmlUrl string `json:"html_url"`
43+
} `json:"integrations"`
44+
EscalationPolicy struct {
45+
Id string `json:"id"`
46+
Type string `json:"type"`
47+
Summary string `json:"summary"`
48+
Self string `json:"self"`
49+
HtmlUrl string `json:"html_url"`
50+
} `json:"escalation_policy"`
51+
Teams []struct {
52+
Id string `json:"id"`
53+
Type string `json:"type"`
54+
Summary string `json:"summary"`
55+
Self string `json:"self"`
56+
HtmlUrl string `json:"html_url"`
57+
} `json:"teams"`
58+
IncidentUrgencyRule struct {
59+
Type string `json:"type"`
60+
DuringSupportHours struct {
61+
Type string `json:"type"`
62+
Urgency string `json:"urgency"`
63+
} `json:"during_support_hours"`
64+
OutsideSupportHours struct {
65+
Type string `json:"type"`
66+
Urgency string `json:"urgency"`
67+
} `json:"outside_support_hours"`
68+
} `json:"incident_urgency_rule"`
69+
SupportHours struct {
70+
Type string `json:"type"`
71+
TimeZone string `json:"time_zone"`
72+
StartTime string `json:"start_time"`
73+
EndTime string `json:"end_time"`
74+
DaysOfWeek []int `json:"days_of_week"`
75+
} `json:"support_hours"`
76+
ScheduledActions []struct {
77+
Type string `json:"type"`
78+
At struct {
79+
Type string `json:"type"`
80+
Name string `json:"name"`
81+
} `json:"at"`
82+
ToUrgency string `json:"to_urgency"`
83+
} `json:"scheduled_actions"`
84+
AutoPauseNotificationsParameters struct {
85+
Enabled bool `json:"enabled"`
86+
Timeout int `json:"timeout"`
87+
} `json:"auto_pause_notifications_parameters"`
20488
}

backend/plugins/pagerduty/tasks/incidents_converter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func ConvertIncidents(taskCtx plugin.SubTaskContext) errors.Error {
5858
dal.From("_tool_pagerduty_incidents AS pi"),
5959
dal.Join(`LEFT JOIN _tool_pagerduty_assignments AS pa ON pa.incident_number = pi.number`),
6060
dal.Join(`LEFT JOIN _tool_pagerduty_users AS pu ON pa.user_id = pu.id`),
61-
dal.Where("pi.connection_id = ?", data.Options.ConnectionId),
61+
dal.Where("pi.connection_id = ? AND pi.service_id = ?", data.Options.ConnectionId, data.Options.ServiceId),
6262
)
6363
if err != nil {
6464
return err

0 commit comments

Comments
 (0)