@@ -27,9 +27,9 @@ use serde::Deserialize;
27
27
#[ derive( Debug , PartialEq , Eq ) ]
28
28
pub enum HookEvent {
29
29
/// From the entity `api:release`.
30
- Rollback { version : String } ,
30
+ Rollback { author : String , version : String } ,
31
31
/// From the entity `api:release`.
32
- EnvVarsChange { raw_change : String } ,
32
+ EnvVarsChange { author : String , raw_change : String } ,
33
33
/// From the entity `dyno` (NB *not* `api:dyno`).
34
34
DynoCrash { name : String , status_code : u8 } ,
35
35
}
@@ -96,9 +96,9 @@ async fn send(
96
96
} ;
97
97
98
98
let desc = match event {
99
- HookEvent :: Rollback { version } => format ! ( "Rollback to {}" , version) ,
100
- HookEvent :: EnvVarsChange { raw_change } => {
101
- format ! ( "Environment variables changed: {}" , raw_change)
99
+ HookEvent :: Rollback { version, author } => format ! ( "Rollback to {} ({}) " , version, author ) ,
100
+ HookEvent :: EnvVarsChange { raw_change, author } => {
101
+ format ! ( "Environment variables changed: {} ({}) " , raw_change, author )
102
102
}
103
103
HookEvent :: DynoCrash { name, status_code } => {
104
104
format ! ( "Dyno {} crashed with status code {}" , name, status_code)
@@ -149,6 +149,7 @@ fn decode_rollback(payload: &ReleaseHookPayload) -> Option<HookEvent> {
149
149
. and_then ( |re| re. captures ( & payload. data . description ) )
150
150
. and_then ( |cs| cs. name ( "version" ) )
151
151
. map ( |m| HookEvent :: Rollback {
152
+ author : payload. data . user . email . to_owned ( ) ,
152
153
version : m. as_str ( ) . to_owned ( ) ,
153
154
} )
154
155
}
@@ -161,6 +162,7 @@ fn decode_env_vars_change(payload: &ReleaseHookPayload) -> Option<HookEvent> {
161
162
. and_then ( |re| re. captures ( & payload. data . description ) )
162
163
. and_then ( |cs| cs. name ( "change" ) )
163
164
. map ( |m| HookEvent :: EnvVarsChange {
165
+ author : payload. data . user . email . to_owned ( ) ,
164
166
raw_change : m. as_str ( ) . to_owned ( ) ,
165
167
} )
166
168
}
@@ -226,14 +228,15 @@ pub enum ReleaseHookAction {
226
228
Other ,
227
229
}
228
230
229
- /// General information about an `api:release` webhook event .
231
+ /// General information about an `api:release` entity type .
230
232
#[ derive( Debug , PartialEq , Deserialize ) ]
231
233
struct ReleaseHookData {
232
234
app : AppData ,
233
235
description : String ,
236
+ user : UserData ,
234
237
}
235
238
236
- /// General information about an `api:release` webhook event .
239
+ /// General information about an `dyno` entity type .
237
240
#[ derive( Debug , PartialEq , Deserialize ) ]
238
241
struct DynoHookData {
239
242
app : AppData ,
@@ -253,6 +256,12 @@ struct AppData {
253
256
name : String ,
254
257
}
255
258
259
+ /// Information about the user who enacted the change.
260
+ #[ derive( Debug , PartialEq , Deserialize ) ]
261
+ struct UserData {
262
+ email : String ,
263
+ }
264
+
256
265
fn get_app_data ( payload : & HookPayload ) -> & AppData {
257
266
match payload {
258
267
HookPayload :: Release ( x) => & x. data . app ,
@@ -285,7 +294,7 @@ mod tests {
285
294
},
286
295
"user": {
287
296
"id": "71def50e-da83-453a-bba3-46b4e26911b0",
288
- "email": "hello@example .com"
297
+ "email": "hodor@unsplash .com"
289
298
},
290
299
"stack": "heroku-20",
291
300
"status": "succeeded",
@@ -340,6 +349,9 @@ mod tests {
340
349
name : "my-app" . to_string ( ) ,
341
350
} ,
342
351
description : "Deploy 69eec518" . to_string ( ) ,
352
+ user : UserData {
353
+ email : "hodor@unsplash.com" . to_string ( ) ,
354
+ } ,
343
355
} ,
344
356
action : ReleaseHookAction :: Update ,
345
357
} ) ;
@@ -551,6 +563,9 @@ mod tests {
551
563
name : "any" . to_string ( ) ,
552
564
} ,
553
565
description : desc. to_string ( ) ,
566
+ user : UserData {
567
+ email : "hodor@unsplash.com" . to_string ( ) ,
568
+ } ,
554
569
} ,
555
570
action : ReleaseHookAction :: Update ,
556
571
}
@@ -561,13 +576,15 @@ mod tests {
561
576
assert_eq ! (
562
577
decode_release_payload( & payload_from_desc( "Rollback to v1234" ) ) ,
563
578
Ok ( HookEvent :: Rollback {
579
+ author: "hodor@unsplash.com" . to_string( ) ,
564
580
version: "v1234" . to_string( )
565
581
} ) ,
566
582
) ;
567
583
568
584
assert_eq ! (
569
585
decode_release_payload( & payload_from_desc( "Rollback to some new format" ) ) ,
570
586
Ok ( HookEvent :: Rollback {
587
+ author: "hodor@unsplash.com" . to_string( ) ,
571
588
version: "some new format" . to_string( )
572
589
} ) ,
573
590
) ;
@@ -583,13 +600,15 @@ mod tests {
583
600
assert_eq ! (
584
601
decode_release_payload( & payload_from_desc( "Set FOO, BAR config vars" ) ) ,
585
602
Ok ( HookEvent :: EnvVarsChange {
603
+ author: "hodor@unsplash.com" . to_string( ) ,
586
604
raw_change: "Set FOO, BAR" . to_string( )
587
605
} ) ,
588
606
) ;
589
607
590
608
assert_eq ! (
591
609
decode_release_payload( & payload_from_desc( "Some new format config vars" ) ) ,
592
610
Ok ( HookEvent :: EnvVarsChange {
611
+ author: "hodor@unsplash.com" . to_string( ) ,
593
612
raw_change: "Some new format" . to_string( )
594
613
} ) ,
595
614
) ;
0 commit comments