(feat) ignore archive repos on sync (#3178)

* (feat) ignore archive repos on sync
This commit is contained in:
Eoin McAfee 2022-01-10 10:49:37 +00:00 committed by GitHub
parent 3398f2eb57
commit 7e757c4a3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 61 additions and 1 deletions

View file

@ -65,6 +65,7 @@ type (
Secret string `json:"-"`
Build *Build `json:"build,omitempty"`
Perms *Perm `json:"permissions,omitempty"`
Archived bool `json:"archived"`
}
RepoBuildStage struct {

2
go.mod
View file

@ -20,7 +20,7 @@ require (
github.com/drone/funcmap v0.0.0-20210823160631-9e9dec149056
github.com/drone/go-license v1.0.2
github.com/drone/go-login v1.1.0
github.com/drone/go-scm v1.16.3
github.com/drone/go-scm v1.17.0
github.com/drone/signal v1.0.0
github.com/dustin/go-humanize v1.0.0
github.com/go-chi/chi v3.3.3+incompatible

2
go.sum
View file

@ -100,6 +100,8 @@ github.com/drone/go-scm v1.16.2 h1:IoxgyIACUArg3d7US8OR1Vwsph3U/x7imNTU5QK47C4=
github.com/drone/go-scm v1.16.2/go.mod h1:DFIJJjhMj0TSXPz+0ni4nyZ9gtTtC40Vh/TGRugtyWw=
github.com/drone/go-scm v1.16.3 h1:jm8xSGv5vVfaVhPY7Dswjq2EdNm0HTDVCQ+/Lqe7KPM=
github.com/drone/go-scm v1.16.3/go.mod h1:DFIJJjhMj0TSXPz+0ni4nyZ9gtTtC40Vh/TGRugtyWw=
github.com/drone/go-scm v1.17.0 h1:Yg0IxA8XAIgAohcQy7S1P9D3Sd6sJq3dNMI7uajwXhQ=
github.com/drone/go-scm v1.17.0/go.mod h1:DFIJJjhMj0TSXPz+0ni4nyZ9gtTtC40Vh/TGRugtyWw=
github.com/drone/signal v1.0.0 h1:NrnM2M/4yAuU/tXs6RP1a1ZfxnaHwYkd0kJurA1p6uI=
github.com/drone/signal v1.0.0/go.mod h1:S8t92eFT0g4WUgEc/LxG+LCuiskpMNsG0ajAMGnyZpc=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=

View file

@ -35,6 +35,7 @@ func convertRepository(src *scm.Repository, visibility string, trusted bool) *co
Visibility: convertVisibility(src, visibility),
Branch: src.Branch,
Trusted: trusted,
Archived: src.Archived,
}
}

View file

@ -110,6 +110,13 @@ func (s *Synchronizer) Sync(ctx context.Context, user *core.User) (*core.Batch,
WithField("uid", repo.UID).
Traceln("syncer: skipping subrepositories")
}
} else if repo.Archived {
if logrus.GetLevel() == logrus.TraceLevel {
logger.WithField("namespace", repo.Namespace).
WithField("name", repo.Name).
WithField("uid", repo.UID).
Traceln("syncer: skipping archived repositories")
}
} else if s.match(repo) {
remote[repo.UID] = repo
if logrus.GetLevel() == logrus.TraceLevel {

View file

@ -434,3 +434,52 @@ func TestSync_SkipSubrepo(t *testing.T) {
t.Errorf(diff)
}
}
func TestSyncArchive(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,
Archived: true,
},
}, nil)
s := New(
repoService,
repoStore,
userStore,
batcher,
)
got, err := s.Sync(context.Background(), user)
if err != nil {
t.Error(err)
}
want := &core.Batch{}
ignore := cmpopts.IgnoreFields(core.Repository{},
"Synced", "Created", "Updated")
if diff := cmp.Diff(got, want, ignore); len(diff) != 0 {
t.Errorf(diff)
}
}