Compare commits

...

5 Commits

Author SHA1 Message Date
4446d9b879 Bump version number
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-06-16 21:46:43 +02:00
ac8ba338bb Don't reuse cache struct
Also we avoid converting from String into Cow<'a, str>'
2019-06-16 21:45:13 +02:00
d609f9bf43 Bump version number
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-06-16 15:03:12 +02:00
6bc783451e Update README 2019-06-16 15:02:45 +02:00
21243e6cfb Document JSON endpoint on index page 2019-06-16 15:00:46 +02:00
5 changed files with 33 additions and 6 deletions

2
Cargo.lock generated
View File

@ -761,7 +761,7 @@ dependencies = [
[[package]] [[package]]
name = "hoc" name = "hoc"
version = "0.9.0" version = "0.9.2"
dependencies = [ dependencies = [
"actix-web 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "actix-web 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"badge 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "badge 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "hoc" name = "hoc"
version = "0.9.0" version = "0.9.2"
authors = ["Valentin Brandl <vbrandl@riseup.net>"] authors = ["Valentin Brandl <vbrandl@riseup.net>"]
edition = "2018" edition = "2018"
build = "build.rs" build = "build.rs"

View File

@ -20,8 +20,14 @@ The API is as simple as
https://<host>/<service>/<user>/<repo> https://<host>/<service>/<user>/<repo>
``` ```
where `<service>` is one of `gitub`, `gitlab` or `bitbucket`. where `<service>` is one of `gitub`, `gitlab` or `bitbucket`. The HoC data can also be received as JSON by appending
`/json` to the reuqest path:
```
https://<host>/<service>/<user>/<repo>/json
```
There is also an overview page available via `https://<host>/view/<service>/<user>/<repo>`
## Building ## Building

View File

@ -17,7 +17,7 @@ mod service;
mod statics; mod statics;
use crate::{ use crate::{
cache::{Cache, CacheState}, cache::CacheState,
error::{Error, Result}, error::{Error, Result},
service::{Bitbucket, FormService, GitHub, Gitlab, Service}, service::{Bitbucket, FormService, GitHub, Gitlab, Service},
statics::{CLIENT, CSS, FAVICON, OPT, REPO_COUNT, VERSION_INFO}, statics::{CLIENT, CSS, FAVICON, OPT, REPO_COUNT, VERSION_INFO},
@ -56,6 +56,12 @@ struct State {
cache: String, cache: String,
} }
#[derive(Serialize)]
struct JsonResponse<'a> {
head: &'a str,
count: u64,
}
fn pull(path: impl AsRef<Path>) -> Result<()> { fn pull(path: impl AsRef<Path>) -> Result<()> {
let repo = Repository::open_bare(path)?; let repo = Repository::open_bare(path)?;
let mut origin = repo.find_remote("origin")?; let mut origin = repo.find_remote("origin")?;
@ -193,8 +199,8 @@ fn json_hoc<T: Service>(
) -> impl Future<Item = HttpResponse, Error = Error> { ) -> impl Future<Item = HttpResponse, Error = Error> {
let mapper = |r| match r { let mapper = |r| match r {
HocResult::NotFound => p404(), HocResult::NotFound => p404(),
HocResult::Hoc { hoc, head, .. } => Ok(HttpResponse::Ok().json(Cache { HocResult::Hoc { hoc, head, .. } => Ok(HttpResponse::Ok().json(JsonResponse {
head: head.into(), head: &head,
count: hoc, count: hoc,
})), })),
}; };

View File

@ -45,6 +45,21 @@ would render this badge:
alt="example badge" /></a> alt="example badge" /></a>
</pre> </pre>
<p>
You can also request the HoC as JSON by appending <code>/json</code> to the request path. This will return a JSON
object with two fields: <code>count</code> and <code>head</code> with count being the HoC value and head being the
commit ref of <code>HEAD</code>. Requesting
<a href="https://@domain/github/vbrandl/hoc/json">https://@domain/github/vbrandl/hoc/json</a> might return something
along the lines of
</p>
<pre>
&#123;
"head" : "05736ee3ba256ec9a7227c436aef2bf43db109ab",
"count": 7582
&#125;
</pre>
<h2>Badge Generator</h2> <h2>Badge Generator</h2>
<form method="post" action="/generate"> <form method="post" action="/generate">