Add Commit struct

This commit is contained in:
Don 2019-09-09 16:16:32 -07:00
parent ac3fef34db
commit 62b9912e0b
2 changed files with 72 additions and 0 deletions

View File

@ -22,6 +22,7 @@ import (
const (
// The following environment variables are being ignored currently
//
// * DRONE_COMMIT - Redundant with DRONE_COMMIT_SHA
// * DRONE_GIT_HTTP_URL
// * DRONE_GIT_SSH_URL
// * DRONE_REPO_NAMESPACE - Redundant to DRONE_REPO_OWNER
@ -49,6 +50,33 @@ const (
// RepoVisibilityEnvVar corresponds to Repo.Visbility.
RepoVisibilityEnvVar = "DRONE_REPO_VISIBILITY"
//---------------------------------------------------------------------
// Commit Enviornment Variables
//---------------------------------------------------------------------
// CommitAfterEnvVar corresponds to Commit.After.
CommitAfterEnvVar = "DRONE_COMMIT_AFTER"
// CommitAuthorEnvVar corresponds to Commit.Author.
CommitAuthorEnvVar = "DRONE_COMMIT_AUTHOR"
// CommitAuthorAvatarEnvVar corresponds to Commit.AuthorAvatar.
CommitAuthorAvatarEnvVar = "DRONE_COMMIT_AUTHOR_AVATAR"
// CommitAuthorEmailEnvVar corresponds to Commit.AuthorEmail.
CommitAuthorEmailEnvVar = "DRONE_COMMIT_AUTHOR_EMAIL"
// CommitAuthorNameEnvVar corresponds to Commit.AuthorName.
CommitAuthorNameEnvVar = "DRONE_COMMIT_AUTHOR_NAME"
// CommitBeforeEnvVar corresponds to Commit.Before.
CommitBeforeEnvVar = "DRONE_COMMIT_BEFORE"
// CommitBranchEnvVar corresponds to Commit.Branch.
CommitBranchEnvVar = "DRONE_COMMIT_BRANCH"
// CommitLinkEnvVar corresponds to Commit.Link.
CommitLinkEnvVar = "DRONE_COMMIT_LINK"
// CommitMessageEnvVar corresponds to Commit.Message.
CommitMessageEnvVar = "DRONE_COMMIT_MESSAGE"
// CommitRefEnvVar corresponds to Commit.Ref.
CommitRefEnvVar = "DRONE_COMMIT_REF"
// CommitSHAEnvVar corresponds to Commit.SHA.
CommitSHAEnvVar = "DRONE_COMMIT_SHA"
//---------------------------------------------------------------------
// Stage Enviornment Variables
//---------------------------------------------------------------------

View File

@ -40,6 +40,33 @@ type (
Visibility string
}
// Commit represents the current commit being built.
Commit struct {
// After contains the commit sha after the patch is applied.
After string
// Author of the commit.
Author string
// AuthorAvatar of the commit.
AuthorAvatar string
// AuthorEmail of the commit.
AuthorEmail string
// AuthorName of the commit.
AuthorName string
// Before contains the commit sha before the patch is applied.
Before string
// Branch target for the push or pull request. This may be empty for
// tag events.
Branch string
// Link to the commit or object in the source control management system.
Link string
// Message for the current commit.
Message string
// Ref for the current commit.
Ref string
// SHA for the current commit.
SHA string
}
// Stage represents a build stage.
Stage struct {
// Arch is the platform architecture of the current build stage.
@ -142,6 +169,23 @@ func RepoFromEnv() Repo {
}
}
// CommitFromEnv creates a Commit from the environment variables used by Drone.
func CommitFromEnv() Commit {
return Commit{
After: StringEnvVar(CommitAfterEnvVar),
Author: StringEnvVar(CommitAuthorEnvVar),
AuthorAvatar: StringEnvVar(CommitAuthorAvatarEnvVar),
AuthorEmail: StringEnvVar(CommitAuthorEmailEnvVar),
AuthorName: StringEnvVar(CommitAuthorNameEnvVar),
Before: StringEnvVar(CommitBeforeEnvVar),
Branch: StringEnvVar(CommitBranchEnvVar),
Link: StringEnvVar(CommitLinkEnvVar),
Message: StringEnvVar(CommitMessageEnvVar),
Ref: StringEnvVar(CommitRefEnvVar),
SHA: StringEnvVar(CommitSHAEnvVar),
}
}
// StageFromEnv creates a Stage from the environment variables used by Drone.
func StageFromEnv() Stage {
return Stage{