feat(ci): Added woodpecker-ci provider

This commit is contained in:
2024-04-01 23:41:26 +13:00
parent 2236fe923c
commit 141f297c87
2 changed files with 47 additions and 4 deletions

View File

@@ -10,7 +10,7 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
//ProviderConfig struct // ProviderConfig struct
type ProviderConfig struct { type ProviderConfig struct {
IsPR bool IsPR bool
PR string PR string
@@ -23,12 +23,12 @@ type ProviderConfig struct {
Name string Name string
} }
//Service interface // Service interface
type Service interface { type Service interface {
detect(envs map[string]string) (*ProviderConfig, error) detect(envs map[string]string) (*ProviderConfig, error)
} }
//ReadAllEnvs as a map // ReadAllEnvs as a map
func ReadAllEnvs() map[string]string { func ReadAllEnvs() map[string]string {
envs := map[string]string{} envs := map[string]string{}
for _, pair := range os.Environ() { for _, pair := range os.Environ() {
@@ -38,13 +38,14 @@ func ReadAllEnvs() map[string]string {
return envs return envs
} }
//GetCIProvider get provider // GetCIProvider get provider
func GetCIProvider(gitUtil *gitutil.GitUtil, configCheck bool, envs map[string]string) (*ProviderConfig, error) { func GetCIProvider(gitUtil *gitutil.GitUtil, configCheck bool, envs map[string]string) (*ProviderConfig, error) {
services := []Service{ services := []Service{
Travis{}, Travis{},
GithubActions{}, GithubActions{},
GitlabCI{}, GitlabCI{},
WoodpeckerCI{},
Git{gitUtil: gitUtil}, // Git must be the last option to check Git{gitUtil: gitUtil}, // Git must be the last option to check
} }

42
internal/ci/woodpecker.go Normal file
View File

@@ -0,0 +1,42 @@
package ci
import (
"fmt"
log "github.com/sirupsen/logrus"
)
// Travis struct
type WoodpeckerCI struct{}
// Detect if on travis
func (t WoodpeckerCI) detect(envs map[string]string) (*ProviderConfig, error) {
if envs["CI"] != "woodpecker" {
return nil, fmt.Errorf("not running on woodpecker")
}
isPR := false
value := envs["CI_COMMIT_PULL_REQUEST"]
pr := ""
if value == "" {
log.Debugf("CI_COMMIT_PULL_REQUEST=%s, not running on pr", value)
} else {
isPR = true
pr = value
}
return &ProviderConfig{
Service: "woodpecker",
Name: "Woodpecker CI",
Commit: envs["CI_COMMIT_SHA"],
Tag: envs["CI_COMMIT_TAG"],
BuildURL: envs["CI_PIPELINE_URL"],
Branch: envs["CI_COMMIT_BRANCH"],
IsPR: isPR,
PR: pr,
PRBranch: envs["CI_COMMIT_SOURCE_BRANCH"],
}, nil
}