Skip to content

Commit

Permalink
Don't parse forge config files multiple times if no error occured (#4272
Browse files Browse the repository at this point in the history
) (#4273)

Co-authored-by: Patrick Schratz <[email protected]>
  • Loading branch information
6543 and pat-s authored Oct 29, 2024
1 parent c427886 commit 3a1c3e7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions server/services/config/forge.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ func (f *forgeFetcher) Fetch(ctx context.Context, forge forge.Forge, user *model
for i := 0; i < int(f.retryCount); i++ {
files, err = ffc.fetch(ctx, strings.TrimSpace(repo.Config))
if err != nil {
log.Trace().Err(err).Msgf("%d. try failed", i+1)
}
if errors.Is(err, context.DeadlineExceeded) {
continue
log.Trace().Err(err).Msgf("Fetching config files: Attempt #%d failed", i+1)
} else {
break
}
}

Expand Down
4 changes: 2 additions & 2 deletions server/services/config/forge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func TestFetch(t *testing.T) {
f := new(mocks.Forge)
dirs := map[string][]*forge_types.FileMeta{}
for _, file := range tt.files {
f.On("File", mock.Anything, mock.Anything, mock.Anything, mock.Anything, file.name).Return(file.data, nil)
f.On("File", mock.Anything, mock.Anything, mock.Anything, mock.Anything, file.name).Once().Return(file.data, nil)
path := filepath.Dir(file.name)
if path != "." {
dirs[path] = append(dirs[path], &forge_types.FileMeta{
Expand All @@ -298,7 +298,7 @@ func TestFetch(t *testing.T) {
}

for path, files := range dirs {
f.On("Dir", mock.Anything, mock.Anything, mock.Anything, mock.Anything, path).Return(files, nil)
f.On("Dir", mock.Anything, mock.Anything, mock.Anything, mock.Anything, path).Once().Return(files, nil)
}

// if the previous mocks do not match return not found errors
Expand Down

0 comments on commit 3a1c3e7

Please sign in to comment.