This repository has been archived on 2025-11-20. You can view files and clone it, but cannot push or open issues or pull requests.
Files
drone-runner-podman/engine/resource/lookup.go
2019-11-08 11:24:38 -08:00

32 lines
780 B
Go

// Copyright 2019 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by the Polyform License
// that can be found in the LICENSE file.
package resource
import (
"errors"
"github.com/drone/runner-go/manifest"
)
// Lookup returns the named pipeline from the Manifest.
func Lookup(name string, manifest *manifest.Manifest) (*Pipeline, error) {
for _, resource := range manifest.Resources {
if !isNameMatch(resource.GetName(), name) {
continue
}
if pipeline, ok := resource.(*Pipeline); ok {
return pipeline, nil
}
}
return nil, errors.New("resource not found")
}
// helper function returns true if the name matches.
func isNameMatch(a, b string) bool {
return a == b ||
(a == "" && b == "default") ||
(b == "" && a == "default")
}