Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Show MR info in schema change #40

Merged
merged 9 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
NAME="github.com/goto/stencil"
VERSION=$(shell git describe --always --tags 2>/dev/null)
PROTON_COMMIT := "4acac160b663d97d64cab017dcb08c787eec3e1d"
PROTON_COMMIT := "6bc4e5b240f0fd8a2dab4696c570a9c9a6a692ec"
EXCLUDE_FILES :=./test_utils/testutils.go
.PHONY: all build test clean dist vet proto install ui

Expand Down
2 changes: 2 additions & 0 deletions core/changedetector/change_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ type ChangeRequest struct {
OldData []byte
NewData []byte
Depth int32
SourceURL string
CommitSHA string
}

type NotificationEvent struct {
Expand Down
4 changes: 4 additions & 0 deletions core/changedetector/proto_change_detector_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func (s *Service) IdentifySchemaChange(ctx context.Context, request *ChangeReque
NamespaceName: request.NamespaceID,
SchemaName: request.SchemaName,
Version: request.Version,
Metadata: &stencilv1beta1.Metadata{
SourceUrl: request.SourceURL,
CommitSha: request.CommitSHA,
},
}
setDirectlyImpactedSchemasAndFields(currentFds, prevFds, sce)
reverseDependencies := getReverseDependencies(currentFds)
Expand Down
3 changes: 3 additions & 0 deletions core/changedetector/proto_change_detector_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func init() {
SchemaName: "testSchemaName",
Version: int32(1),
Depth: 10,
SourceURL: "https://github.com/some-repo",
CommitSHA: "some-commit-sha",
}
}

Expand Down Expand Up @@ -256,6 +258,7 @@ func assertSchemaChangeEvent(t *testing.T, expected, actual *stencilv1beta2.Sche
assert.ElementsMatch(t, expected.UpdatedSchemas, actual.UpdatedSchemas)
assertUpdatedFields(t, expected.UpdatedFields, actual.UpdatedFields)
assertImpactedSchemas(t, expected.ImpactedSchemas, actual.ImpactedSchemas)
assert.Equal(t, expected.Metadata, actual.Metadata)
}

func assertUpdatedFields(t *testing.T, expected, actual map[string]*stencilv1beta2.ImpactedFields) {
Expand Down
6 changes: 5 additions & 1 deletion core/changedetector/testdata/output/sce_enum_added.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@
]
}
},
"version": 1
"version": 1,
"metadata": {
"source_url": "https://github.com/some-repo",
"commit_sha": "some-commit-sha"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@
]
}
},
"version": 1
"version": 1,
"metadata": {
"source_url": "https://github.com/some-repo",
"commit_sha": "some-commit-sha"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@
]
}
},
"version": 1
"version": 1,
"metadata": {
"source_url": "https://github.com/some-repo",
"commit_sha": "some-commit-sha"
}
}
6 changes: 5 additions & 1 deletion core/changedetector/testdata/output/sce_enum_updated.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@
]
}
},
"version": 1
"version": 1,
"metadata": {
"source_url": "https://github.com/some-repo",
"commit_sha": "some-commit-sha"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@
]
}
},
"version": 1
"version": 1,
"metadata": {
"source_url": "https://github.com/some-repo",
"commit_sha": "some-commit-sha"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@
]
}
},
"version": 1
"version": 1,
"metadata": {
"source_url": "https://github.com/some-repo",
"commit_sha": "some-commit-sha"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@
]
}
},
"version": 1
"version": 1,
"metadata": {
"source_url": "https://github.com/some-repo",
"commit_sha": "some-commit-sha"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@
]
}
},
"version": 1
"version": 1,
"metadata": {
"source_url": "https://github.com/some-repo",
"commit_sha": "some-commit-sha"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@
]
}
},
"version": 1
"version": 1,
"metadata": {
"source_url": "https://github.com/some-repo",
"commit_sha": "some-commit-sha"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@
]
}
},
"version": 1
"version": 1,
"metadata": {
"source_url": "https://github.com/some-repo",
"commit_sha": "some-commit-sha"
}
}
20 changes: 10 additions & 10 deletions core/schema/mocks/schema_repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion core/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package schema

import (
"context"

"google.golang.org/protobuf/proto"

"github.com/goto/stencil/core/changedetector"
Expand All @@ -12,6 +13,7 @@ type Metadata struct {
Authority string
Format string
Compatibility string
SourceURL string
}

type SchemaInfo struct {
Expand All @@ -27,8 +29,15 @@ type SchemaFile struct {
Data []byte
}

type UpdateSchemaRequest struct {
Namespace string
Schema string
Metadata *Metadata
SchemaFile *SchemaFile
}

type Repository interface {
Create(ctx context.Context, namespace string, schema string, metadata *Metadata, versionID string, schemaFile *SchemaFile) (version int32, err error)
Create(ctx context.Context, request *UpdateSchemaRequest, versionID string, commitSHA string) (version int32, err error)
List(context.Context, string) ([]Schema, error)
ListVersions(context.Context, string, string) ([]int32, error)
Get(context.Context, string, string, int32) ([]byte, error)
Expand Down Expand Up @@ -62,6 +71,7 @@ type Schema struct {
Format string
Compatibility string
Authority string
SourceURL string
}

type ChangeDetectorService interface {
Expand Down
14 changes: 11 additions & 3 deletions core/schema/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"github.com/google/uuid"

"github.com/jackc/pgx/v4"

"github.com/goto/stencil/config"
Expand Down Expand Up @@ -100,7 +99,7 @@ func (s *Service) checkCompatibility(ctx context.Context, nsName, schemaName, fo
return checkerFn(current, []ParsedSchema{prevSchema})
}

func (s *Service) Create(ctx context.Context, nsName string, schemaName string, metadata *Metadata, data []byte) (SchemaInfo, error) {
func (s *Service) Create(ctx context.Context, nsName string, schemaName string, metadata *Metadata, data []byte, commitSHA string) (SchemaInfo, error) {
endFunc := s.newrelic.StartGenericSegment(ctx, "Create Schema Info")
defer endFunc()
var scInfo SchemaInfo
Expand All @@ -121,10 +120,17 @@ func (s *Service) Create(ctx context.Context, nsName string, schemaName string,
mergedMetadata := &Metadata{
Format: format,
Compatibility: compatibility,
SourceURL: metadata.SourceURL,
}
versionID := getIDforSchema(nsName, schemaName, sf.ID)
_, prevSchemaData, err2 := s.GetLatest(ctx, nsName, schemaName)
version, err := s.repo.Create(ctx, nsName, schemaName, mergedMetadata, versionID, sf)
request := &UpdateSchemaRequest{
Namespace: nsName,
Schema: schemaName,
Metadata: mergedMetadata,
SchemaFile: sf,
}
version, err := s.repo.Create(ctx, request, versionID, commitSHA)
if err != nil {
log.Printf("got error while creating schema %s in namespace %s -> %s", schemaName, nsName, err.Error())
}
Expand All @@ -139,6 +145,8 @@ func (s *Service) Create(ctx context.Context, nsName string, schemaName string,
OldData: prevSchemaData,
NewData: data,
Depth: s.config.SchemaChange.Depth,
SourceURL: metadata.SourceURL,
CommitSHA: commitSHA,
}
go func() {
newCtx, cancel := context.WithTimeout(context.Background(), 1*time.Hour)
Expand Down
Loading
Loading