@@ -20,6 +20,8 @@ type Plugin struct {
2020 Watch []WatchConfig
2121 RawEnv interface {} `json:"env"`
2222 Env map [string ]string
23+ RawNotify []map [string ]interface {} `json:"notify" yaml:",omitempty"`
24+ Notify []PluginNotify `yaml:"notify,omitempty"`
2325}
2426
2527// HookConfig Plugin hook configuration
@@ -39,19 +41,28 @@ type Group struct {
3941 Steps []Step `yaml:"steps"`
4042}
4143
44+ // GithubStatusNotification is notification config for github_commit_status
4245type GithubStatusNotification struct {
4346 Context string `yaml:"context,omitempty"`
4447}
4548
46- // Notify is Buildkite notification definition
47- type Notify struct {
48- Email string `yaml:"email,omitempty"`
49- Basecamp string `yaml:"basecamp_campfire,omitempty"`
49+ // PluginNotify is notify configuration for pipeline
50+ type PluginNotify struct {
5051 Slack string `yaml:"slack,omitempty"`
51- Webhook string `yaml:"webhook ,omitempty"`
52+ Email string `yaml:"email ,omitempty"`
5253 PagerDuty string `yaml:"pagerduty_change_event,omitempty"`
54+ Webhook string `yaml:"webhook,omitempty"`
55+ Basecamp string `yaml:"basecamp_campfire,omitempty"`
56+ GithubStatus GithubStatusNotification `yaml:"github_commit_status,omitempty"`
5357 Condition string `yaml:"if,omitempty"`
58+ }
59+
60+ // Notify is Buildkite notification definition
61+ type StepNotify struct {
62+ Slack string `yaml:"slack,omitempty"`
63+ Basecamp string `yaml:"basecamp_campfire,omitempty"`
5464 GithubStatus GithubStatusNotification `yaml:"github_commit_status,omitempty"`
65+ Condition string `yaml:"if,omitempty"`
5566}
5667
5768// Step is buildkite pipeline definition
@@ -69,7 +80,7 @@ type Step struct {
6980 Async bool `yaml:"async,omitempty"`
7081 SoftFail interface {} `json:"soft_fail" yaml:"soft_fail,omitempty"`
7182 RawNotify []map [string ]interface {} `json:"notify" yaml:",omitempty"`
72- Notify []Notify `yaml:"notify,omitempty"`
83+ Notify []StepNotify `yaml:"notify,omitempty"`
7384}
7485
7586// Agent is Buildkite agent definition
@@ -85,45 +96,6 @@ type Build struct {
8596 // Notify []Notify `yaml:"notify,omitempty"`
8697}
8798
88- func (s Step ) MarshalYAML () (interface {}, error ) {
89- if s .Group == "" {
90- type Alias Step
91- return (Alias )(s ), nil
92- }
93-
94- label := s .Group
95- s .Group = ""
96- return Group {Label : label , Steps : []Step {s }}, nil
97- }
98-
99- func initializePlugin (data string ) (Plugin , error ) {
100- log .Debugf ("parsing plugin config: %v" , data )
101-
102- var pluginConfigs []map [string ]json.RawMessage
103-
104- if err := json .Unmarshal ([]byte (data ), & pluginConfigs ); err != nil {
105- log .Debug (err )
106- return Plugin {}, errors .New ("failed to parse plugin configuration" )
107- }
108-
109- for _ , p := range pluginConfigs {
110- for key , pluginConfig := range p {
111- if strings .HasPrefix (key , pluginName ) {
112- var plugin Plugin
113-
114- if err := json .Unmarshal (pluginConfig , & plugin ); err != nil {
115- log .Debug (err )
116- return Plugin {}, errors .New ("failed to parse plugin configuration" )
117- }
118-
119- return plugin , nil
120- }
121- }
122- }
123-
124- return Plugin {}, errors .New ("could not initialize plugin" )
125- }
126-
12799// UnmarshalJSON set defaults properties
128100func (plugin * Plugin ) UnmarshalJSON (data []byte ) error {
129101 type plain Plugin
@@ -147,6 +119,8 @@ func (plugin *Plugin) UnmarshalJSON(data []byte) error {
147119 plugin .Env = parseResult
148120 plugin .RawEnv = nil
149121
122+ setPluginNotify (& plugin .Notify , & plugin .RawNotify )
123+
150124 // Path can be string or an array of strings,
151125 // handle both cases and create an array of paths.
152126 for i , p := range plugin .Watch {
@@ -175,9 +149,37 @@ func (plugin *Plugin) UnmarshalJSON(data []byte) error {
175149 return nil
176150}
177151
178- func setNotify (notifications * []Notify , rawNotify * []map [string ]interface {}) {
152+ func initializePlugin (data string ) (Plugin , error ) {
153+ log .Debugf ("parsing plugin config: %v" , data )
154+
155+ var pluginConfigs []map [string ]json.RawMessage
156+
157+ if err := json .Unmarshal ([]byte (data ), & pluginConfigs ); err != nil {
158+ log .Debug (err )
159+ return Plugin {}, errors .New ("failed to parse plugin configuration" )
160+ }
161+
162+ for _ , p := range pluginConfigs {
163+ for key , pluginConfig := range p {
164+ if strings .HasPrefix (key , pluginName ) {
165+ var plugin Plugin
166+
167+ if err := json .Unmarshal (pluginConfig , & plugin ); err != nil {
168+ log .Debug (err )
169+ return Plugin {}, errors .New ("failed to parse plugin configuration" )
170+ }
171+
172+ return plugin , nil
173+ }
174+ }
175+ }
176+
177+ return Plugin {}, errors .New ("could not initialize plugin" )
178+ }
179+
180+ func setPluginNotify (notifications * []PluginNotify , rawNotify * []map [string ]interface {}) {
179181 for _ , v := range * rawNotify {
180- var notify Notify
182+ var notify PluginNotify
181183
182184 if condition , ok := isString (v ["if" ]); ok {
183185 notify .Condition = condition
@@ -225,6 +227,38 @@ func setNotify(notifications *[]Notify, rawNotify *[]map[string]interface{}) {
225227 * rawNotify = nil
226228}
227229
230+ func setNotify (notifications * []StepNotify , rawNotify * []map [string ]interface {}) {
231+ for _ , v := range * rawNotify {
232+ var notify StepNotify
233+
234+ if condition , ok := isString (v ["if" ]); ok {
235+ notify .Condition = condition
236+ }
237+
238+ if basecamp , ok := isString (v ["basecamp_campfire" ]); ok {
239+ notify .Basecamp = basecamp
240+ * notifications = append (* notifications , notify )
241+ continue
242+ }
243+
244+ if slack , ok := isString (v ["slack" ]); ok {
245+ notify .Slack = slack
246+ * notifications = append (* notifications , notify )
247+ continue
248+ }
249+
250+ if github , ok := v ["github_commit_status" ].(map [string ]interface {}); ok {
251+ if context , ok := isString (github ["context" ]); ok {
252+ notify .GithubStatus = GithubStatusNotification {Context : context }
253+ * notifications = append (* notifications , notify )
254+ }
255+ continue
256+ }
257+ }
258+
259+ * rawNotify = nil
260+ }
261+
228262func setBuild (build * Build ) {
229263 if build .Message == "" {
230264 build .Message = env ("BUILDKITE_MESSAGE" , "" )
0 commit comments