Don't parse forge config files multiple times if no error occured (#4272)

This commit is contained in:
Patrick Schratz 2024-10-29 01:57:37 +01:00 committed by GitHub
parent bd933669ef
commit 87bfe95c43
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 6 deletions

View file

@ -59,10 +59,9 @@ func (f *forgeFetcher) Fetch(ctx context.Context, forge forge.Forge, user *model
for i := 0; i < int(f.retryCount); i++ { for i := 0; i < int(f.retryCount); i++ {
files, err = ffc.fetch(ctx, strings.TrimSpace(repo.Config)) files, err = ffc.fetch(ctx, strings.TrimSpace(repo.Config))
if err != nil { if err != nil {
log.Trace().Err(err).Msgf("Attempt #%d failed", i+1) log.Trace().Err(err).Msgf("Fetching config files: Attempt #%d failed", i+1)
} } else {
if errors.Is(err, context.DeadlineExceeded) { break
continue
} }
} }

View file

@ -287,7 +287,7 @@ func TestFetch(t *testing.T) {
f := new(mocks.Forge) f := new(mocks.Forge)
dirs := map[string][]*forge_types.FileMeta{} dirs := map[string][]*forge_types.FileMeta{}
for _, file := range tt.files { 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) path := filepath.Dir(file.name)
if path != "." { if path != "." {
dirs[path] = append(dirs[path], &forge_types.FileMeta{ dirs[path] = append(dirs[path], &forge_types.FileMeta{
@ -298,7 +298,7 @@ func TestFetch(t *testing.T) {
} }
for path, files := range dirs { 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 // if the previous mocks do not match return not found errors