update struct.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu
2017-06-10 17:42:11 +08:00
parent 4d0a3378a1
commit 100ff18145
3 changed files with 27 additions and 16 deletions
+6 -4
View File
@@ -169,11 +169,13 @@ func run(c *cli.Context) error {
Config: Config{
WebhookID: c.String("webhook-id"),
WebhookToken: c.String("webhook-token"),
Wait: c.Bool("wait"),
Message: c.StringSlice("message"),
Username: c.String("username"),
AvatarURL: c.String("avatar-url"),
TTS: c.Bool("tts"),
},
Form: Form{
Wait: c.Bool("wait"),
Username: c.String("username"),
AvatarURL: c.String("avatar-url"),
TTS: c.Bool("tts"),
},
}
+13 -7
View File
@@ -39,11 +39,15 @@ type (
WebhookID string
WebhookToken string
Message []string
Wait bool `json:"wait"`
Content string `json:"content"`
Username string `json:"username"`
AvatarURL string `json:"avatar_url"`
TTS bool `json:"tts"`
}
// Form for the plugin.
Form struct {
Wait bool `json:"wait"`
Content string `json:"content"`
Username string `json:"username"`
AvatarURL string `json:"avatar_url"`
TTS bool `json:"tts"`
}
// Plugin values.
@@ -51,6 +55,7 @@ type (
Repo Repo
Build Build
Config Config
Form Form
}
)
@@ -78,9 +83,10 @@ func (p Plugin) Exec() error {
}
// update content
p.Config.Content = txt
p.Form.Content = txt
fmt.Println(p.Form)
b := new(bytes.Buffer)
json.NewEncoder(b).Encode(p.Config)
json.NewEncoder(b).Encode(p.Form)
_, err = http.Post(webhookURL, "application/json; charset=utf-8", b)
if err != nil {
+8 -5
View File
@@ -56,10 +56,13 @@ func TestSendMessage(t *testing.T) {
Config: Config{
WebhookID: os.Getenv("WEBHOOK_ID"),
WebhookToken: os.Getenv("WEBHOOK_TOKEN"),
Wait: false,
Message: []string{"test one message from drone testing", "test two message from drone testing"},
Username: "drone-ci",
TTS: false,
},
Form: Form{
Username: "drone-ci",
TTS: false,
Wait: false,
},
}
@@ -71,8 +74,8 @@ func TestSendMessage(t *testing.T) {
assert.Nil(t, err)
plugin.Config.Message = []string{"I am appleboy"}
plugin.Config.TTS = true
plugin.Config.Wait = true
plugin.Form.TTS = true
plugin.Form.Wait = true
err = plugin.Exec()
assert.Nil(t, err)
}