Skip to content

Commit

Permalink
fix: warning when can't find prev or next commit ID (#1462)
Browse files Browse the repository at this point in the history
When previous or next commit id is provided but kuberpult does not find
the folder for those commits, previously we were throwing an error. Now
we simply log a warning and move on.

---------

Co-authored-by: Sven Urbanski <[email protected]>
  • Loading branch information
1 parent fff7fda commit 006f7b4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions services/cd-service/pkg/repository/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,12 +559,12 @@ func writeCommitData(ctx context.Context, sourceCommitId string, sourceMessage s
}

if previousCommitId != "" {
if err := writeNextPrevInfo(sourceCommitId, strings.ToLower(previousCommitId), fieldPreviousCommitId, fs); err != nil {
if err := writeNextPrevInfo(ctx, sourceCommitId, strings.ToLower(previousCommitId), fieldPreviousCommitId, app, fs); err != nil {
return GetCreateReleaseGeneralFailure(err)
}
}
if nextCommitId != "" {
if err := writeNextPrevInfo(sourceCommitId, strings.ToLower(nextCommitId), fieldNextCommidId, fs); err != nil {
if err := writeNextPrevInfo(ctx, sourceCommitId, strings.ToLower(nextCommitId), fieldNextCommidId, app, fs); err != nil {
return GetCreateReleaseGeneralFailure(err)
}
}
Expand Down Expand Up @@ -596,15 +596,17 @@ func writeCommitData(ctx context.Context, sourceCommitId string, sourceMessage s
return nil
}

func writeNextPrevInfo(sourceCommitId string, otherCommitId string, fieldSource string, fs billy.Filesystem) error {
func writeNextPrevInfo(ctx context.Context, sourceCommitId string, otherCommitId string, fieldSource string, application string, fs billy.Filesystem) error {

otherCommitId = strings.ToLower(otherCommitId)
sourceCommitDir := commitDirectory(fs, sourceCommitId)

otherCommitDir := commitDirectory(fs, otherCommitId)

if _, err := fs.Stat(otherCommitDir); err != nil {
return err
logger.FromContext(ctx).Sugar().Warnf(
"Could not find the previous commit while trying to create a new release for commit %s and application %s. This is expected when `git.enableWritingCommitData` was just turned on, however it should not happen multiple times.", otherCommitId, application, otherCommitDir)
return nil
}

if err := util.WriteFile(fs, fs.Join(sourceCommitDir, fieldSource), []byte(otherCommitId), 0666); err != nil {
Expand Down

0 comments on commit 006f7b4

Please sign in to comment.