diff --git a/cmd/frontend/internal/search/BUILD.bazel b/cmd/frontend/internal/search/BUILD.bazel index 7747490379d..2e8d8306603 100644 --- a/cmd/frontend/internal/search/BUILD.bazel +++ b/cmd/frontend/internal/search/BUILD.bazel @@ -23,7 +23,6 @@ go_library( "//internal/honey", "//internal/honey/search", "//internal/lazyregexp", - "//internal/own/codeowners", "//internal/search", "//internal/search/client", "//internal/search/job/jobutil", diff --git a/cmd/frontend/internal/search/search.go b/cmd/frontend/internal/search/search.go index 2a4b9f30a20..a2771b1ee56 100644 --- a/cmd/frontend/internal/search/search.go +++ b/cmd/frontend/internal/search/search.go @@ -28,7 +28,6 @@ import ( "github.com/sourcegraph/sourcegraph/internal/honey" searchhoney "github.com/sourcegraph/sourcegraph/internal/honey/search" "github.com/sourcegraph/sourcegraph/internal/lazyregexp" - "github.com/sourcegraph/sourcegraph/internal/own/codeowners" "github.com/sourcegraph/sourcegraph/internal/search" "github.com/sourcegraph/sourcegraph/internal/search/client" "github.com/sourcegraph/sourcegraph/internal/search/job/jobutil" @@ -521,7 +520,7 @@ func fromCommit(commit *result.CommitMatch, repoCache map[api.RepoID]*types.Sear func fromOwner(owner *result.OwnerMatch) streamhttp.EventMatch { switch v := owner.ResolvedOwner.(type) { - case *codeowners.Person: + case *result.OwnerPerson: person := &streamhttp.EventPersonMatch{ Type: streamhttp.PersonMatchType, Handle: v.Handle, @@ -535,7 +534,7 @@ func fromOwner(owner *result.OwnerMatch) streamhttp.EventMatch { } } return person - case *codeowners.Team: + case *result.OwnerTeam: return &streamhttp.EventTeamMatch{ Type: streamhttp.TeamMatchType, Handle: v.Handle, diff --git a/enterprise/cmd/frontend/internal/own/BUILD.bazel b/enterprise/cmd/frontend/internal/own/BUILD.bazel index e7cca92fa31..3ab037ce020 100644 --- a/enterprise/cmd/frontend/internal/own/BUILD.bazel +++ b/enterprise/cmd/frontend/internal/own/BUILD.bazel @@ -9,10 +9,10 @@ go_library( "//cmd/frontend/enterprise", "//enterprise/cmd/frontend/internal/own/resolvers", "//enterprise/internal/codeintel", + "//enterprise/internal/own", "//internal/conf/conftypes", "//internal/database", "//internal/gitserver", "//internal/observation", - "//internal/own", ], ) diff --git a/enterprise/cmd/frontend/internal/own/init.go b/enterprise/cmd/frontend/internal/own/init.go index d39a023339b..cf9f54ec3e5 100644 --- a/enterprise/cmd/frontend/internal/own/init.go +++ b/enterprise/cmd/frontend/internal/own/init.go @@ -6,11 +6,11 @@ import ( "github.com/sourcegraph/sourcegraph/cmd/frontend/enterprise" "github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/own/resolvers" "github.com/sourcegraph/sourcegraph/enterprise/internal/codeintel" + "github.com/sourcegraph/sourcegraph/enterprise/internal/own" "github.com/sourcegraph/sourcegraph/internal/conf/conftypes" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/gitserver" "github.com/sourcegraph/sourcegraph/internal/observation" - "github.com/sourcegraph/sourcegraph/internal/own" ) // Init initializes the given enterpriseServices to include the required diff --git a/enterprise/cmd/frontend/internal/own/resolvers/BUILD.bazel b/enterprise/cmd/frontend/internal/own/resolvers/BUILD.bazel index 429c2778af2..fd4828e4ff2 100644 --- a/enterprise/cmd/frontend/internal/own/resolvers/BUILD.bazel +++ b/enterprise/cmd/frontend/internal/own/resolvers/BUILD.bazel @@ -8,10 +8,10 @@ go_library( deps = [ "//cmd/frontend/graphqlbackend", "//cmd/frontend/graphqlbackend/graphqlutil", + "//enterprise/internal/own", + "//enterprise/internal/own/codeowners", "//internal/api", "//internal/database", - "//internal/own", - "//internal/own/codeowners", ], ) @@ -22,14 +22,14 @@ go_test( ":resolvers", "//cmd/frontend/backend", "//cmd/frontend/graphqlbackend", + "//enterprise/internal/own/codeowners", + "//enterprise/internal/own/codeowners/v1:codeowners", "//internal/actor", "//internal/api", "//internal/authz", "//internal/database", "//internal/database/fakedb", "//internal/gitserver", - "//internal/own/codeowners", - "//internal/own/codeowners/v1:codeowners", "//internal/types", "@com_github_graph_gophers_graphql_go//relay", ], diff --git a/enterprise/cmd/frontend/internal/own/resolvers/resolvers.go b/enterprise/cmd/frontend/internal/own/resolvers/resolvers.go index 186e74c7182..1b5c1a999e4 100644 --- a/enterprise/cmd/frontend/internal/own/resolvers/resolvers.go +++ b/enterprise/cmd/frontend/internal/own/resolvers/resolvers.go @@ -7,10 +7,10 @@ import ( "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" + "github.com/sourcegraph/sourcegraph/enterprise/internal/own" + "github.com/sourcegraph/sourcegraph/enterprise/internal/own/codeowners" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/database" - "github.com/sourcegraph/sourcegraph/internal/own" - "github.com/sourcegraph/sourcegraph/internal/own/codeowners" ) func New(db database.DB, ownService own.Service) *ownResolver { diff --git a/enterprise/cmd/frontend/internal/own/resolvers/resolvers_test.go b/enterprise/cmd/frontend/internal/own/resolvers/resolvers_test.go index 6d9251f5a8a..4f71d9f9173 100644 --- a/enterprise/cmd/frontend/internal/own/resolvers/resolvers_test.go +++ b/enterprise/cmd/frontend/internal/own/resolvers/resolvers_test.go @@ -10,16 +10,15 @@ import ( "github.com/sourcegraph/sourcegraph/cmd/frontend/backend" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" "github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/own/resolvers" + "github.com/sourcegraph/sourcegraph/enterprise/internal/own/codeowners" + codeownerspb "github.com/sourcegraph/sourcegraph/enterprise/internal/own/codeowners/v1" "github.com/sourcegraph/sourcegraph/internal/actor" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/authz" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/database/fakedb" "github.com/sourcegraph/sourcegraph/internal/gitserver" - "github.com/sourcegraph/sourcegraph/internal/own/codeowners" "github.com/sourcegraph/sourcegraph/internal/types" - - codeownerspb "github.com/sourcegraph/sourcegraph/internal/own/codeowners/v1" ) // userCtx returns a context where give user ID identifies logged in user. diff --git a/enterprise/internal/database/BUILD.bazel b/enterprise/internal/database/BUILD.bazel index 45889a41726..08ac9f4a0e4 100644 --- a/enterprise/internal/database/BUILD.bazel +++ b/enterprise/internal/database/BUILD.bazel @@ -29,6 +29,8 @@ go_library( "//enterprise/internal/authz/github", "//enterprise/internal/authz/gitlab", "//enterprise/internal/authz/perforce", + "//enterprise/internal/own/codeowners/v1:codeowners", + "//enterprise/internal/own/types", "//internal/actor", "//internal/api", "//internal/authz", @@ -40,7 +42,6 @@ go_library( "//internal/database/dbutil", "//internal/encryption", "//internal/extsvc", - "//internal/own/codeowners/v1:codeowners", "//internal/search/result", "//internal/timeutil", "//internal/trace", @@ -85,6 +86,8 @@ go_test( deps = [ "//cmd/frontend/globals", "//enterprise/internal/licensing", + "//enterprise/internal/own/codeowners/v1:codeowners", + "//enterprise/internal/own/types", "//internal/actor", "//internal/api", "//internal/authz", @@ -94,7 +97,6 @@ go_test( "//internal/database/dbtest", "//internal/database/dbutil", "//internal/extsvc", - "//internal/own/codeowners/v1:codeowners", "//internal/search/result", "//internal/timeutil", "//internal/types", diff --git a/enterprise/internal/database/codeowners.go b/enterprise/internal/database/codeowners.go index 30011034ec0..4b032c1e5b8 100644 --- a/enterprise/internal/database/codeowners.go +++ b/enterprise/internal/database/codeowners.go @@ -8,13 +8,13 @@ import ( "github.com/keegancsmith/sqlf" "google.golang.org/protobuf/proto" + codeownerspb "github.com/sourcegraph/sourcegraph/enterprise/internal/own/codeowners/v1" + "github.com/sourcegraph/sourcegraph/enterprise/internal/own/types" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/database/basestore" "github.com/sourcegraph/sourcegraph/internal/database/dbutil" - codeownerspb "github.com/sourcegraph/sourcegraph/internal/own/codeowners/v1" "github.com/sourcegraph/sourcegraph/internal/timeutil" - "github.com/sourcegraph/sourcegraph/internal/types" "github.com/sourcegraph/sourcegraph/lib/errors" ) @@ -99,7 +99,7 @@ var codeownersColumns = []*sqlf.Query{ } const createCodeownersQueryFmtStr = ` -INSERT INTO codeowners +INSERT INTO codeowners (%s) VALUES (%s, %s, %s, %s, %s) ` @@ -143,12 +143,12 @@ func (s *codeownersStore) UpdateCodeownersFile(ctx context.Context, file *types. } const updateCodeownersQueryFmtStr = ` -UPDATE codeowners -SET +UPDATE codeowners +SET contents = %s, contents_proto = %s, updated_at = %s -WHERE +WHERE %s ` @@ -170,7 +170,7 @@ func (s *codeownersStore) GetCodeownersForRepo(ctx context.Context, id api.RepoI const getCodeownersFileQueryFmtStr = ` SELECT %s -FROM codeowners +FROM codeowners WHERE %s LIMIT 1 ` @@ -199,7 +199,7 @@ func (s *codeownersStore) DeleteCodeownersForRepo(ctx context.Context, id api.Re } const deleteCodeownersFileQueryFmtStr = ` -DELETE FROM codeowners +DELETE FROM codeowners WHERE %s ` @@ -240,10 +240,10 @@ func (s *codeownersStore) ListCodeowners(ctx context.Context, opts ListCodeowner const listCodeownersFilesQueryFmtStr = ` SELECT %s -FROM codeowners +FROM codeowners WHERE %s -ORDER BY - repo_id ASC +ORDER BY + repo_id ASC %s ` diff --git a/enterprise/internal/database/codeowners_test.go b/enterprise/internal/database/codeowners_test.go index a1702462d58..08364347c47 100644 --- a/enterprise/internal/database/codeowners_test.go +++ b/enterprise/internal/database/codeowners_test.go @@ -10,10 +10,11 @@ import ( "github.com/stretchr/testify/require" "google.golang.org/protobuf/testing/protocmp" + codeownerspb "github.com/sourcegraph/sourcegraph/enterprise/internal/own/codeowners/v1" + owntypes "github.com/sourcegraph/sourcegraph/enterprise/internal/own/types" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/database/dbtest" - codeownerspb "github.com/sourcegraph/sourcegraph/internal/own/codeowners/v1" "github.com/sourcegraph/sourcegraph/internal/timeutil" "github.com/sourcegraph/sourcegraph/internal/types" ) @@ -109,7 +110,7 @@ func TestCodeowners_GetList(t *testing.T) { store := db.Codeowners() - createFile := func(file *types.CodeownersFile) *types.CodeownersFile { + createFile := func(file *owntypes.CodeownersFile) *owntypes.CodeownersFile { if err := store.CreateCodeownersFile(ctx, file); err != nil { t.Fatal(err) } @@ -158,7 +159,7 @@ func TestCodeowners_GetList(t *testing.T) { }) t.Run("list", func(t *testing.T) { - all := []*types.CodeownersFile{repo1Codeowners, repo2Codeowners} + all := []*owntypes.CodeownersFile{repo1Codeowners, repo2Codeowners} // List all have, cursor, err := store.ListCodeowners(ctx, ListCodeownersOpts{}) @@ -192,8 +193,8 @@ func TestCodeowners_GetList(t *testing.T) { } // newCodeownersFile returns a simple test Codeowners file with one pattern and one owner. -func newCodeownersFile(pattern, handle string, repoID api.RepoID) *types.CodeownersFile { - return &types.CodeownersFile{ +func newCodeownersFile(pattern, handle string, repoID api.RepoID) *owntypes.CodeownersFile { + return &owntypes.CodeownersFile{ Contents: fmt.Sprintf("%s @%s", pattern, handle), Proto: &codeownerspb.File{ Rule: []*codeownerspb.Rule{ diff --git a/internal/own/BUILD.bazel b/enterprise/internal/own/BUILD.bazel similarity index 66% rename from internal/own/BUILD.bazel rename to enterprise/internal/own/BUILD.bazel index 4031ebb1d71..c3cff428b60 100644 --- a/internal/own/BUILD.bazel +++ b/enterprise/internal/own/BUILD.bazel @@ -3,16 +3,16 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") go_library( name = "own", srcs = ["service.go"], - importpath = "github.com/sourcegraph/sourcegraph/internal/own", - visibility = ["//:__subpackages__"], + importpath = "github.com/sourcegraph/sourcegraph/enterprise/internal/own", + visibility = ["//enterprise:__subpackages__"], deps = [ + "//enterprise/internal/own/codeowners", + "//enterprise/internal/own/codeowners/v1:codeowners", "//internal/api", "//internal/authz", "//internal/database", "//internal/errcode", "//internal/gitserver", - "//internal/own/codeowners", - "//internal/own/codeowners/v1:codeowners", "//internal/types", ], ) @@ -22,12 +22,12 @@ go_test( srcs = ["service_test.go"], deps = [ ":own", + "//enterprise/internal/own/codeowners", + "//enterprise/internal/own/codeowners/v1:codeowners", "//internal/api", "//internal/authz", "//internal/database", "//internal/gitserver", - "//internal/own/codeowners", - "//internal/own/codeowners/v1:codeowners", "//internal/types", "//lib/errors", "@com_github_stretchr_testify//assert", diff --git a/internal/own/codeowners/BUILD.bazel b/enterprise/internal/own/codeowners/BUILD.bazel similarity index 76% rename from internal/own/codeowners/BUILD.bazel rename to enterprise/internal/own/codeowners/BUILD.bazel index d288235e9b1..5df10cec0bf 100644 --- a/internal/own/codeowners/BUILD.bazel +++ b/enterprise/internal/own/codeowners/BUILD.bazel @@ -9,11 +9,11 @@ go_library( "parse.go", "repr.go", ], - importpath = "github.com/sourcegraph/sourcegraph/internal/own/codeowners", + importpath = "github.com/sourcegraph/sourcegraph/enterprise/internal/own/codeowners", visibility = ["//:__subpackages__"], deps = [ + "//enterprise/internal/own/codeowners/v1:codeowners", "//internal/lazyregexp", - "//internal/own/codeowners/v1:codeowners", "//internal/types", "//lib/errors", "@com_github_becheran_wildmatch_go//:wildmatch-go", @@ -28,7 +28,7 @@ go_test( ], deps = [ ":codeowners", - "//internal/own/codeowners/v1:codeowners", + "//enterprise/internal/own/codeowners/v1:codeowners", "@com_github_stretchr_testify//assert", "@com_github_stretchr_testify//require", ], diff --git a/internal/own/codeowners/README.md b/enterprise/internal/own/codeowners/README.md similarity index 100% rename from internal/own/codeowners/README.md rename to enterprise/internal/own/codeowners/README.md diff --git a/internal/own/codeowners/file.go b/enterprise/internal/own/codeowners/file.go similarity index 92% rename from internal/own/codeowners/file.go rename to enterprise/internal/own/codeowners/file.go index 6d053cd2714..f8b699960c1 100644 --- a/internal/own/codeowners/file.go +++ b/enterprise/internal/own/codeowners/file.go @@ -3,7 +3,7 @@ package codeowners import ( "sync" - codeownerspb "github.com/sourcegraph/sourcegraph/internal/own/codeowners/v1" + codeownerspb "github.com/sourcegraph/sourcegraph/enterprise/internal/own/codeowners/v1" ) type Ruleset struct { diff --git a/internal/own/codeowners/find_owners.go b/enterprise/internal/own/codeowners/find_owners.go similarity index 100% rename from internal/own/codeowners/find_owners.go rename to enterprise/internal/own/codeowners/find_owners.go diff --git a/internal/own/codeowners/find_owners_test.go b/enterprise/internal/own/codeowners/find_owners_test.go similarity index 98% rename from internal/own/codeowners/find_owners_test.go rename to enterprise/internal/own/codeowners/find_owners_test.go index 2d53831a025..78ac11614f4 100644 --- a/internal/own/codeowners/find_owners_test.go +++ b/enterprise/internal/own/codeowners/find_owners_test.go @@ -7,8 +7,8 @@ import ( "github.com/stretchr/testify/assert" - "github.com/sourcegraph/sourcegraph/internal/own/codeowners" - codeownerspb "github.com/sourcegraph/sourcegraph/internal/own/codeowners/v1" + "github.com/sourcegraph/sourcegraph/enterprise/internal/own/codeowners" + codeownerspb "github.com/sourcegraph/sourcegraph/enterprise/internal/own/codeowners/v1" ) type testCase struct { diff --git a/internal/own/codeowners/owner_types.go b/enterprise/internal/own/codeowners/owner_types.go similarity index 100% rename from internal/own/codeowners/owner_types.go rename to enterprise/internal/own/codeowners/owner_types.go diff --git a/internal/own/codeowners/parse.go b/enterprise/internal/own/codeowners/parse.go similarity index 98% rename from internal/own/codeowners/parse.go rename to enterprise/internal/own/codeowners/parse.go index f49bbf614a8..ceca42c85d4 100644 --- a/internal/own/codeowners/parse.go +++ b/enterprise/internal/own/codeowners/parse.go @@ -6,8 +6,8 @@ import ( "net/mail" "strings" + codeownerspb "github.com/sourcegraph/sourcegraph/enterprise/internal/own/codeowners/v1" "github.com/sourcegraph/sourcegraph/internal/lazyregexp" - codeownerspb "github.com/sourcegraph/sourcegraph/internal/own/codeowners/v1" "github.com/sourcegraph/sourcegraph/lib/errors" ) diff --git a/internal/own/codeowners/parse_test.go b/enterprise/internal/own/codeowners/parse_test.go similarity index 98% rename from internal/own/codeowners/parse_test.go rename to enterprise/internal/own/codeowners/parse_test.go index b54a0dbcd34..1d15dee30aa 100644 --- a/internal/own/codeowners/parse_test.go +++ b/enterprise/internal/own/codeowners/parse_test.go @@ -7,8 +7,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/sourcegraph/sourcegraph/internal/own/codeowners" - codeownerspb "github.com/sourcegraph/sourcegraph/internal/own/codeowners/v1" + "github.com/sourcegraph/sourcegraph/enterprise/internal/own/codeowners" + codeownerspb "github.com/sourcegraph/sourcegraph/enterprise/internal/own/codeowners/v1" ) func TestParseGithubExample(t *testing.T) { diff --git a/internal/own/codeowners/repr.go b/enterprise/internal/own/codeowners/repr.go similarity index 100% rename from internal/own/codeowners/repr.go rename to enterprise/internal/own/codeowners/repr.go diff --git a/internal/own/codeowners/v1/BUILD.bazel b/enterprise/internal/own/codeowners/v1/BUILD.bazel similarity index 88% rename from internal/own/codeowners/v1/BUILD.bazel rename to enterprise/internal/own/codeowners/v1/BUILD.bazel index 057ba9184fd..f3425e7e8b8 100644 --- a/internal/own/codeowners/v1/BUILD.bazel +++ b/enterprise/internal/own/codeowners/v1/BUILD.bazel @@ -14,7 +14,7 @@ proto_library( go_library( name = "codeowners", srcs = ["codeowners.pb.go"], - importpath = "github.com/sourcegraph/sourcegraph/internal/own/codeowners/v1", + importpath = "github.com/sourcegraph/sourcegraph/enterprise/internal/own/codeowners/v1", visibility = ["//:__subpackages__"], deps = [ "@org_golang_google_protobuf//reflect/protoreflect", diff --git a/internal/own/codeowners/v1/buf.gen.yaml b/enterprise/internal/own/codeowners/v1/buf.gen.yaml similarity index 100% rename from internal/own/codeowners/v1/buf.gen.yaml rename to enterprise/internal/own/codeowners/v1/buf.gen.yaml diff --git a/internal/own/codeowners/v1/codeowners.pb.go b/enterprise/internal/own/codeowners/v1/codeowners.pb.go similarity index 97% rename from internal/own/codeowners/v1/codeowners.pb.go rename to enterprise/internal/own/codeowners/v1/codeowners.pb.go index 43f745dd7af..9a403b8793f 100644 --- a/internal/own/codeowners/v1/codeowners.pb.go +++ b/enterprise/internal/own/codeowners/v1/codeowners.pb.go @@ -280,12 +280,12 @@ var file_codeowners_proto_rawDesc = []byte{ 0x72, 0x22, 0x35, 0x0a, 0x05, 0x4f, 0x77, 0x6e, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x42, 0x3f, 0x5a, 0x3d, 0x67, 0x69, 0x74, 0x68, + 0x09, 0x52, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x42, 0x4a, 0x5a, 0x48, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x67, 0x72, 0x61, - 0x70, 0x68, 0x2f, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x67, 0x72, 0x61, 0x70, 0x68, 0x2f, 0x69, - 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x6f, 0x77, 0x6e, 0x2f, 0x63, 0x6f, 0x64, 0x65, - 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x73, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x70, 0x68, 0x2f, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x67, 0x72, 0x61, 0x70, 0x68, 0x2f, 0x65, + 0x6e, 0x74, 0x65, 0x72, 0x70, 0x72, 0x69, 0x73, 0x65, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, + 0x61, 0x6c, 0x2f, 0x6f, 0x77, 0x6e, 0x2f, 0x63, 0x6f, 0x64, 0x65, 0x6f, 0x77, 0x6e, 0x65, 0x72, + 0x73, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/internal/own/codeowners/v1/codeowners.proto b/enterprise/internal/own/codeowners/v1/codeowners.proto similarity index 97% rename from internal/own/codeowners/v1/codeowners.proto rename to enterprise/internal/own/codeowners/v1/codeowners.proto index 6d1a1a9ce02..37ddbb6bc45 100644 --- a/internal/own/codeowners/v1/codeowners.proto +++ b/enterprise/internal/own/codeowners/v1/codeowners.proto @@ -6,7 +6,7 @@ syntax = "proto3"; package own.codeowners.v1; -option go_package = "github.com/sourcegraph/sourcegraph/internal/own/codeowners/v1"; +option go_package = "github.com/sourcegraph/sourcegraph/enterprise/internal/own/codeowners/v1"; // File represents the contents of a single CODEOWNERS file. // As specified by various CODEOWNERS implementations the following apply: diff --git a/internal/own/search/BUILD.bazel b/enterprise/internal/own/search/BUILD.bazel similarity index 90% rename from internal/own/search/BUILD.bazel rename to enterprise/internal/own/search/BUILD.bazel index de557548312..1d3e7a7e630 100644 --- a/internal/own/search/BUILD.bazel +++ b/enterprise/internal/own/search/BUILD.bazel @@ -53,15 +53,15 @@ go_library( "rules_cache.go", "select_job.go", ], - importpath = "github.com/sourcegraph/sourcegraph/internal/own/search", + importpath = "github.com/sourcegraph/sourcegraph/enterprise/internal/own/search", visibility = ["//:__subpackages__"], deps = [ + "//enterprise/internal/own", + "//enterprise/internal/own/codeowners", + "//enterprise/internal/own/codeowners/v1:codeowners", "//internal/api", "//internal/database", "//internal/gitserver", - "//internal/own", - "//internal/own/codeowners", - "//internal/own/codeowners/v1:codeowners", "//internal/search", "//internal/search/job", "//internal/search/result", @@ -84,7 +84,6 @@ go_test( "//internal/authz", "//internal/database", "//internal/gitserver", - "//internal/own/codeowners", "//internal/search/result", "//internal/types", "@com_github_hexops_autogold_v2//:autogold", diff --git a/internal/own/search/filter_job.go b/enterprise/internal/own/search/filter_job.go similarity index 97% rename from internal/own/search/filter_job.go rename to enterprise/internal/own/search/filter_job.go index 5887e3f2121..8cb43e5f87b 100644 --- a/internal/own/search/filter_job.go +++ b/enterprise/internal/own/search/filter_job.go @@ -7,7 +7,7 @@ import ( otlog "github.com/opentracing/opentracing-go/log" - codeownerspb "github.com/sourcegraph/sourcegraph/internal/own/codeowners/v1" + codeownerspb "github.com/sourcegraph/sourcegraph/enterprise/internal/own/codeowners/v1" "github.com/sourcegraph/sourcegraph/internal/search" "github.com/sourcegraph/sourcegraph/internal/search/job" "github.com/sourcegraph/sourcegraph/internal/search/result" diff --git a/internal/own/search/filter_job_test.go b/enterprise/internal/own/search/filter_job_test.go similarity index 100% rename from internal/own/search/filter_job_test.go rename to enterprise/internal/own/search/filter_job_test.go diff --git a/internal/own/search/rules_cache.go b/enterprise/internal/own/search/rules_cache.go similarity index 84% rename from internal/own/search/rules_cache.go rename to enterprise/internal/own/search/rules_cache.go index 531267f9794..453a4406777 100644 --- a/internal/own/search/rules_cache.go +++ b/enterprise/internal/own/search/rules_cache.go @@ -4,12 +4,12 @@ import ( "context" "sync" + "github.com/sourcegraph/sourcegraph/enterprise/internal/own" + "github.com/sourcegraph/sourcegraph/enterprise/internal/own/codeowners" + codeownerspb "github.com/sourcegraph/sourcegraph/enterprise/internal/own/codeowners/v1" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/gitserver" - "github.com/sourcegraph/sourcegraph/internal/own" - "github.com/sourcegraph/sourcegraph/internal/own/codeowners" - codeownerspb "github.com/sourcegraph/sourcegraph/internal/own/codeowners/v1" ) type RulesKey struct { diff --git a/internal/own/search/select_job.go b/enterprise/internal/own/search/select_job.go similarity index 84% rename from internal/own/search/select_job.go rename to enterprise/internal/own/search/select_job.go index 180cde2304f..8f3df93cd9e 100644 --- a/internal/own/search/select_job.go +++ b/enterprise/internal/own/search/select_job.go @@ -6,6 +6,7 @@ import ( otlog "github.com/opentracing/opentracing-go/log" + "github.com/sourcegraph/sourcegraph/enterprise/internal/own/codeowners" "github.com/sourcegraph/sourcegraph/internal/search" "github.com/sourcegraph/sourcegraph/internal/search/job" "github.com/sourcegraph/sourcegraph/internal/search/result" @@ -107,7 +108,7 @@ matchesLoop: } for _, o := range resolvedOwners { ownerMatch := &result.OwnerMatch{ - ResolvedOwner: o, + ResolvedOwner: ownerToResult(o), InputRev: mm.InputRev, Repo: mm.Repo, CommitID: mm.CommitID, @@ -117,3 +118,21 @@ matchesLoop: } return ownerMatches, errs } + +func ownerToResult(o codeowners.ResolvedOwner) result.Owner { + if v, ok := o.(*codeowners.Person); ok { + return &result.OwnerPerson{ + Handle: v.Handle, + Email: v.Email, + User: v.User, + } + } + if v, ok := o.(*codeowners.Team); ok { + return &result.OwnerTeam{ + Handle: v.Handle, + Email: v.Email, + Team: v.Team, + } + } + panic("unimplemented resolved owner in ownerToResult") +} diff --git a/internal/own/search/select_job_test.go b/enterprise/internal/own/search/select_job_test.go similarity index 92% rename from internal/own/search/select_job_test.go rename to enterprise/internal/own/search/select_job_test.go index 74d598e1012..d712c151b8a 100644 --- a/internal/own/search/select_job_test.go +++ b/enterprise/internal/own/search/select_job_test.go @@ -13,7 +13,6 @@ import ( "github.com/sourcegraph/sourcegraph/internal/authz" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/gitserver" - "github.com/sourcegraph/sourcegraph/internal/own/codeowners" "github.com/sourcegraph/sourcegraph/internal/search/result" "github.com/sourcegraph/sourcegraph/internal/types" ) @@ -123,28 +122,28 @@ func TestGetCodeOwnersFromMatches(t *testing.T) { } want := []result.Match{ &result.OwnerMatch{ - ResolvedOwner: &codeowners.Person{User: personOwnerByEmail, Email: "user@email.com"}, + ResolvedOwner: &result.OwnerPerson{User: personOwnerByEmail, Email: "user@email.com"}, InputRev: nil, Repo: types.MinimalRepo{}, CommitID: "", LimitHit: 0, }, &result.OwnerMatch{ - ResolvedOwner: &codeowners.Person{Handle: "unknown"}, + ResolvedOwner: &result.OwnerPerson{Handle: "unknown"}, InputRev: nil, Repo: types.MinimalRepo{}, CommitID: "", LimitHit: 0, }, &result.OwnerMatch{ - ResolvedOwner: &codeowners.Person{User: personOwnerByHandle, Handle: "testUserHandle"}, + ResolvedOwner: &result.OwnerPerson{User: personOwnerByHandle, Handle: "testUserHandle"}, InputRev: nil, Repo: types.MinimalRepo{}, CommitID: "", LimitHit: 0, }, &result.OwnerMatch{ - ResolvedOwner: &codeowners.Team{Team: teamOwner, Handle: "testTeamHandle"}, + ResolvedOwner: &result.OwnerTeam{Team: teamOwner, Handle: "testTeamHandle"}, InputRev: nil, Repo: types.MinimalRepo{}, CommitID: "", diff --git a/internal/own/service.go b/enterprise/internal/own/service.go similarity index 97% rename from internal/own/service.go rename to enterprise/internal/own/service.go index 940f7475053..93a8acffa24 100644 --- a/internal/own/service.go +++ b/enterprise/internal/own/service.go @@ -6,13 +6,13 @@ import ( "os" "sync" + "github.com/sourcegraph/sourcegraph/enterprise/internal/own/codeowners" + codeownerspb "github.com/sourcegraph/sourcegraph/enterprise/internal/own/codeowners/v1" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/authz" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/errcode" "github.com/sourcegraph/sourcegraph/internal/gitserver" - "github.com/sourcegraph/sourcegraph/internal/own/codeowners" - codeownerspb "github.com/sourcegraph/sourcegraph/internal/own/codeowners/v1" "github.com/sourcegraph/sourcegraph/internal/types" ) diff --git a/internal/own/service_test.go b/enterprise/internal/own/service_test.go similarity index 98% rename from internal/own/service_test.go rename to enterprise/internal/own/service_test.go index 023cde5f94e..1cb2942ee23 100644 --- a/internal/own/service_test.go +++ b/enterprise/internal/own/service_test.go @@ -9,13 +9,13 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/sourcegraph/sourcegraph/enterprise/internal/own" + "github.com/sourcegraph/sourcegraph/enterprise/internal/own/codeowners" + codeownerspb "github.com/sourcegraph/sourcegraph/enterprise/internal/own/codeowners/v1" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/authz" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/gitserver" - "github.com/sourcegraph/sourcegraph/internal/own" - "github.com/sourcegraph/sourcegraph/internal/own/codeowners" - codeownerspb "github.com/sourcegraph/sourcegraph/internal/own/codeowners/v1" "github.com/sourcegraph/sourcegraph/internal/types" "github.com/sourcegraph/sourcegraph/lib/errors" ) diff --git a/enterprise/internal/own/types/BUILD.bazel b/enterprise/internal/own/types/BUILD.bazel new file mode 100644 index 00000000000..283607336bf --- /dev/null +++ b/enterprise/internal/own/types/BUILD.bazel @@ -0,0 +1,12 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "types", + srcs = ["types.go"], + importpath = "github.com/sourcegraph/sourcegraph/enterprise/internal/own/types", + visibility = ["//enterprise:__subpackages__"], + deps = [ + "//enterprise/internal/own/codeowners/v1:codeowners", + "//internal/api", + ], +) diff --git a/enterprise/internal/own/types/types.go b/enterprise/internal/own/types/types.go new file mode 100644 index 00000000000..096b9675520 --- /dev/null +++ b/enterprise/internal/own/types/types.go @@ -0,0 +1,17 @@ +package types + +import ( + "time" + + codeownerspb "github.com/sourcegraph/sourcegraph/enterprise/internal/own/codeowners/v1" + "github.com/sourcegraph/sourcegraph/internal/api" +) + +type CodeownersFile struct { + CreatedAt time.Time + UpdatedAt time.Time + + RepoID api.RepoID + Contents string + Proto *codeownerspb.File +} diff --git a/enterprise/internal/search/BUILD.bazel b/enterprise/internal/search/BUILD.bazel index 4ed3d635a1c..ceabe359e79 100644 --- a/enterprise/internal/search/BUILD.bazel +++ b/enterprise/internal/search/BUILD.bazel @@ -6,7 +6,7 @@ go_library( importpath = "github.com/sourcegraph/sourcegraph/enterprise/internal/search", visibility = ["//enterprise:__subpackages__"], deps = [ - "//internal/own/search", + "//enterprise/internal/own/search", "//internal/search/job", "//internal/search/job/jobutil", ], diff --git a/enterprise/internal/search/jobs.go b/enterprise/internal/search/jobs.go index 77c7eb839e7..c30a065836b 100644 --- a/enterprise/internal/search/jobs.go +++ b/enterprise/internal/search/jobs.go @@ -1,7 +1,7 @@ package search import ( - "github.com/sourcegraph/sourcegraph/internal/own/search" + "github.com/sourcegraph/sourcegraph/enterprise/internal/own/search" "github.com/sourcegraph/sourcegraph/internal/search/job" "github.com/sourcegraph/sourcegraph/internal/search/job/jobutil" ) diff --git a/internal/search/result/BUILD.bazel b/internal/search/result/BUILD.bazel index 02ba67ab834..e5dac71d7ae 100644 --- a/internal/search/result/BUILD.bazel +++ b/internal/search/result/BUILD.bazel @@ -24,7 +24,6 @@ go_library( "//internal/api", "//internal/gitserver/gitdomain", "//internal/lazyregexp", - "//internal/own/codeowners", "//internal/search/filter", "//internal/types", "//lib/errors", diff --git a/internal/search/result/owner.go b/internal/search/result/owner.go index 149df6cb09a..e011db00424 100644 --- a/internal/search/result/owner.go +++ b/internal/search/result/owner.go @@ -2,13 +2,45 @@ package result import ( "github.com/sourcegraph/sourcegraph/internal/api" - "github.com/sourcegraph/sourcegraph/internal/own/codeowners" "github.com/sourcegraph/sourcegraph/internal/search/filter" "github.com/sourcegraph/sourcegraph/internal/types" ) +type Owner interface { + Type() string + Identifier() string +} + +type OwnerPerson struct { + Handle string + Email string + User *types.User +} + +func (o OwnerPerson) Identifier() string { + return "Person:" + o.Handle + o.Email +} + +func (o OwnerPerson) Type() string { + return "person" +} + +type OwnerTeam struct { + Handle string + Email string + Team *types.Team +} + +func (o OwnerTeam) Identifier() string { + return "Team:" + o.Team.Name +} + +func (o OwnerTeam) Type() string { + return "team" +} + type OwnerMatch struct { - ResolvedOwner codeowners.ResolvedOwner + ResolvedOwner Owner // The following contain information about what search the owner was matched from. InputRev *string `json:"-"` @@ -53,7 +85,7 @@ func (om *OwnerMatch) Key() Key { Commit: om.CommitID, } if om.ResolvedOwner != nil { - k.OwnerMetadata = string(om.ResolvedOwner.Type()) + om.ResolvedOwner.Identifier() + k.OwnerMetadata = om.ResolvedOwner.Type() + om.ResolvedOwner.Identifier() } if om.InputRev != nil { k.Rev = *om.InputRev diff --git a/internal/types/BUILD.bazel b/internal/types/BUILD.bazel index 095cecab747..078c1e6daa4 100644 --- a/internal/types/BUILD.bazel +++ b/internal/types/BUILD.bazel @@ -24,7 +24,6 @@ go_library( "//internal/executor", "//internal/extsvc", "//internal/jsonc", - "//internal/own/codeowners/v1:codeowners", "//lib/errors", "//schema", "@com_github_google_uuid//:uuid", diff --git a/internal/types/types.go b/internal/types/types.go index 3c0e649ca3b..b9310d606ee 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -15,7 +15,6 @@ import ( "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/encryption" "github.com/sourcegraph/sourcegraph/internal/extsvc" - codeownerspb "github.com/sourcegraph/sourcegraph/internal/own/codeowners/v1" ) // BatchChangeSource represents how a batch change can be created @@ -1888,15 +1887,6 @@ type TeamMember struct { UpdatedAt time.Time } -type CodeownersFile struct { - CreatedAt time.Time - UpdatedAt time.Time - - RepoID api.RepoID - Contents string - Proto *codeownerspb.File -} - type AccessRequestStatus string type AccessRequest struct { diff --git a/migrations/BUILD.bazel b/migrations/BUILD.bazel index 043452f9a91..90fc7d1d5c9 100644 --- a/migrations/BUILD.bazel +++ b/migrations/BUILD.bazel @@ -733,6 +733,12 @@ go_library( "frontend/1677627566_add_index_to_reference_scan_column/down.sql", "frontend/1677627566_add_index_to_reference_scan_column/metadata.yaml", "frontend/1677627566_add_index_to_reference_scan_column/up.sql", + "frontend/1677694168_add_vulnerability_tables/down.sql", + "frontend/1677694168_add_vulnerability_tables/metadata.yaml", + "frontend/1677694168_add_vulnerability_tables/up.sql", + "frontend/1677694170_add_vulnerability_match_tables/down.sql", + "frontend/1677694170_add_vulnerability_match_tables/metadata.yaml", + "frontend/1677694170_add_vulnerability_match_tables/up.sql", ], importpath = "github.com/sourcegraph/sourcegraph/migrations", visibility = ["//visibility:public"],