Add Build struct

This commit is contained in:
Don 2019-09-09 16:54:52 -07:00
parent b9b4a23880
commit 703857da2f
2 changed files with 91 additions and 0 deletions

View File

@ -27,6 +27,41 @@ const (
// * DRONE_GIT_SSH_URL
// * DRONE_REPO_NAMESPACE - Redundant to DRONE_REPO_OWNER
//---------------------------------------------------------------------
// Build Enviornment Variables
//---------------------------------------------------------------------
// BuildActionEnvVar corresponds to Build.Action.
BuildActionEnvVar = "DRONE_BUILD_ACTION"
// BuildCreatedEnvVar corresponds to Build.Created.
BuildCreatedEnvVar = "DRONE_BUILD_CREATED"
// BuildEventEnvVar corresponds to Build.Event.
BuildEventEnvVar = "DRONE_BUILD_EVENT"
// BuildFinishedEnvVar corresponds to Build.Finished.
BuildFinishedEnvVar = "DRONE_BUILD_FINISHED"
// BuildNumberEnvVar corresponds to Build.Created.
BuildNumberEnvVar = "DRONE_BUILD_NUMBER"
// BuildParentEnvVar corresponds to Build.Parent.
BuildParentEnvVar = "DRONE_BUILD_PARENT"
// BuildStartedEnvVar corresponds to Build.Started.
BuildStartedEnvVar = "DRONE_BUILD_STARTED"
// BuildStatusEnvVar corresponds to Build.Status.
BuildStatusEnvVar = "DRONE_BUILD_STATUS"
// BuildDeployToEnvVar corresponds to Build.DeployTo.
BuildDeployToEnvVar = "DRONE_DEPLOY_TO"
// BuildFailedStagesEnvVar corresponds to Build.FailedStages.
BuildFailedStagesEnvVar = "DRONE_FAILED_STAGES"
// BuildFailedStepsEnvVar corresponds to Build.FailedSteps.
BuildFailedStepsEnvVar = "DRONE_FAILED_STEPS"
// BuildPullRequestEnvVar corresponds to Build.PullRequest.
BuildPullRequestEnvVar = "DRONE_PULL_REQUEST"
// BuildSourceBranchEnvVar corresponds to Build.SourceBranch.
BuildSourceBranchEnvVar = "DRONE_SOURCE_BRANCH"
// BuildTagEnvVar corresponds to Build.Tag.
BuildTagEnvVar = "DRONE_TAG"
// BuildTargetBranchEnvVar corresponds to Build.TargetBranch.
BuildTargetBranchEnvVar = "DRONE_TARGET_BRANCH"
//---------------------------------------------------------------------
// Repo Enviornment Variables
//---------------------------------------------------------------------

View File

@ -27,6 +27,41 @@ type (
Step Step
}
// Build represents a build of a repository.
Build struct {
// Action that triggered the build. This value is used to differentiate
// bettween a pull request being opened vs synchronized.
Action string
// Created time of the build.
Created time.Time
// Event that triggered the build.
Event string
// Finished time of the build.
Finished time.Time
// Number for the build.
Number int
// Parent build number for the build.
Parent int
// Started time of the build.
Started time.Time
// Status of the build.
Status string
// DeployTo the environment.
DeployTo string
// FailedStages of the build.
FailedStages []string
// FailedSteps of the build.
FailedSteps []string
// PullRequest number of the build.
PullRequest int
// SourceBranch for the pull request.
SourceBranch string
// Tag of the build.
Tag string
// TargetBranch for the pull request.
TargetBranch string
}
// Repo represents the repository for the build.
Repo struct {
DefaultBranch string
@ -154,6 +189,27 @@ type (
}
)
// BuildFromEnv creates a Build from the environment variables used by Drone.
func BuildFromEnv() Build {
return Build{
Action: StringEnvVar(BuildActionEnvVar),
Created: TimeEnvVar(BuildCreatedEnvVar),
Event: StringEnvVar(BuildEventEnvVar),
Finished: TimeEnvVar(BuildFinishedEnvVar),
Number: IntEnvVar(BuildNumberEnvVar),
Parent: IntEnvVar(BuildParentEnvVar),
Started: TimeEnvVar(BuildStartedEnvVar),
Status: StringEnvVar(BuildStatusEnvVar),
DeployTo: StringEnvVar(BuildDeployToEnvVar),
FailedStages: StringSliceEnvVar(BuildFailedStagesEnvVar),
FailedSteps: StringSliceEnvVar(BuildFailedStepsEnvVar),
PullRequest: IntEnvVar(BuildPullRequestEnvVar),
SourceBranch: StringEnvVar(BuildSourceBranchEnvVar),
Tag: StringEnvVar(BuildTagEnvVar),
TargetBranch: StringEnvVar(BuildTargetBranchEnvVar),
}
}
// RepoFromEnv creates a Repo from the environment variables used by Drone.
func RepoFromEnv() Repo {
return Repo{