From 2092363c6dad7ea6eaf7b7f5ef8b63c56becff64 Mon Sep 17 00:00:00 2001 From: Jian Yuan Lee Date: Sun, 5 May 2024 23:55:49 +0100 Subject: [PATCH] feat: OrganizationIntegration endpoints use json.RawMessage --- sentry/organization_integrations.go | 15 +++++---- sentry/organization_integrations_test.go | 42 ++++++++++++------------ 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/sentry/organization_integrations.go b/sentry/organization_integrations.go index 687296e..69af055 100644 --- a/sentry/organization_integrations.go +++ b/sentry/organization_integrations.go @@ -2,6 +2,7 @@ package sentry import ( "context" + "encoding/json" "fmt" "time" ) @@ -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 @@ -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. @@ -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 diff --git a/sentry/organization_integrations_test.go b/sentry/organization_integrations_test.go index 63ab695..8846a3f 100644 --- a/sentry/organization_integrations_test.go +++ b/sentry/organization_integrations_test.go @@ -81,7 +81,7 @@ func TestOrganizationIntegrationsService_List(t *testing.T) { "stacktrace-link", }, }, - ConfigData: &IntegrationConfigData{}, + ConfigData: json.RawMessage("{}"), ExternalId: "87654321", OrganizationId: 2, OrganizationIntegrationStatus: "active", @@ -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", @@ -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)