ignore gitlab surepositories

This commit is contained in:
Brad Rydzewski 2020-02-27 14:09:56 -08:00
parent 664da1d436
commit aead279caf
2 changed files with 57 additions and 2 deletions

View file

@ -16,6 +16,7 @@ package syncer
import ( import (
"context" "context"
"strings"
"time" "time"
"github.com/drone/drone/core" "github.com/drone/drone/core"
@ -102,7 +103,14 @@ func (s *Synchronizer) Sync(ctx context.Context, user *core.User) (*core.Batch,
return nil, err return nil, err
} }
for _, repo := range repos { 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 remote[repo.UID] = repo
if logrus.GetLevel() == logrus.TraceLevel { if logrus.GetLevel() == logrus.TraceLevel {
logger.WithField("namespace", repo.Namespace). logger.WithField("namespace", repo.Namespace).

View file

@ -259,7 +259,7 @@ func TestSync_Revoke(t *testing.T) {
// this test verifies that we invoke the batch update even // this test verifies that we invoke the batch update even
// if there are no batch updates to make. This is important // if there are no batch updates to make. This is important
// because the batcher resets permissions and forces Drone // because the batcher resets permissions and forces Drone
// to re-synchrnoize. // to re-synchronize.
func TestSync_EmptyBatch(t *testing.T) { func TestSync_EmptyBatch(t *testing.T) {
controller := gomock.NewController(t) controller := gomock.NewController(t)
defer controller.Finish() defer controller.Finish()
@ -387,3 +387,50 @@ func TestSync_BatchError(t *testing.T) {
t.Errorf("Want error %s, got %s", want, got) 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)
}
}