Add all Drone env variables to template context
This commit is contained in:
parent
89bfb86f8f
commit
0888ac7f7e
10
defaults.go
10
defaults.go
|
@ -11,7 +11,7 @@ const (
|
||||||
|
|
||||||
// DefaultSubject is the default subject template to use for the email
|
// DefaultSubject is the default subject template to use for the email
|
||||||
const DefaultSubject = `
|
const DefaultSubject = `
|
||||||
[{{ build.status }}] {{ repo.owner }}/{{ repo.name }} ({{ build.branch }} - {{ truncate build.commit 8 }})
|
[{{ build.status }}] {{ repo.owner }}/{{ repo.name }} ({{ commit.branch }} - {{ truncate commit.sha 8 }})
|
||||||
`
|
`
|
||||||
|
|
||||||
// DefaultTemplate is the default body template to use for the email
|
// DefaultTemplate is the default body template to use for the email
|
||||||
|
@ -219,7 +219,7 @@ const DefaultTemplate = `
|
||||||
Author:
|
Author:
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ build.author.name }} ({{ build.author.email }})
|
{{ commit.author.name }} ({{ commit.author.email }})
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -227,7 +227,7 @@ const DefaultTemplate = `
|
||||||
Branch:
|
Branch:
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ build.branch }}
|
{{ commit.branch }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -235,7 +235,7 @@ const DefaultTemplate = `
|
||||||
Commit:
|
Commit:
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ truncate build.commit 8 }}
|
{{ truncate commit.sha 8 }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -251,7 +251,7 @@ const DefaultTemplate = `
|
||||||
<table width="100%" cellpadding="0" cellspacing="0">
|
<table width="100%" cellpadding="0" cellspacing="0">
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
{{ build.message }}
|
{{ commit.message }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
218
main.go
218
main.go
|
@ -76,6 +76,12 @@ func main() {
|
||||||
},
|
},
|
||||||
|
|
||||||
// Drone environment
|
// Drone environment
|
||||||
|
// Repo
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "repo.fullName",
|
||||||
|
Usage: "repository full name",
|
||||||
|
EnvVar: "DRONE_REPO",
|
||||||
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "repo.owner",
|
Name: "repo.owner",
|
||||||
Usage: "repository owner",
|
Usage: "repository owner",
|
||||||
|
@ -86,6 +92,47 @@ func main() {
|
||||||
Usage: "repository name",
|
Usage: "repository name",
|
||||||
EnvVar: "DRONE_REPO_NAME",
|
EnvVar: "DRONE_REPO_NAME",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "repo.scm",
|
||||||
|
Value: "git",
|
||||||
|
Usage: "respository scm",
|
||||||
|
EnvVar: "DRONE_REPO_SCM",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "repo.link",
|
||||||
|
Usage: "repository link",
|
||||||
|
EnvVar: "DRONE_REPO_LINK",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "repo.avatar",
|
||||||
|
Usage: "repository avatar",
|
||||||
|
EnvVar: "DRONE_REPO_AVATAR",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "repo.branch",
|
||||||
|
Value: "master",
|
||||||
|
Usage: "repository default branch",
|
||||||
|
EnvVar: "DRONE_REPO_BRANCH",
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "repo.private",
|
||||||
|
Usage: "repository is private",
|
||||||
|
EnvVar: "DRONE_REPO_PRIVATE",
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "repo.trusted",
|
||||||
|
Usage: "repository is trusted",
|
||||||
|
EnvVar: "DRONE_REPO_TRUSTED",
|
||||||
|
},
|
||||||
|
|
||||||
|
// Remote
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "remote.url",
|
||||||
|
Usage: "repository clone url",
|
||||||
|
EnvVar: "DRONE_REMOTE_URL",
|
||||||
|
},
|
||||||
|
|
||||||
|
// Commit
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "commit.sha",
|
Name: "commit.sha",
|
||||||
Usage: "git commit sha",
|
Usage: "git commit sha",
|
||||||
|
@ -103,6 +150,16 @@ func main() {
|
||||||
Usage: "git commit branch",
|
Usage: "git commit branch",
|
||||||
EnvVar: "DRONE_COMMIT_BRANCH",
|
EnvVar: "DRONE_COMMIT_BRANCH",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "commit.link",
|
||||||
|
Usage: "commit link",
|
||||||
|
EnvVar: "DRONE_COMMIT_LINK",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "commit.message",
|
||||||
|
Usage: "git commit message",
|
||||||
|
EnvVar: "DRONE_COMMIT_MESSAGE",
|
||||||
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "commit.author.name",
|
Name: "commit.author.name",
|
||||||
Usage: "git author name",
|
Usage: "git author name",
|
||||||
|
@ -118,10 +175,12 @@ func main() {
|
||||||
Usage: "git author avatar",
|
Usage: "git author avatar",
|
||||||
EnvVar: "DRONE_COMMIT_AUTHOR_AVATAR",
|
EnvVar: "DRONE_COMMIT_AUTHOR_AVATAR",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
|
||||||
Name: "commit.message",
|
// Build
|
||||||
Usage: "git commit message",
|
cli.IntFlag{
|
||||||
EnvVar: "DRONE_COMMIT_MESSAGE",
|
Name: "build.number",
|
||||||
|
Usage: "build number",
|
||||||
|
EnvVar: "DRONE_BUILD_NUMBER",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "build.event",
|
Name: "build.event",
|
||||||
|
@ -129,11 +188,6 @@ func main() {
|
||||||
Usage: "build event",
|
Usage: "build event",
|
||||||
EnvVar: "DRONE_BUILD_EVENT",
|
EnvVar: "DRONE_BUILD_EVENT",
|
||||||
},
|
},
|
||||||
cli.IntFlag{
|
|
||||||
Name: "build.number",
|
|
||||||
Usage: "build number",
|
|
||||||
EnvVar: "DRONE_BUILD_NUMBER",
|
|
||||||
},
|
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "build.status",
|
Name: "build.status",
|
||||||
Usage: "build status",
|
Usage: "build status",
|
||||||
|
@ -145,26 +199,98 @@ func main() {
|
||||||
Usage: "build link",
|
Usage: "build link",
|
||||||
EnvVar: "DRONE_BUILD_LINK",
|
EnvVar: "DRONE_BUILD_LINK",
|
||||||
},
|
},
|
||||||
|
cli.Int64Flag{
|
||||||
|
Name: "build.created",
|
||||||
|
Usage: "build created",
|
||||||
|
EnvVar: "DRONE_BUILD_CREATED",
|
||||||
|
},
|
||||||
cli.Int64Flag{
|
cli.Int64Flag{
|
||||||
Name: "build.started",
|
Name: "build.started",
|
||||||
Usage: "build started",
|
Usage: "build started",
|
||||||
EnvVar: "DRONE_BUILD_STARTED",
|
EnvVar: "DRONE_BUILD_STARTED",
|
||||||
},
|
},
|
||||||
cli.Int64Flag{
|
cli.Int64Flag{
|
||||||
Name: "build.created",
|
Name: "build.finished",
|
||||||
Usage: "build created",
|
Usage: "build finished",
|
||||||
EnvVar: "DRONE_BUILD_CREATED",
|
EnvVar: "DRONE_BUILD_FINISHED",
|
||||||
|
},
|
||||||
|
|
||||||
|
// Prev
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "prev.build.status",
|
||||||
|
Usage: "prior build status",
|
||||||
|
EnvVar: "DRONE_PREV_BUILD_STATUS",
|
||||||
|
},
|
||||||
|
cli.IntFlag{
|
||||||
|
Name: "prev.build.number",
|
||||||
|
Usage: "prior build number",
|
||||||
|
EnvVar: "DRONE_PREV_BUILD_NUMBER",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "build.tag",
|
Name: "prev.commit.sha",
|
||||||
Usage: "build tag",
|
Usage: "prior commit sha",
|
||||||
EnvVar: "DRONE_TAG",
|
EnvVar: "DRONE_PREV_COMMIT_SHA",
|
||||||
|
},
|
||||||
|
|
||||||
|
// Job
|
||||||
|
cli.IntFlag{
|
||||||
|
Name: "job.number",
|
||||||
|
Usage: "job number",
|
||||||
|
EnvVar: "DRONE_JOB_NUMBER",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "job.status",
|
||||||
|
Usage: "job status",
|
||||||
|
EnvVar: "DRONE_JOB_STATUS",
|
||||||
|
},
|
||||||
|
cli.IntFlag{
|
||||||
|
Name: "job.exitCode",
|
||||||
|
Usage: "job exit code",
|
||||||
|
EnvVar: "DRONE_JOB_EXIT_CODE",
|
||||||
},
|
},
|
||||||
cli.Int64Flag{
|
cli.Int64Flag{
|
||||||
Name: "job.started",
|
Name: "job.started",
|
||||||
Usage: "job started",
|
Usage: "job started",
|
||||||
EnvVar: "DRONE_JOB_STARTED",
|
EnvVar: "DRONE_JOB_STARTED",
|
||||||
},
|
},
|
||||||
|
cli.Int64Flag{
|
||||||
|
Name: "job.finished",
|
||||||
|
Usage: "job finished",
|
||||||
|
EnvVar: "DRONE_JOB_FINISHED",
|
||||||
|
},
|
||||||
|
|
||||||
|
// Yaml
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "yaml.signed",
|
||||||
|
Usage: "yaml is signed",
|
||||||
|
EnvVar: "DRONE_YAML_SIGNED",
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "yaml.verified",
|
||||||
|
Usage: "yaml is signed and verified",
|
||||||
|
EnvVar: "DRONE_YAML_VERIFIED",
|
||||||
|
},
|
||||||
|
|
||||||
|
// Tag
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "tag",
|
||||||
|
Usage: "git tag",
|
||||||
|
EnvVar: "DRONE_TAG",
|
||||||
|
},
|
||||||
|
|
||||||
|
// PullRequest
|
||||||
|
cli.IntFlag{
|
||||||
|
Name: "pullRequest",
|
||||||
|
Usage: "pull request number",
|
||||||
|
EnvVar: "DRONE_PULL_REQUEST",
|
||||||
|
},
|
||||||
|
|
||||||
|
// DeployTo
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "deployTo",
|
||||||
|
Usage: "deployment target",
|
||||||
|
EnvVar: "DRONE_DEPLOY_TO",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := app.Run(os.Args); err != nil {
|
if err := app.Run(os.Args); err != nil {
|
||||||
|
@ -176,30 +302,62 @@ func main() {
|
||||||
func run(c *cli.Context) error {
|
func run(c *cli.Context) error {
|
||||||
plugin := Plugin{
|
plugin := Plugin{
|
||||||
Repo: Repo{
|
Repo: Repo{
|
||||||
Owner: c.String("repo.owner"),
|
FullName: c.String("repo.fullName"),
|
||||||
Name: c.String("repo.name"),
|
Owner: c.String("repo.owner"),
|
||||||
|
Name: c.String("repo.name"),
|
||||||
|
SCM: c.String("repo.scm"),
|
||||||
|
Link: c.String("repo.link"),
|
||||||
|
Avatar: c.String("repo.avatar"),
|
||||||
|
Branch: c.String("repo.branch"),
|
||||||
|
Private: c.Bool("repo.private"),
|
||||||
|
Trusted: c.Bool("repo.trusted"),
|
||||||
},
|
},
|
||||||
Build: Build{
|
Remote: Remote{
|
||||||
Tag: c.String("build.tag"),
|
URL: c.String("remote.url"),
|
||||||
Number: c.Int("build.number"),
|
},
|
||||||
Event: c.String("build.event"),
|
Commit: Commit{
|
||||||
Status: c.String("build.status"),
|
Sha: c.String("commit.sha"),
|
||||||
Commit: c.String("commit.sha"),
|
Ref: c.String("commit.ref"),
|
||||||
Ref: c.String("commit.ref"),
|
Branch: c.String("commit.branch"),
|
||||||
Branch: c.String("commit.branch"),
|
Link: c.String("commit.link"),
|
||||||
|
Message: c.String("commit.message"),
|
||||||
Author: Author{
|
Author: Author{
|
||||||
Name: c.String("commit.author.name"),
|
Name: c.String("commit.author.name"),
|
||||||
Email: c.String("commit.author.email"),
|
Email: c.String("commit.author.email"),
|
||||||
Avatar: c.String("commit.author.avatar"),
|
Avatar: c.String("commit.author.avatar"),
|
||||||
},
|
},
|
||||||
Message: c.String("commit.message"),
|
},
|
||||||
Link: c.String("build.link"),
|
Build: Build{
|
||||||
Started: c.Int64("build.started"),
|
Number: c.Int("build.number"),
|
||||||
Created: c.Int64("build.created"),
|
Event: c.String("build.event"),
|
||||||
|
Status: c.String("build.status"),
|
||||||
|
Link: c.String("build.link"),
|
||||||
|
Created: c.Int64("build.created"),
|
||||||
|
Started: c.Int64("build.started"),
|
||||||
|
Finished: c.Int64("build.finished"),
|
||||||
|
},
|
||||||
|
Prev: Prev{
|
||||||
|
Build: PrevBuild{
|
||||||
|
Status: c.String("prev.build.status"),
|
||||||
|
Number: c.Int("prev.build.number"),
|
||||||
|
},
|
||||||
|
Commit: PrevCommit{
|
||||||
|
Sha: c.String("prev.commit.sha"),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Job: Job{
|
Job: Job{
|
||||||
Started: c.Int64("job.started"),
|
Status: c.String("job.status"),
|
||||||
|
ExitCode: c.Int("job.exitCode"),
|
||||||
|
Started: c.Int64("job.started"),
|
||||||
|
Finished: c.Int64("job.finished"),
|
||||||
},
|
},
|
||||||
|
Yaml: Yaml{
|
||||||
|
Signed: c.Bool("yaml.signed"),
|
||||||
|
Verified: c.Bool("yaml.verified"),
|
||||||
|
},
|
||||||
|
Tag: c.String("tag"),
|
||||||
|
PullRequest: c.Int("pullRequest"),
|
||||||
|
DeployTo: c.String("deployTo"),
|
||||||
Config: Config{
|
Config: Config{
|
||||||
From: c.String("from"),
|
From: c.String("from"),
|
||||||
Host: c.String("host"),
|
Host: c.String("host"),
|
||||||
|
|
114
plugin.go
114
plugin.go
|
@ -11,8 +11,19 @@ import (
|
||||||
|
|
||||||
type (
|
type (
|
||||||
Repo struct {
|
Repo struct {
|
||||||
Owner string
|
FullName string
|
||||||
Name string
|
Owner string
|
||||||
|
Name string
|
||||||
|
SCM string
|
||||||
|
Link string
|
||||||
|
Avatar string
|
||||||
|
Branch string
|
||||||
|
Private bool
|
||||||
|
Trusted bool
|
||||||
|
}
|
||||||
|
|
||||||
|
Remote struct {
|
||||||
|
URL string
|
||||||
}
|
}
|
||||||
|
|
||||||
Author struct {
|
Author struct {
|
||||||
|
@ -21,19 +32,49 @@ type (
|
||||||
Avatar string
|
Avatar string
|
||||||
}
|
}
|
||||||
|
|
||||||
Build struct {
|
Commit struct {
|
||||||
Tag string
|
Sha string
|
||||||
Event string
|
|
||||||
Number int
|
|
||||||
Commit string
|
|
||||||
Ref string
|
Ref string
|
||||||
Branch string
|
Branch string
|
||||||
Author Author
|
|
||||||
Message string
|
|
||||||
Status string
|
|
||||||
Link string
|
Link string
|
||||||
Started int64
|
Message string
|
||||||
Created int64
|
Author Author
|
||||||
|
}
|
||||||
|
|
||||||
|
Build struct {
|
||||||
|
Number int
|
||||||
|
Event string
|
||||||
|
Status string
|
||||||
|
Link string
|
||||||
|
Created int64
|
||||||
|
Started int64
|
||||||
|
Finished int64
|
||||||
|
}
|
||||||
|
|
||||||
|
PrevBuild struct {
|
||||||
|
Status string
|
||||||
|
Number int
|
||||||
|
}
|
||||||
|
|
||||||
|
PrevCommit struct {
|
||||||
|
Sha string
|
||||||
|
}
|
||||||
|
|
||||||
|
Prev struct {
|
||||||
|
Build PrevBuild
|
||||||
|
Commit PrevCommit
|
||||||
|
}
|
||||||
|
|
||||||
|
Job struct {
|
||||||
|
Status string
|
||||||
|
ExitCode int
|
||||||
|
Started int64
|
||||||
|
Finished int64
|
||||||
|
}
|
||||||
|
|
||||||
|
Yaml struct {
|
||||||
|
Signed bool
|
||||||
|
Verified bool
|
||||||
}
|
}
|
||||||
|
|
||||||
Config struct {
|
Config struct {
|
||||||
|
@ -49,15 +90,18 @@ type (
|
||||||
Body string
|
Body string
|
||||||
}
|
}
|
||||||
|
|
||||||
Job struct {
|
|
||||||
Started int64
|
|
||||||
}
|
|
||||||
|
|
||||||
Plugin struct {
|
Plugin struct {
|
||||||
Repo Repo
|
Repo Repo
|
||||||
Build Build
|
Remote Remote
|
||||||
Config Config
|
Commit Commit
|
||||||
Job Job
|
Build Build
|
||||||
|
Prev Prev
|
||||||
|
Job Job
|
||||||
|
Yaml Yaml
|
||||||
|
Tag string
|
||||||
|
PullRequest int
|
||||||
|
DeployTo string
|
||||||
|
Config Config
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -66,7 +110,7 @@ func (p Plugin) Exec() error {
|
||||||
var dialer *gomail.Dialer
|
var dialer *gomail.Dialer
|
||||||
|
|
||||||
if !p.Config.RecipientsOnly {
|
if !p.Config.RecipientsOnly {
|
||||||
p.Config.Recipients = append(p.Config.Recipients, p.Build.Author.Email)
|
p.Config.Recipients = append(p.Config.Recipients, p.Commit.Author.Email)
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.Config.Username == "" && p.Config.Password == "" {
|
if p.Config.Username == "" && p.Config.Password == "" {
|
||||||
|
@ -85,16 +129,28 @@ func (p Plugin) Exec() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Context struct {
|
type Context struct {
|
||||||
Job Job
|
Repo Repo
|
||||||
Repo Repo
|
Remote Remote
|
||||||
Build Build
|
Commit Commit
|
||||||
Config Config
|
Build Build
|
||||||
|
Prev Prev
|
||||||
|
Job Job
|
||||||
|
Yaml Yaml
|
||||||
|
Tag string
|
||||||
|
PullRequest int
|
||||||
|
DeployTo string
|
||||||
}
|
}
|
||||||
ctx := Context{
|
ctx := Context{
|
||||||
Job: p.Job,
|
Repo: p.Repo,
|
||||||
Repo: p.Repo,
|
Remote: p.Remote,
|
||||||
Build: p.Build,
|
Commit: p.Commit,
|
||||||
Config: p.Config,
|
Build: p.Build,
|
||||||
|
Prev: p.Prev,
|
||||||
|
Job: p.Job,
|
||||||
|
Yaml: p.Yaml,
|
||||||
|
Tag: p.Tag,
|
||||||
|
PullRequest: p.PullRequest,
|
||||||
|
DeployTo: p.DeployTo,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render body in HTML and plain text
|
// Render body in HTML and plain text
|
||||||
|
|
Loading…
Reference in a new issue