Skip to content

Commit

Permalink
update sentryclient to latest master
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesverdad committed Jun 10, 2020
1 parent 6bc753e commit a1fa38a
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 84 deletions.
19 changes: 10 additions & 9 deletions sentryclient/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,16 @@ func (s *ProjectService) Create(organizationSlug string, teamSlug string, params

// UpdateProjectParams are the parameters for ProjectService.Update.
type UpdateProjectParams struct {
Name string `json:"name,omitempty"`
Slug string `json:"slug,omitempty"`
Platform string `json:"platform,omitempty"`
IsBookmarked *bool `json:"isBookmarked,omitempty"`
DigestsMinDelay *int `json:"digestsMinDelay,omitempty"`
DigestsMaxDelay *int `json:"digestsMaxDelay,omitempty"`
Options map[string]interface{} `json:"options,omitempty"`
AllowedDomains []string `json:"allowedDomains,omitempty"`
GroupingEnhancements string `json:"groupingEnhancements,omitempty"`
Name string `json:"name,omitempty"`
Slug string `json:"slug,omitempty"`
Platform string `json:"platform,omitempty"`
IsBookmarked *bool `json:"isBookmarked,omitempty"`
DigestsMinDelay *int `json:"digestsMinDelay,omitempty"`
DigestsMaxDelay *int `json:"digestsMaxDelay,omitempty"`
ResolveAge *int `json:"resolveAge,omitempty"`
Options map[string]interface{} `json:"options,omitempty"`
AllowedDomains []string `json:"allowedDomains,omitempty"`
GroupingEnhancements string `json:"groupingEnhancements,omitempty"`
}

// Update various attributes and configurable settings for a given project.
Expand Down
19 changes: 11 additions & 8 deletions sentryclient/projects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func TestProjectService_List(t *testing.T) {
Avatar: Avatar{
Type: "letter_avatar",
},
Organization: expectedOrganization,
Organization: expectedOrganization,
GroupingEnhancements: "pump station grouping enhancement rule",
},
}
Expand Down Expand Up @@ -335,7 +335,7 @@ func TestProjectService_Get(t *testing.T) {
}],
"processingIssues": 0,
"relayPiiConfig": null,
"resolveAge": 0,
"resolveAge": 720,
"safeFields": [],
"scrapeJavaScript": true,
"scrubIPAddresses": false,
Expand Down Expand Up @@ -392,6 +392,7 @@ func TestProjectService_Get(t *testing.T) {
},
DigestsMinDelay: 300,
DigestsMaxDelay: 1800,
ResolveAge: 720,
SubjectPrefix: "[Sentry] ",
AllowedDomains: []string{"*"},
DataScrubber: true,
Expand Down Expand Up @@ -506,7 +507,7 @@ func TestProjectService_Update(t *testing.T) {
"digestsMinDelay": 300,
"options": {
"sentry:origins": "http://example.com\nhttp://example.invalid",
"sentry:resolve_age": 0
"sentry:resolve_age": 720
},
"defaultEnvironment": null,
"features": [
Expand All @@ -523,14 +524,15 @@ func TestProjectService_Update(t *testing.T) {
"callSign": "PLANE-PROXY",
"firstEvent": null,
"digestsMaxDelay": 1800,
"resolveAge": 720,
"processingIssues": 0,
"isBookmarked": false,
"callSignReviewed": false,
"id": "5",
"subjectTemplate": "[$project] ${tag:level}: $title",
"name": "Plane Proxy",
"groupingEnhancements": "Plane Proxy grouping enhancement rule"
}`)
}`)
})

client := NewClient(httpClient, nil, "")
Expand Down Expand Up @@ -559,11 +561,12 @@ func TestProjectService_Update(t *testing.T) {
Status: "active",
Options: map[string]interface{}{
"sentry:origins": "http://example.com\nhttp://example.invalid",
"sentry:resolve_age": float64(0),
"sentry:resolve_age": float64(720),
},
DigestsMinDelay: 300,
DigestsMaxDelay: 1800,
SubjectTemplate: "[$project] ${tag:level}: $title",
DigestsMinDelay: 300,
DigestsMaxDelay: 1800,
ResolveAge: 720,
SubjectTemplate: "[$project] ${tag:level}: $title",
GroupingEnhancements: "Plane Proxy grouping enhancement rule",
}
assert.Equal(t, expected, project)
Expand Down
19 changes: 8 additions & 11 deletions sentryclient/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type Rule struct {
ID string `json:"id"`
ActionMatch string `json:"actionMatch"`
Environment string `json:"environment"`
Environment *string `json:"environment"`
Frequency int `json:"frequency"`
Name string `json:"name"`
Conditions []RuleCondition `json:"conditions"`
Expand All @@ -23,8 +23,10 @@ type Rule struct {
// RuleCondition represents the conditions for each rule.
// https://github.com/getsentry/sentry/blob/9.0.0/src/sentry/api/serializers/models/rule.py
type RuleCondition struct {
ID string `json:"id"`
Name string `json:"name"`
ID string `json:"id"`
Name string `json:"name"`
Interval string `json:"interval"`
Value int `json:"value"`
}

// RuleAction represents the actions will be taken for each rule based on its conditions.
Expand Down Expand Up @@ -75,18 +77,13 @@ type CreateRuleActionParams struct {
Tags string `json:"tags"`
Channel string `json:"channel"`
Workspace string `json:"workspace"`
Action string `json:"action,omitempty"`
Service string `json:"service,omitempty"`
}

// CreateRuleConditionParams models the conditions when creating the action for the rule.
type CreateRuleConditionParams struct {
ID string `json:"id"`
Attribute string `json:"attribute,omitempty"`
Match string `json:"match,omitempty"`
Value string `json:"value,omitempty"`
Key string `json:"key,omitempty"`
Interval string `json:"interval,omitempty"`
ID string `json:"id"`
Interval string `json:"interval"`
Value int `json:"value"`
}

// Create a new alert rule bound to a project.
Expand Down
123 changes: 67 additions & 56 deletions sentryclient/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ func TestRulesService_List(t *testing.T) {
"conditions": [
{
"id": "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition",
"name": "An issue is first seen"
"name": "An issue is first seen",
"value": 500,
"interval": "1h"
}
],
"id": "123456",
Expand All @@ -46,26 +48,27 @@ func TestRulesService_List(t *testing.T) {
rules, _, err := client.Rules.List("the-interstellar-jurisdiction", "pump-station")
assert.NoError(t, err)

environment := "production"
expected := []Rule{
{
ID: "123456",
ID: "123456",
ActionMatch: "all",
Environment: "production",
Frequency: 30,
Name: "Notify errors",
Environment: &environment,
Frequency: 30,
Name: "Notify errors",
Conditions: []RuleCondition{
{
ID: "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition",
ID: "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition",
Name: "An issue is first seen",
},
},
Actions: []RuleAction{
{
ID: "sentry.integrations.slack.notify_action.SlackNotifyServiceAction",
Name: "Send a notification to the Dummy Slack workspace to #dummy-channel and show tags [environment] in notification",
Tags: "environment",
ID: "sentry.integrations.slack.notify_action.SlackNotifyServiceAction",
Name: "Send a notification to the Dummy Slack workspace to #dummy-channel and show tags [environment] in notification",
Tags: "environment",
ChannelID: "XX00X0X0X",
Channel: "#dummy-channel",
Channel: "#dummy-channel",
Workspace: "1234",
},
},
Expand All @@ -85,16 +88,16 @@ func TestRulesService_Create(t *testing.T) {
assertPostJSON(t, map[string]interface{}{
"actionMatch": "all",
"environment": "production",
"frequency": 30,
"name": "Notify errors",
"frequency": 30,
"name": "Notify errors",
"conditions": []map[string]interface{}{
{"ID": "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition"},
{"ID": "sentry.rules.conditions.event_frequency.EventFrequencyCondition", "value": 500, "interval": "1h"},
},
"actions": []map[string]interface{}{
{
"ID": "sentry.integrations.slack.notify_action.SlackNotifyServiceAction",
"Tags": "environment",
"Channel": "#dummy-channel",
"ID": "sentry.integrations.slack.notify_action.SlackNotifyServiceAction",
"Tags": "environment",
"Channel": "#dummy-channel",
"Workspace": "1234",
},
},
Expand Down Expand Up @@ -129,16 +132,20 @@ func TestRulesService_Create(t *testing.T) {
params := &CreateRuleParams{
ActionMatch: "all",
Environment: "production",
Frequency: 30,
Name: "Notify errors",
Frequency: 30,
Name: "Notify errors",
Conditions: []*CreateRuleConditionParams{
{ID: "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition"},
{
ID: "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition",
Value: 500,
Interval: "1h",
},
},
Actions: []*CreateRuleActionParams{
{
ID: "sentry.integrations.slack.notify_action.SlackNotifyServiceAction",
Tags: "environment",
Channel: "#dummy-channel",
ID: "sentry.integrations.slack.notify_action.SlackNotifyServiceAction",
Tags: "environment",
Channel: "#dummy-channel",
Workspace: "1234",
},
},
Expand All @@ -148,25 +155,26 @@ func TestRulesService_Create(t *testing.T) {
rules, _, err := client.Rules.Create("the-interstellar-jurisdiction", "pump-station", params)
assert.NoError(t, err)

environment := "production"
expected := Rule{
ID: "123456",
ID: "123456",
ActionMatch: "all",
Environment: "production",
Frequency: 30,
Name: "Notify errors",
Environment: &environment,
Frequency: 30,
Name: "Notify errors",
Conditions: []RuleCondition{
{
ID: "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition",
ID: "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition",
Name: "An issue is first seen",
},
},
Actions: []RuleAction{
{
ID: "sentry.integrations.slack.notify_action.SlackNotifyServiceAction",
Name: "Send a notification to the Dummy Slack workspace to #dummy-channel and show tags [environment] in notification",
Tags: "environment",
ID: "sentry.integrations.slack.notify_action.SlackNotifyServiceAction",
Name: "Send a notification to the Dummy Slack workspace to #dummy-channel and show tags [environment] in notification",
Tags: "environment",
ChannelID: "XX00X0X0X",
Channel: "#dummy-channel",
Channel: "#dummy-channel",
Workspace: "1234",
},
},
Expand All @@ -185,16 +193,16 @@ func TestRulesService_Update(t *testing.T) {
assertPostJSON(t, map[string]interface{}{
"actionMatch": "all",
"environment": "staging",
"frequency": 30,
"name": "Notify errors",
"frequency": 30,
"name": "Notify errors",
"conditions": []map[string]interface{}{
{"ID": "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition"},
{"ID": "sentry.rules.conditions.event_frequency.EventFrequencyCondition", "value": 500, "interval": "1h"},
},
"actions": []map[string]interface{}{
{
"ID": "sentry.integrations.slack.notify_action.SlackNotifyServiceAction",
"Tags": "environment",
"Channel": "#dummy-channel",
"ID": "sentry.integrations.slack.notify_action.SlackNotifyServiceAction",
"Tags": "environment",
"Channel": "#dummy-channel",
"Workspace": "1234",
},
},
Expand Down Expand Up @@ -226,25 +234,27 @@ func TestRulesService_Update(t *testing.T) {
"dateCreated": "2019-08-24T18:12:16.321Z"
}`)

environment := "staging"
params := &Rule{
ID: "123456",
ID: "123456",
ActionMatch: "all",
Environment: "staging",
Frequency: 30,
Name: "Notify errors",
Environment: &environment,
Frequency: 30,
Name: "Notify errors",
Conditions: []RuleCondition{
{
ID: "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition",
Name: "An issue is first seen",
ID: "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition",
Value: 500,
Interval: "1h",
},
},
Actions: []RuleAction{
{
ID: "sentry.integrations.slack.notify_action.SlackNotifyServiceAction",
Name: "Send a notification to the Dummy Slack workspace to #dummy-channel and show tags [environment] in notification",
Tags: "environment",
ID: "sentry.integrations.slack.notify_action.SlackNotifyServiceAction",
Name: "Send a notification to the Dummy Slack workspace to #dummy-channel and show tags [environment] in notification",
Tags: "environment",
ChannelID: "XX00X0X0X",
Channel: "#dummy-channel",
Channel: "#dummy-channel",
Workspace: "1234",
},
},
Expand All @@ -255,25 +265,26 @@ func TestRulesService_Update(t *testing.T) {
rules, _, err := client.Rules.Update("the-interstellar-jurisdiction", "pump-station", "12345", params)
assert.NoError(t, err)

environment = "production"
expected := Rule{
ID: "123456",
ID: "123456",
ActionMatch: "all",
Environment: "production",
Frequency: 30,
Name: "Notify errors",
Environment: &environment,
Frequency: 30,
Name: "Notify errors",
Conditions: []RuleCondition{
{
ID: "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition",
ID: "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition",
Name: "An issue is first seen",
},
},
Actions: []RuleAction{
{
ID: "sentry.integrations.slack.notify_action.SlackNotifyServiceAction",
Name: "Send a notification to the Dummy Slack workspace to #dummy-channel and show tags [environment] in notification",
Tags: "environment",
ID: "sentry.integrations.slack.notify_action.SlackNotifyServiceAction",
Name: "Send a notification to the Dummy Slack workspace to #dummy-channel and show tags [environment] in notification",
Tags: "environment",
ChannelID: "XX00X0X0X",
Channel: "#dummy-channel",
Channel: "#dummy-channel",
Workspace: "1234",
},
},
Expand Down

0 comments on commit a1fa38a

Please sign in to comment.