Skip to content

Commit

Permalink
Merge pull request #115 from gardener/fixgithubinfo
Browse files Browse the repository at this point in the history
Do not panic when all git commits are internal
  • Loading branch information
g-pavlov authored Nov 17, 2020
2 parents d2e8020 + ba8c9fd commit e0153c3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (r *gitInfoReader) Read(ctx context.Context, source string) ([]byte, error)
return nil, nil
}

// NewGitInfoController creates Controller object for wokring with GitHub info
// NewGitInfoController creates Controller object for wokring with Git info
func NewGitInfoController(reader Reader, writer writers.Writer, workersCount int, failFast bool, rhs resourcehandlers.Registry) GitInfoController {
if reader == nil {
reader = &gitInfoReader{
Expand All @@ -75,7 +75,7 @@ func NewGitInfoController(reader Reader, writer writers.Writer, workersCount int
}

job := &jobs.Job{
ID: "GitHubInfo",
ID: "GitInfo",
FailFast: failFast,
MaxWorkers: workersCount,
MinWorkers: workersCount,
Expand Down Expand Up @@ -117,9 +117,10 @@ func (d *gitInfoWorker) Work(ctx context.Context, ctrl *gitInfoController, task
if info, err = d.Read(ctx, s); err != nil {
return jobs.NewWorkerError(err, 0)
}
if info != nil {
b.Write(info)
if info == nil {
continue
}
b.Write(info)
if err := ctrl.updateContributors(info); err != nil {
return jobs.NewWorkerError(err, 0)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/resourcehandlers/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (fs *fsHandler) ReadGitInfo(ctx context.Context, uri string) ([]byte, error
}

if len(log) == 0 {
return []byte(""), nil
return nil, nil
}

for _, logEntry := range log {
Expand Down
3 changes: 3 additions & 0 deletions pkg/resourcehandlers/github/github_resource_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,9 @@ func (gh *GitHub) ReadGitInfo(ctx context.Context, uri string) ([]byte, error) {
}
if commits != nil {
gitInfo := transform(commits)
if gitInfo == nil {
return nil, nil
}
if blob, err = marshallGitInfo(gitInfo); err != nil {
return nil, err
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/resourcehandlers/github/gitinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import (
)

func transform(commits []*github.RepositoryCommit) *git.GitInfo {
if commits == nil {
return nil
}
gitInfo := &git.GitInfo{}
nonInternalCommits := []*github.RepositoryCommit{}
// skip internal commits
Expand All @@ -24,7 +27,7 @@ func transform(commits []*github.RepositoryCommit) *git.GitInfo {
nonInternalCommits = append(nonInternalCommits, commit)
}
}
if len(commits) == 0 {
if len(nonInternalCommits) == 0 {
return nil
}
sort.Slice(nonInternalCommits, func(i, j int) bool {
Expand Down

0 comments on commit e0153c3

Please sign in to comment.