From aead279caf225aabd0b41e08caa9d62f5bdf6ff8 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Thu, 27 Feb 2020 14:09:56 -0800 Subject: [PATCH] ignore gitlab surepositories --- service/syncer/syncer.go | 10 ++++++- service/syncer/syncer_test.go | 49 ++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/service/syncer/syncer.go b/service/syncer/syncer.go index 9b25afe4..83308c5c 100644 --- a/service/syncer/syncer.go +++ b/service/syncer/syncer.go @@ -16,6 +16,7 @@ package syncer import ( "context" + "strings" "time" "github.com/drone/drone/core" @@ -102,7 +103,14 @@ func (s *Synchronizer) Sync(ctx context.Context, user *core.User) (*core.Batch, return nil, err } for _, repo := range repos { - if s.match(repo) { + if strings.Count(repo.Slug, "/") > 1 { + if logrus.GetLevel() == logrus.TraceLevel { + logger.WithField("namespace", repo.Namespace). + WithField("name", repo.Name). + WithField("uid", repo.UID). + Traceln("syncer: skipping subrepositories") + } + } else if s.match(repo) { remote[repo.UID] = repo if logrus.GetLevel() == logrus.TraceLevel { logger.WithField("namespace", repo.Namespace). diff --git a/service/syncer/syncer_test.go b/service/syncer/syncer_test.go index 968ba875..4b8640e6 100644 --- a/service/syncer/syncer_test.go +++ b/service/syncer/syncer_test.go @@ -259,7 +259,7 @@ func TestSync_Revoke(t *testing.T) { // this test verifies that we invoke the batch update even // if there are no batch updates to make. This is important // because the batcher resets permissions and forces Drone -// to re-synchrnoize. +// to re-synchronize. func TestSync_EmptyBatch(t *testing.T) { controller := gomock.NewController(t) defer controller.Finish() @@ -387,3 +387,50 @@ func TestSync_BatchError(t *testing.T) { t.Errorf("Want error %s, got %s", want, got) } } + +// this test verifies that sub-repositories are skipped. They +// are unsupported by Drone and should not be ignored. +func TestSync_SkipSubrepo(t *testing.T) { + controller := gomock.NewController(t) + defer controller.Finish() + + user := &core.User{ID: 1} + + userStore := mock.NewMockUserStore(controller) + userStore.EXPECT().Update(gomock.Any(), user).Return(nil) + userStore.EXPECT().Update(gomock.Any(), user).Return(nil) + + batcher := mock.NewMockBatcher(controller) + batcher.EXPECT().Batch(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) + + repoStore := mock.NewMockRepositoryStore(controller) + repoStore.EXPECT().List(gomock.Any(), gomock.Any()).Return([]*core.Repository{}, nil) + + repoService := mock.NewMockRepositoryService(controller) + repoService.EXPECT().List(gomock.Any(), user).Return([]*core.Repository{ + { + UID: "1", + Slug: "octocat/hello/world", + Namespace: "octocat", + Name: "hello-world", + Private: false, + Visibility: core.VisibilityPublic, + }, + }, nil) + + s := New( + repoService, + repoStore, + userStore, + batcher, + ) + got, err := s.Sync(context.Background(), user) + if err != nil { + t.Error(err) + } + + want := &core.Batch{} + if diff := cmp.Diff(got, want); len(diff) != 0 { + t.Errorf(diff) + } +}