diff --git a/pkg/plugin/env.go b/pkg/plugin/env.go index 99d2c29..862d87e 100644 --- a/pkg/plugin/env.go +++ b/pkg/plugin/env.go @@ -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 //--------------------------------------------------------------------- diff --git a/pkg/plugin/types.go b/pkg/plugin/types.go index 1feed8d..6c14176 100644 --- a/pkg/plugin/types.go +++ b/pkg/plugin/types.go @@ -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{