Skip to content

Commit f5d34f8

Browse files
authored
Merge pull request #23 from unsplash/print-heroku-author
Print author of change in relevant Heroku webhooks
2 parents 498224d + 2e6ab2a commit f5d34f8

File tree

2 files changed

+52
-18
lines changed

2 files changed

+52
-18
lines changed

src/heroku/webhook.rs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ use serde::Deserialize;
2727
#[derive(Debug, PartialEq, Eq)]
2828
pub enum HookEvent {
2929
/// From the entity `api:release`.
30-
Rollback { version: String },
30+
Rollback { author: String, version: String },
3131
/// From the entity `api:release`.
32-
EnvVarsChange { raw_change: String },
32+
EnvVarsChange { author: String, raw_change: String },
3333
/// From the entity `dyno` (NB *not* `api:dyno`).
3434
DynoCrash { name: String, status_code: u8 },
3535
}
@@ -96,9 +96,9 @@ async fn send(
9696
};
9797

9898
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)
102102
}
103103
HookEvent::DynoCrash { name, status_code } => {
104104
format!("Dyno {} crashed with status code {}", name, status_code)
@@ -149,6 +149,7 @@ fn decode_rollback(payload: &ReleaseHookPayload) -> Option<HookEvent> {
149149
.and_then(|re| re.captures(&payload.data.description))
150150
.and_then(|cs| cs.name("version"))
151151
.map(|m| HookEvent::Rollback {
152+
author: payload.data.user.email.to_owned(),
152153
version: m.as_str().to_owned(),
153154
})
154155
}
@@ -161,6 +162,7 @@ fn decode_env_vars_change(payload: &ReleaseHookPayload) -> Option<HookEvent> {
161162
.and_then(|re| re.captures(&payload.data.description))
162163
.and_then(|cs| cs.name("change"))
163164
.map(|m| HookEvent::EnvVarsChange {
165+
author: payload.data.user.email.to_owned(),
164166
raw_change: m.as_str().to_owned(),
165167
})
166168
}
@@ -226,14 +228,15 @@ pub enum ReleaseHookAction {
226228
Other,
227229
}
228230

229-
/// General information about an `api:release` webhook event.
231+
/// General information about an `api:release` entity type.
230232
#[derive(Debug, PartialEq, Deserialize)]
231233
struct ReleaseHookData {
232234
app: AppData,
233235
description: String,
236+
user: UserData,
234237
}
235238

236-
/// General information about an `api:release` webhook event.
239+
/// General information about an `dyno` entity type.
237240
#[derive(Debug, PartialEq, Deserialize)]
238241
struct DynoHookData {
239242
app: AppData,
@@ -253,6 +256,12 @@ struct AppData {
253256
name: String,
254257
}
255258

259+
/// Information about the user who enacted the change.
260+
#[derive(Debug, PartialEq, Deserialize)]
261+
struct UserData {
262+
email: String,
263+
}
264+
256265
fn get_app_data(payload: &HookPayload) -> &AppData {
257266
match payload {
258267
HookPayload::Release(x) => &x.data.app,
@@ -285,7 +294,7 @@ mod tests {
285294
},
286295
"user": {
287296
"id": "71def50e-da83-453a-bba3-46b4e26911b0",
288-
"email": "hello@example.com"
297+
"email": "hodor@unsplash.com"
289298
},
290299
"stack": "heroku-20",
291300
"status": "succeeded",
@@ -340,6 +349,9 @@ mod tests {
340349
name: "my-app".to_string(),
341350
},
342351
description: "Deploy 69eec518".to_string(),
352+
user: UserData {
353+
email: "hodor@unsplash.com".to_string(),
354+
},
343355
},
344356
action: ReleaseHookAction::Update,
345357
});
@@ -551,6 +563,9 @@ mod tests {
551563
name: "any".to_string(),
552564
},
553565
description: desc.to_string(),
566+
user: UserData {
567+
email: "hodor@unsplash.com".to_string(),
568+
},
554569
},
555570
action: ReleaseHookAction::Update,
556571
}
@@ -561,13 +576,15 @@ mod tests {
561576
assert_eq!(
562577
decode_release_payload(&payload_from_desc("Rollback to v1234")),
563578
Ok(HookEvent::Rollback {
579+
author: "hodor@unsplash.com".to_string(),
564580
version: "v1234".to_string()
565581
}),
566582
);
567583

568584
assert_eq!(
569585
decode_release_payload(&payload_from_desc("Rollback to some new format")),
570586
Ok(HookEvent::Rollback {
587+
author: "hodor@unsplash.com".to_string(),
571588
version: "some new format".to_string()
572589
}),
573590
);
@@ -583,13 +600,15 @@ mod tests {
583600
assert_eq!(
584601
decode_release_payload(&payload_from_desc("Set FOO, BAR config vars")),
585602
Ok(HookEvent::EnvVarsChange {
603+
author: "hodor@unsplash.com".to_string(),
586604
raw_change: "Set FOO, BAR".to_string()
587605
}),
588606
);
589607

590608
assert_eq!(
591609
decode_release_payload(&payload_from_desc("Some new format config vars")),
592610
Ok(HookEvent::EnvVarsChange {
611+
author: "hodor@unsplash.com".to_string(),
593612
raw_change: "Some new format".to_string()
594613
}),
595614
);

src/router.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -833,11 +833,14 @@ mod tests {
833833
"app": {
834834
"name": "any"
835835
},
836-
"description": "any"
836+
"description": "any",
837+
"user": {
838+
"email": "hodor@unsplash.com"
839+
}
837840
},
838841
"action": "update"
839842
}"#;
840-
let sig = "IsNt6nWoGu9tBYt1fKKi3SjiLhMp6Fk/TYsFCehd6LM=";
843+
let sig = "0+jCzQsgvzi0SL0haDhB18ttbTNEYYlrwhtpL0FEVGw=";
841844

842845
let req = Request::builder()
843846
.method("POST")
@@ -861,11 +864,14 @@ mod tests {
861864
"app": {
862865
"name": "any"
863866
},
864-
"description": "any"
867+
"description": "any",
868+
"user": {
869+
"email": "hodor@unsplash.com"
870+
}
865871
},
866872
"action": "create"
867873
}"#;
868-
let sig = "WKv86Cw9YFrEpu8vkCw21QfsQ7FT0f8502q1F9EEQ6c=";
874+
let sig = "F5ArFnV9sfXsDmk9ubM24fu6gVVxEXl1TOdt1XTVokg=";
869875

870876
let req = Request::builder()
871877
.method("POST")
@@ -889,11 +895,14 @@ mod tests {
889895
"app": {
890896
"name": "any"
891897
},
892-
"description": "Rollback to v1234"
898+
"description": "Rollback to v1234",
899+
"user": {
900+
"email": "hodor@unsplash.com"
901+
}
893902
},
894903
"action": "update"
895904
}"#;
896-
let sig = "mMGRnv4/Wjm2kyEbI0vqR//Kmt8NaV3Rj9xiMBdvlUU=";
905+
let sig = "GxMZ9dos5w6r9V0JTDyeWprKmd3JW+i4otfkkDV463M=";
897906

898907
let req = Request::builder()
899908
.method("POST")
@@ -943,11 +952,14 @@ mod tests {
943952
"app": {
944953
"name": "any"
945954
},
946-
"description": "Rollback to v1234"
955+
"description": "Rollback to v1234",
956+
"user": {
957+
"email": "hodor@unsplash.com"
958+
}
947959
},
948960
"action": "update"
949961
}"#;
950-
let sig = "mMGRnv4/Wjm2kyEbI0vqR//Kmt8NaV3Rj9xiMBdvlUU=";
962+
let sig = "GxMZ9dos5w6r9V0JTDyeWprKmd3JW+i4otfkkDV463M=";
951963

952964
let req = Request::builder()
953965
.method("POST")
@@ -997,11 +1009,14 @@ mod tests {
9971009
"app": {
9981010
"name": "any"
9991011
},
1000-
"description": "Rollback to v1234"
1012+
"description": "Rollback to v1234",
1013+
"user": {
1014+
"email": "hodor@unsplash.com"
1015+
}
10011016
},
10021017
"action": "update"
10031018
}"#;
1004-
let sig = "mMGRnv4/Wjm2kyEbI0vqR//Kmt8NaV3Rj9xiMBdvlUU=";
1019+
let sig = "GxMZ9dos5w6r9V0JTDyeWprKmd3JW+i4otfkkDV463M=";
10051020

10061021
let req = Request::builder()
10071022
.method("POST")

0 commit comments

Comments
 (0)