diff --git a/service/repo/repo.go b/service/repo/repo.go index 1835a37f..9a578c51 100644 --- a/service/repo/repo.go +++ b/service/repo/repo.go @@ -57,7 +57,9 @@ func (s *service) List(ctx context.Context, user *core.User) ([]*core.Repository return nil, err } for _, src := range result { - repos = append(repos, convertRepository(src, s.visibility, s.trusted)) + if src != nil { + repos = append(repos, convertRepository(src, s.visibility, s.trusted)) + } } opts.Page = meta.Page.Next opts.URL = meta.Page.NextURL diff --git a/service/repo/repo_test.go b/service/repo/repo_test.go index 210d3d49..299c79a1 100644 --- a/service/repo/repo_test.go +++ b/service/repo/repo_test.go @@ -246,3 +246,44 @@ func TestList_RefreshErr(t *testing.T) { t.Errorf("Expect error refreshing token") } } + +func TestListWithNilRepo(t *testing.T) { + controller := gomock.NewController(t) + defer controller.Finish() + + mockUser := &core.User{} + mockRepos := []*scm.Repository{ + { + Namespace: "octocat", + Name: "hello-world", + }, + nil, + } + + mockRepoService := mockscm.NewMockRepositoryService(controller) + mockRepoService.EXPECT().List(gomock.Any(), gomock.Any()).Return(mockRepos, &scm.Response{}, nil) + + mockRenewer := mock.NewMockRenewer(controller) + mockRenewer.EXPECT().Renew(gomock.Any(), mockUser, false) + + client := new(scm.Client) + client.Repositories = mockRepoService + + want := []*core.Repository{ + { + Namespace: "octocat", + Name: "hello-world", + Slug: "octocat/hello-world", + Visibility: "public", + }, + } + + service := New(client, mockRenewer, "", false) + got, err := service.List(noContext, mockUser) + if err != nil { + t.Error(err) + } + if diff := cmp.Diff(got, want); diff != "" { + t.Errorf(diff) + } +} diff --git a/service/syncer/syncer.go b/service/syncer/syncer.go index af148fc3..d65bc374 100644 --- a/service/syncer/syncer.go +++ b/service/syncer/syncer.go @@ -16,6 +16,7 @@ package syncer import ( "context" + "runtime/debug" "strings" "time" @@ -67,6 +68,7 @@ func (s *Synchronizer) Sync(ctx context.Context, user *core.User) (*core.Batch, if err := recover(); err != nil { logger = logger.WithField("error", err) logger.Errorln("syncer: unexpected panic") + debug.PrintStack() } // when the synchronization process is complete