Skip to content

Commit 6bb33bc

Browse files
committed
Add endpoint to display deployed git sha.
Fix rustfmt and clippy errors. Change endpoint name, extract function. Add comment to `show_deployed_sha` function.
1 parent e70ae13 commit 6bb33bc

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;
@@ -202,6 +203,7 @@ pub fn middleware(app: Arc<App>) -> MiddlewareBuilder {
202203
api_router.get("/summary", C(krate::summary));
203204
api_router.put("/confirm/:email_token", C(user::confirm_user_email));
204205
api_router.put("/users/:user_id/resend", C(user::regenerate_token_and_send));
206+
api_router.get("/site_metadata", C(site_metadata::show_deployed_sha));
205207
let api_router = Arc::new(R404(api_router));
206208

207209
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)