If config is no dir asume its a folder (#354)

If config is no dir assume its a folder (user do not always add / suffix)
This commit is contained in:
6543 2021-09-25 02:56:05 +02:00 committed by GitHub
parent 4df9c8d6a5
commit d8cd4925ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -26,14 +26,15 @@ func NewConfigFetcher(remote remote.Remote, user *model.User, repo *model.Repo,
func (cf *configFetcher) Fetch() (files []*remote.FileMeta, err error) { func (cf *configFetcher) Fetch() (files []*remote.FileMeta, err error) {
var file []byte var file []byte
config := strings.TrimSpace(cf.repo.Config)
for i := 0; i < 5; i++ { for i := 0; i < 5; i++ {
select { select {
case <-time.After(time.Second * time.Duration(i)): case <-time.After(time.Second * time.Duration(i)):
if len(cf.repo.Config) > 0 { if len(cf.repo.Config) > 0 {
// either a file // either a file
if !strings.HasSuffix(cf.repo.Config, "/") { if !strings.HasSuffix(config, "/") {
file, err = cf.remote_.File(cf.user, cf.repo, cf.build, cf.repo.Config) file, err = cf.remote_.File(cf.user, cf.repo, cf.build, config)
if err == nil { if err == nil {
return []*remote.FileMeta{{ return []*remote.FileMeta{{
Name: cf.repo.Config, Name: cf.repo.Config,
@ -43,12 +44,10 @@ func (cf *configFetcher) Fetch() (files []*remote.FileMeta, err error) {
} }
// or a folder // or a folder
if strings.HasSuffix(cf.repo.Config, "/") { files, err = cf.remote_.Dir(cf.user, cf.repo, cf.build, strings.TrimSuffix(config, "/"))
files, err = cf.remote_.Dir(cf.user, cf.repo, cf.build, strings.TrimSuffix(cf.repo.Config, "/"))
if err == nil { if err == nil {
return filterPipelineFiles(files), nil return filterPipelineFiles(files), nil
} }
}
} else { } else {
// no user defined config so try .woodpecker/*.yml -> .woodpecker.yml -> .drone.yml // no user defined config so try .woodpecker/*.yml -> .woodpecker.yml -> .drone.yml