Skip to content

Commit dd2d17e

Browse files
Merge #1115
1115: Add endpoint to display deployed git sha. r=carols10cents This PR adds an api endpoint `/deployed_sha`, which returns a JSON response containing that sha `{ "sha": "abc" }` or if it's unavailable returns `{ "sha": "unknown" }`. Closes #879
2 parents 4628bcf + 6bb33bc commit dd2d17e

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ pub mod user;
9797
pub mod util;
9898
pub mod version;
9999
pub mod email;
100+
pub mod site_metadata;
100101

101102
mod local_upload;
102103
mod pagination;
@@ -217,6 +218,7 @@ pub fn middleware(app: Arc<App>) -> MiddlewareBuilder {
217218
api_router.get("/summary", C(krate::metadata::summary));
218219
api_router.put("/confirm/:email_token", C(user::confirm_user_email));
219220
api_router.put("/users/:user_id/resend", C(user::regenerate_token_and_send));
221+
api_router.get("/site_metadata", C(site_metadata::show_deployed_sha));
220222
let api_router = Arc::new(R404(api_router));
221223

222224
let mut router = RouteBuilder::new();

src/site_metadata.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use conduit::{Request, Response};
2+
use util::RequestUtils;
3+
use util::errors::CargoResult;
4+
5+
/// Returns the JSON representation of the current deployed commit sha.
6+
///
7+
/// The sha is contained within the `HEROKU_SLUG_COMMIT` environment variable.
8+
/// If `HEROKU_SLUG_COMMIT` is not set, returns `"unknown"`.
9+
pub fn show_deployed_sha(req: &mut Request) -> CargoResult<Response> {
10+
let deployed_sha =
11+
::std::env::var("HEROKU_SLUG_COMMIT").unwrap_or_else(|_| String::from("unknown"));
12+
13+
#[derive(Serialize)]
14+
struct R {
15+
deployed_sha: String,
16+
}
17+
Ok(req.json(&R {
18+
deployed_sha: deployed_sha,
19+
}))
20+
}

0 commit comments

Comments
 (0)