Skip to content

Commit

Permalink
feat: OrganizationIntegration endpoints use json.RawMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
jianyuan committed May 5, 2024
1 parent b33f9fa commit 2092363
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
15 changes: 8 additions & 7 deletions sentry/organization_integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sentry

import (
"context"
"encoding/json"
"fmt"
"time"
)
Expand All @@ -17,7 +18,7 @@ type OrganizationIntegrationProvider struct {
}

// IntegrationConfigData for defining integration-specific configuration data.
type IntegrationConfigData map[string]interface{}
type IntegrationConfigData map[string]json.RawMessage

// OrganizationIntegration represents an integration added for the organization.
// https://github.com/getsentry/sentry/blob/22.7.0/src/sentry/api/serializers/models/integration.py#L93
Expand All @@ -33,11 +34,11 @@ type OrganizationIntegration struct {
Provider OrganizationIntegrationProvider `json:"provider"`

// https://github.com/getsentry/sentry/blob/22.7.0/src/sentry/api/serializers/models/integration.py#L138
ConfigData *IntegrationConfigData `json:"configData"`
ExternalId string `json:"externalId"`
OrganizationId int `json:"organizationId"`
OrganizationIntegrationStatus string `json:"organizationIntegrationStatus"`
GracePeriodEnd *time.Time `json:"gracePeriodEnd"`
ConfigData json.RawMessage `json:"configData"`
ExternalId string `json:"externalId"`
OrganizationId int `json:"organizationId"`
OrganizationIntegrationStatus string `json:"organizationIntegrationStatus"`
GracePeriodEnd *time.Time `json:"gracePeriodEnd"`
}

// OrganizationIntegrationsService provides methods for accessing Sentry organization integrations API endpoints.
Expand Down Expand Up @@ -88,7 +89,7 @@ func (s *OrganizationIntegrationsService) Get(ctx context.Context, organizationS
return integration, resp, nil
}

type UpdateConfigOrganizationIntegrationsParams = IntegrationConfigData
type UpdateConfigOrganizationIntegrationsParams = json.RawMessage

// UpdateConfig - update configData for organization integration.
// https://github.com/getsentry/sentry/blob/22.7.0/src/sentry/api/endpoints/integrations/organization_integrations/details.py#L94-L102
Expand Down
42 changes: 21 additions & 21 deletions sentry/organization_integrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestOrganizationIntegrationsService_List(t *testing.T) {
"stacktrace-link",
},
},
ConfigData: &IntegrationConfigData{},
ConfigData: json.RawMessage("{}"),
ExternalId: "87654321",
OrganizationId: 2,
OrganizationIntegrationStatus: "active",
Expand Down Expand Up @@ -181,15 +181,15 @@ func TestOrganizationIntegrationsService_Get(t *testing.T) {
"incident-management",
},
},
ConfigData: &IntegrationConfigData{
"service_table": []interface{}{
map[string]interface{}{
"service": "testing123",
"integration_key": "abc123xyz",
"id": json.Number("22222"),
},
},
},
ConfigData: json.RawMessage(`{
"service_table": [
{
"service": "testing123",
"integration_key": "abc123xyz",
"id": 22222
}
]
}`),
ExternalId: "999999",
OrganizationId: 2,
OrganizationIntegrationStatus: "active",
Expand All @@ -207,20 +207,20 @@ func TestOrganizationIntegrationsService_UpdateConfig(t *testing.T) {
w.Header().Set("Content-Type", "application/json")
})

updateConfigOrganizationIntegrationsParams := UpdateConfigOrganizationIntegrationsParams{
"service_table": []interface{}{
map[string]interface{}{
"service": "testing123",
updateConfigOrganizationIntegrationsParams := UpdateConfigOrganizationIntegrationsParams(`{
"service_table": [
{
"service": "testing123",
"integration_key": "abc123xyz",
"id": json.Number("22222"),
"id": 22222
},
map[string]interface{}{
"service": "testing456",
{
"service": "testing456",
"integration_key": "efg456lmn",
"id": "",
},
},
}
"id": ""
}
]
}`)
ctx := context.Background()
resp, err := client.OrganizationIntegrations.UpdateConfig(ctx, "the-interstellar-jurisdiction", "456789", &updateConfigOrganizationIntegrationsParams)
assert.NoError(t, err)
Expand Down

0 comments on commit 2092363

Please sign in to comment.