Skip to content

Commit

Permalink
chore: update config
Browse files Browse the repository at this point in the history
  • Loading branch information
appleboy committed Nov 16, 2019
1 parent 999af5c commit 66e7c50
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 25 deletions.
74 changes: 61 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,20 @@ func main() {
EnvVar: "LINE_PORT",
Value: 8088,
},
cli.BoolFlag{
Name: "drone",
Usage: "environment is drone",
EnvVar: "DRONE",
},
cli.StringFlag{
Name: "repo",
Usage: "repository owner and repository name",
EnvVar: "DRONE_REPO,GITHUB_REPOSITORY",
},
cli.StringFlag{
Name: "repo.owner",
Usage: "repository owner",
EnvVar: "DRONE_REPO_OWNER",
Name: "repo.namespace",
Usage: "repository namespace",
EnvVar: "DRONE_REPO_OWNER,DRONE_REPO_NAMESPACE,GITHUB_ACTOR",
},
cli.StringFlag{
Name: "repo.name",
Expand Down Expand Up @@ -185,25 +195,55 @@ func main() {
Usage: "pull request",
EnvVar: "DRONE_PULL_REQUEST",
},
cli.Int64Flag{
cli.Float64Flag{
Name: "job.started",
Usage: "job started",
EnvVar: "DRONE_BUILD_STARTED",
},
cli.Int64Flag{
cli.Float64Flag{
Name: "job.finished",
Usage: "job finished",
EnvVar: "DRONE_BUILD_FINISHED",
},
cli.StringFlag{
Name: "env-file",
Usage: "source env file",
},
cli.BoolFlag{
Name: "github",
Usage: "Boolean value, indicates the runtime environment is GitHub Action.",
EnvVar: "PLUGIN_GITHUB,GITHUB",
},
cli.StringFlag{
Name: "github.workflow",
Usage: "The name of the workflow.",
EnvVar: "GITHUB_WORKFLOW",
},
cli.StringFlag{
Name: "github.action",
Usage: "The name of the action.",
EnvVar: "GITHUB_ACTION",
},
cli.StringFlag{
Name: "github.event.name",
Usage: "The webhook name of the event that triggered the workflow.",
EnvVar: "GITHUB_EVENT_NAME",
},
cli.StringFlag{
Name: "github.event.path",
Usage: "The path to a file that contains the payload of the event that triggered the workflow. Value: /github/workflow/event.json.",
EnvVar: "GITHUB_EVENT_PATH",
},
cli.StringFlag{
Name: "github.workspace",
Usage: "The GitHub workspace path. Value: /github/workspace.",
EnvVar: "GITHUB_WORKSPACE",
},
cli.StringFlag{
Name: "deploy.to",
Usage: "Provides the target deployment environment for the running build. This value is only available to promotion and rollback pipelines.",
EnvVar: "DRONE_DEPLOY_TO",
},
cli.StringFlag{
Name: "env-file",
Usage: "source env file",
},
cli.BoolFlag{
Name: "tunnel",
Usage: "Enable tunnel host for webhook",
Expand Down Expand Up @@ -275,9 +315,17 @@ func run(c *cli.Context) error {
}

plugin := Plugin{
GitHub: GitHub{
Workflow: c.String("github.workflow"),
Workspace: c.String("github.workspace"),
Action: c.String("github.action"),
EventName: c.String("github.event.name"),
EventPath: c.String("github.event.path"),
},
Repo: Repo{
Owner: c.String("repo.owner"),
Name: c.String("repo.name"),
FullName: c.String("repo"),
Namespace: c.String("repo.namespace"),
Name: c.String("repo.name"),
},
Commit: Commit{
Sha: c.String("commit.sha"),
Expand All @@ -295,8 +343,8 @@ func run(c *cli.Context) error {
Event: c.String("build.event"),
Status: c.String("build.status"),
Link: c.String("build.link"),
Started: c.Int64("job.started"),
Finished: c.Int64("job.finished"),
Started: c.Float64("job.started"),
Finished: c.Float64("job.finished"),
PR: c.String("pull.request"),
DeployTo: c.String("deploy.to"),
},
Expand Down
19 changes: 15 additions & 4 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,20 @@ import (
const defaultPreviewImageURL = "https://cdn4.iconfinder.com/data/icons/miu/24/device-camera-recorder-video-glyph-256.png"

type (
// GitHub information.
GitHub struct {
Workflow string
Workspace string
Action string
EventName string
EventPath string
}

// Repo information.
Repo struct {
Owner string
Name string
FullName string
Namespace string
Name string
}

// Commit information.
Expand All @@ -48,8 +58,8 @@ type (
Number int
Status string
Link string
Started int64
Finished int64
Started float64
Finished float64
PR string
DeployTo string
}
Expand Down Expand Up @@ -83,6 +93,7 @@ type (
Build Build
Config Config
Commit Commit
GitHub GitHub
}

// Audio format
Expand Down
16 changes: 8 additions & 8 deletions plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func TestMissingUserConfig(t *testing.T) {
func TestSendTextError(t *testing.T) {
plugin := Plugin{
Repo: Repo{
Name: "go-hello",
Owner: "appleboy",
Name: "go-hello",
FullName: "appleboy",
},
Commit: Commit{
Author: "Bo-Yi Wu",
Expand Down Expand Up @@ -73,8 +73,8 @@ func TestSendTextError(t *testing.T) {
func TestSendRoomAndGroup(t *testing.T) {
plugin := Plugin{
Repo: Repo{
Name: "go-hello",
Owner: "appleboy",
Name: "go-hello",
FullName: "appleboy",
},
Commit: Commit{
Author: "Bo-Yi Wu",
Expand Down Expand Up @@ -103,8 +103,8 @@ func TestSendRoomAndGroup(t *testing.T) {
func TestDefaultMessageFormat(t *testing.T) {
plugin := Plugin{
Repo: Repo{
Name: "go-hello",
Owner: "appleboy",
Name: "go-hello",
FullName: "appleboy",
},
Commit: Commit{
Author: "Bo-Yi Wu",
Expand All @@ -126,8 +126,8 @@ func TestDefaultMessageFormat(t *testing.T) {
func TestErrorSendMessage(t *testing.T) {
plugin := Plugin{
Repo: Repo{
Name: "go-hello",
Owner: "appleboy",
Name: "go-hello",
FullName: "appleboy",
},
Commit: Commit{
Author: "Bo-Yi Wu",
Expand Down

0 comments on commit 66e7c50

Please sign in to comment.