Skip to content

Commit

Permalink
Merge pull request #7 from Canva/foadnh-sync-upstream
Browse files Browse the repository at this point in the history
Sync with upstream
  • Loading branch information
foadnh authored Mar 21, 2024
2 parents 34975c1 + 50b9617 commit 9ae3735
Show file tree
Hide file tree
Showing 38 changed files with 2,563 additions and 311 deletions.
26 changes: 12 additions & 14 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,24 @@ name: Go
on: push

jobs:

build:
runs-on: ubuntu-latest
strategy:
matrix:
go:
- "1.15"
- "1.16"
- "1.17"
- "1.18"
- "1.19"
- "1.20"
- "1.21"
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}

- name: Build
run: go build -v ./...
- name: Build
run: go build -v ./...

- name: Test
run: make test
- name: Test
run: make test
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module github.com/canva/go-sentry

go 1.18
go 1.19

require (
github.com/google/go-querystring v1.1.0
github.com/peterhellberg/link v1.1.0
github.com/stretchr/testify v1.8.0
github.com/peterhellberg/link v1.2.0
github.com/stretchr/testify v1.8.4
)

require (
Expand Down
19 changes: 4 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
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/peterhellberg/link v1.1.0 h1:s2+RH8EGuI/mI4QwrWGSYQCRz7uNgip9BaM04HKu5kc=
github.com/peterhellberg/link v1.1.0/go.mod h1:gtSlOT4jmkY8P47hbTc8PTgiDDWpdPbFYl75keYyBB8=
github.com/peterhellberg/link v1.2.0 h1:UA5pg3Gp/E0F2WdX7GERiNrPQrM1K6CVJUUWfHa4t6c=
github.com/peterhellberg/link v1.2.0/go.mod h1:gYfAh+oJgQu2SrZHg5hROVRQe1ICoK0/HHJTcE0edxc=
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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/stretchr/testify v1.7.4 h1:wZRexSlwd7ZXfKINDLsO4r7WBt3gTKONc6K/VesHvHM=
github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.7.5 h1:s5PTfem8p8EbKQOctVV53k6jCJt3UX4IEJzwh+C324Q=
github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
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.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
7 changes: 3 additions & 4 deletions sentry/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import (
// APIError represents a Sentry API Error response.
// Should look like:
//
// type apiError struct {
// Detail string `json:"detail"`
// }
//
// type apiError struct {
// Detail string `json:"detail"`
// }
type APIError struct {
f interface{} // unknown
}
Expand Down
38 changes: 15 additions & 23 deletions sentry/issue_alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sentry

import (
"context"
"encoding/json"
"errors"
"fmt"
"time"
Expand All @@ -10,20 +11,20 @@ import (
// IssueAlert represents an issue alert configured for this project.
// https://github.com/getsentry/sentry/blob/22.5.0/src/sentry/api/serializers/models/rule.py#L131-L155
type IssueAlert struct {
ID *string `json:"id,omitempty"`
Conditions []*IssueAlertCondition `json:"conditions,omitempty"`
Filters []*IssueAlertFilter `json:"filters,omitempty"`
Actions []*IssueAlertAction `json:"actions,omitempty"`
ActionMatch *string `json:"actionMatch,omitempty"`
FilterMatch *string `json:"filterMatch,omitempty"`
Frequency *int `json:"frequency,omitempty"`
Name *string `json:"name,omitempty"`
DateCreated *time.Time `json:"dateCreated,omitempty"`
Owner *string `json:"owner,omitempty"`
CreatedBy *IssueAlertCreatedBy `json:"createdBy,omitempty"`
Environment *string `json:"environment,omitempty"`
Projects []string `json:"projects,omitempty"`
TaskUUID *string `json:"uuid,omitempty"` // This is actually the UUID of the async task that can be spawned to create the rule
ID *string `json:"id,omitempty"`
Conditions []map[string]interface{} `json:"conditions,omitempty"`
Filters []map[string]interface{} `json:"filters,omitempty"`
Actions []map[string]interface{} `json:"actions,omitempty"`
ActionMatch *string `json:"actionMatch,omitempty"`
FilterMatch *string `json:"filterMatch,omitempty"`
Frequency *json.Number `json:"frequency,omitempty"`
Name *string `json:"name,omitempty"`
DateCreated *time.Time `json:"dateCreated,omitempty"`
Owner *string `json:"owner,omitempty"`
CreatedBy *IssueAlertCreatedBy `json:"createdBy,omitempty"`
Environment *string `json:"environment,omitempty"`
Projects []string `json:"projects,omitempty"`
TaskUUID *string `json:"uuid,omitempty"` // This is actually the UUID of the async task that can be spawned to create the rule
}

// IssueAlertCreatedBy for defining the rule creator.
Expand All @@ -33,15 +34,6 @@ type IssueAlertCreatedBy struct {
Email *string `json:"email,omitempty"`
}

// IssueAlertCondition for defining conditions.
type IssueAlertCondition map[string]interface{}

// IssueAlertAction for defining actions.
type IssueAlertAction map[string]interface{}

// IssueAlertFilter for defining actions.
type IssueAlertFilter map[string]interface{}

// IssueAlertTaskDetail represents the inline struct Sentry defines for task details
// https://github.com/getsentry/sentry/blob/22.5.0/src/sentry/api/endpoints/project_rule_task_details.py#L29
type IssueAlertTaskDetail struct {
Expand Down
52 changes: 26 additions & 26 deletions sentry/issue_alerts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ func TestIssueAlertsService_List(t *testing.T) {
ID: String("12345"),
ActionMatch: String("any"),
Environment: String("production"),
Frequency: Int(30),
Frequency: JsonNumber(json.Number("30")),
Name: String("Notify errors"),
Conditions: []*IssueAlertCondition{
Conditions: []map[string]interface{}{
{
"id": "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition",
"name": "An issue is first seen",
"value": json.Number("500"),
"interval": "1h",
},
},
Actions: []*IssueAlertAction{
Actions: []map[string]interface{}{
{
"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",
Expand Down Expand Up @@ -221,7 +221,7 @@ func TestIssueAlertsService_Get(t *testing.T) {

expected := &IssueAlert{
ID: String("11185158"),
Conditions: []*IssueAlertCondition{
Conditions: []map[string]interface{}{
{
"id": "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition",
"name": "A new issue is created",
Expand Down Expand Up @@ -256,7 +256,7 @@ func TestIssueAlertsService_Get(t *testing.T) {
"name": "The issue affects more than 100.0 percent of sessions in 1h",
},
},
Filters: []*IssueAlertFilter{
Filters: []map[string]interface{}{
{
"comparison_type": "older",
"time": "minute",
Expand Down Expand Up @@ -300,7 +300,7 @@ func TestIssueAlertsService_Get(t *testing.T) {
"name": "The event's level is equal to fatal",
},
},
Actions: []*IssueAlertAction{
Actions: []map[string]interface{}{
{
"targetType": "IssueOwners",
"id": "sentry.mail.actions.NotifyEmailAction",
Expand All @@ -326,7 +326,7 @@ func TestIssueAlertsService_Get(t *testing.T) {
},
ActionMatch: String("any"),
FilterMatch: String("any"),
Frequency: Int(30),
Frequency: JsonNumber(json.Number("30")),
Name: String("My Rule Name"),
DateCreated: Time(mustParseTime("2022-05-23T19:54:30.860115Z")),
Owner: String("team:1322366"),
Expand Down Expand Up @@ -404,17 +404,17 @@ func TestIssueAlertsService_Create(t *testing.T) {
params := &IssueAlert{
ActionMatch: String("all"),
Environment: String("production"),
Frequency: Int(30),
Frequency: JsonNumber(json.Number("30")),
Name: String("Notify errors"),
Conditions: []*IssueAlertCondition{
Conditions: []map[string]interface{}{
{
"interval": "1h",
"name": "The issue is seen more than 10 times in 1h",
"value": json.Number("10"),
"id": "sentry.rules.conditions.event_frequency.EventFrequencyCondition",
},
},
Actions: []*IssueAlertAction{
Actions: []map[string]interface{}{
{
"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",
Expand All @@ -433,17 +433,17 @@ func TestIssueAlertsService_Create(t *testing.T) {
ID: String("123456"),
ActionMatch: String("all"),
Environment: String("production"),
Frequency: Int(30),
Frequency: JsonNumber(json.Number("30")),
Name: String("Notify errors"),
Conditions: []*IssueAlertCondition{
Conditions: []map[string]interface{}{
{
"interval": "1h",
"name": "The issue is seen more than 10 times in 1h",
"value": json.Number("10"),
"id": "sentry.rules.conditions.event_frequency.EventFrequencyCondition",
},
},
Actions: []*IssueAlertAction{
Actions: []map[string]interface{}{
{
"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",
Expand Down Expand Up @@ -532,17 +532,17 @@ func TestIssueAlertsService_CreateWithAsyncTask(t *testing.T) {
params := &IssueAlert{
ActionMatch: String("all"),
Environment: String("production"),
Frequency: Int(30),
Frequency: JsonNumber(json.Number("30")),
Name: String("Notify errors"),
Conditions: []*IssueAlertCondition{
Conditions: []map[string]interface{}{
{
"interval": "1h",
"name": "The issue is seen more than 10 times in 1h",
"value": json.Number("10"),
"id": "sentry.rules.conditions.event_frequency.EventFrequencyCondition",
},
},
Actions: []*IssueAlertAction{
Actions: []map[string]interface{}{
{
"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",
Expand All @@ -561,17 +561,17 @@ func TestIssueAlertsService_CreateWithAsyncTask(t *testing.T) {
ID: String("123456"),
ActionMatch: String("all"),
Environment: String("production"),
Frequency: Int(30),
Frequency: JsonNumber(json.Number("30")),
Name: String("Notify errors"),
Conditions: []*IssueAlertCondition{
Conditions: []map[string]interface{}{
{
"interval": "1h",
"name": "The issue is seen more than 10 times in 1h",
"value": json.Number("10"),
"id": "sentry.rules.conditions.event_frequency.EventFrequencyCondition",
},
},
Actions: []*IssueAlertAction{
Actions: []map[string]interface{}{
{
"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",
Expand All @@ -596,16 +596,16 @@ func TestIssueAlertsService_Update(t *testing.T) {
ActionMatch: String("all"),
FilterMatch: String("any"),
Environment: String("staging"),
Frequency: Int(30),
Frequency: JsonNumber(json.Number("30")),
Name: String("Notify errors"),
Conditions: []*IssueAlertCondition{
Conditions: []map[string]interface{}{
{
"id": "sentry.rules.conditions.event_frequency.EventFrequencyCondition",
"value": 500,
"interval": "1h",
},
},
Actions: []*IssueAlertAction{
Actions: []map[string]interface{}{
{
"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",
Expand All @@ -615,7 +615,7 @@ func TestIssueAlertsService_Update(t *testing.T) {
"workspace": "1234",
},
},
Filters: []*IssueAlertFilter{
Filters: []map[string]interface{}{
{
"id": "sentry.rules.filters.issue_occurrences.IssueOccurrencesFilter",
"name": "The issue has happened at least 4 times",
Expand Down Expand Up @@ -709,15 +709,15 @@ func TestIssueAlertsService_Update(t *testing.T) {
ID: String("12345"),
ActionMatch: String("any"),
Environment: String("staging"),
Frequency: Int(30),
Frequency: JsonNumber(json.Number("30")),
Name: String("Notify errors"),
Conditions: []*IssueAlertCondition{
Conditions: []map[string]interface{}{
{
"id": "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition",
"name": "An issue is first seen",
},
},
Actions: []*IssueAlertAction{
Actions: []map[string]interface{}{
{
"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",
Expand Down
Loading

0 comments on commit 9ae3735

Please sign in to comment.