1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-12 08:23:48 +02:00
woodpecker/server/configFetcher.go

54 lines
1.1 KiB
Go
Raw Normal View History

package server
import (
2019-06-24 09:04:30 +02:00
"strings"
"time"
2019-08-27 13:01:29 +02:00
"github.com/laszlocph/woodpecker/model"
"github.com/laszlocph/woodpecker/remote"
)
type configFetcher struct {
remote_ remote.Remote
user *model.User
repo *model.Repo
build *model.Build
}
func (cf *configFetcher) Fetch() ([]*remote.FileMeta, error) {
for i := 0; i < 5; i++ {
select {
case <-time.After(time.Second * time.Duration(i)):
2019-06-24 09:04:30 +02:00
// either a file
file, fileerr := cf.remote_.File(cf.user, cf.repo, cf.build, cf.repo.Config)
2019-06-05 10:08:49 +02:00
if fileerr == nil {
return []*remote.FileMeta{&remote.FileMeta{
Name: cf.repo.Config,
Data: file,
}}, nil
}
2019-06-24 09:04:30 +02:00
// or a folder
dir, direrr := cf.remote_.Dir(cf.user, cf.repo, cf.build, strings.TrimSuffix(cf.repo.Config, "/"))
if direrr == nil {
return dir, nil
} else if !cf.repo.Fallback {
2019-06-05 10:08:49 +02:00
return nil, direrr
}
2019-06-13 18:09:25 +02:00
// or fallback
file, fileerr = cf.remote_.File(cf.user, cf.repo, cf.build, ".drone.yml")
if fileerr != nil {
return nil, fileerr
}
return []*remote.FileMeta{&remote.FileMeta{
Name: cf.repo.Config,
Data: file,
}}, nil
}
}
return []*remote.FileMeta{}, nil
}