2021-06-09 09:38:52 +02:00
|
|
|
package orchestrator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AzureDevOpsConfigProvider struct{}
|
|
|
|
|
2021-06-25 10:50:56 +02:00
|
|
|
func (a *AzureDevOpsConfigProvider) GetBranch() string {
|
|
|
|
tmp := os.Getenv("BUILD_SOURCEBRANCH")
|
|
|
|
return strings.TrimPrefix(tmp, "refs/heads/")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AzureDevOpsConfigProvider) GetBuildUrl() string {
|
|
|
|
return os.Getenv("SYSTEM_TEAMFOUNDATIONCOLLECTIONURI") + os.Getenv("SYSTEM_TEAMPROJECT") + "/_build/results?buildId=" + os.Getenv("BUILD_BUILDID")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AzureDevOpsConfigProvider) GetCommit() string {
|
|
|
|
return os.Getenv("BUILD_SOURCEVERSION")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AzureDevOpsConfigProvider) GetRepoUrl() string {
|
|
|
|
return os.Getenv("BUILD_REPOSITORY_URI")
|
|
|
|
}
|
|
|
|
|
2021-06-09 09:38:52 +02:00
|
|
|
func (a *AzureDevOpsConfigProvider) GetPullRequestConfig() PullRequestConfig {
|
2021-08-02 10:08:33 +02:00
|
|
|
prKey := os.Getenv("SYSTEM_PULLREQUEST_PULLREQUESTID")
|
|
|
|
|
|
|
|
// This variable is populated for pull requests which have a different pull request ID and pull request number.
|
|
|
|
// In this case the pull request ID will contain an internal numeric ID and the pull request number will be provided
|
|
|
|
// as part of the 'SYSTEM_PULLREQUEST_PULLREQUESTNUMBER' environment variable.
|
|
|
|
prNumber, prNumberEnvVarSet := os.LookupEnv("SYSTEM_PULLREQUEST_PULLREQUESTNUMBER")
|
|
|
|
if prNumberEnvVarSet == true {
|
|
|
|
prKey = prNumber
|
|
|
|
}
|
|
|
|
|
2021-06-09 09:38:52 +02:00
|
|
|
return PullRequestConfig{
|
|
|
|
Branch: os.Getenv("SYSTEM_PULLREQUEST_SOURCEBRANCH"),
|
|
|
|
Base: os.Getenv("SYSTEM_PULLREQUEST_TARGETBRANCH"),
|
2021-08-02 10:08:33 +02:00
|
|
|
Key: prKey,
|
2021-06-09 09:38:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AzureDevOpsConfigProvider) IsPullRequest() bool {
|
|
|
|
return os.Getenv("BUILD_REASON") == "PullRequest"
|
|
|
|
}
|
|
|
|
|
|
|
|
func isAzure() bool {
|
|
|
|
envVars := []string{"AZURE_HTTP_USER_AGENT"}
|
|
|
|
return areIndicatingEnvVarsSet(envVars)
|
|
|
|
}
|