Compare commits

...

8 Commits

Author SHA1 Message Date
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
05736ee3ba Bump version number
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-06-16 14:43:00 +02:00
d23588172b Merge branch 'feature/json-output' 2019-06-16 14:33:47 +02:00
ce77854754 Implement JSON endpoint 2019-06-16 14:33:15 +02:00
70e83d8cee Bump version number
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-06-12 21:58:02 +02:00
284e41c591 Fix footer structure 2019-06-12 21:57:24 +02:00
6 changed files with 77 additions and 40 deletions

2
Cargo.lock generated
View File

@ -761,7 +761,7 @@ dependencies = [
[[package]]
name = "hoc"
version = "0.8.0"
version = "0.9.1"
dependencies = [
"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)",

View File

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

View File

@ -20,8 +20,14 @@ The API is as simple as
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

View File

@ -17,7 +17,7 @@ mod service;
mod statics;
use crate::{
cache::CacheState,
cache::{Cache, CacheState},
error::{Error, Result},
service::{Bitbucket, FormService, GitHub, Gitlab, Service},
statics::{CLIENT, CSS, FAVICON, OPT, REPO_COUNT, VERSION_INFO},
@ -150,14 +150,8 @@ where
T: Service,
F: Fn(HocResult) -> Result<HttpResponse>,
{
hoc_request::<T>(state, data).and_then(mapper)
}
fn hoc_request<T: Service>(
state: web::Data<Arc<State>>,
data: web::Path<(String, String)>,
) -> impl Future<Item = HocResult, Error = Error> {
futures::future::result(Ok(())).and_then(move |_| {
futures::future::result(Ok(()))
.and_then(move |_| {
let repo = format!("{}/{}", data.0.to_lowercase(), data.1.to_lowercase());
let service_path = format!("{}/{}", T::domain(), repo);
let path = format!("{}/{}", state.repos, service_path);
@ -190,6 +184,21 @@ fn hoc_request<T: Service>(
service_path,
})
})
.and_then(mapper)
}
fn json_hoc<T: Service>(
state: web::Data<Arc<State>>,
data: web::Path<(String, String)>,
) -> impl Future<Item = HttpResponse, Error = Error> {
let mapper = |r| match r {
HocResult::NotFound => p404(),
HocResult::Hoc { hoc, head, .. } => Ok(HttpResponse::Ok().json(Cache {
head: head.into(),
count: hoc,
})),
};
handle_hoc_request::<T, _>(state, data, mapper)
}
fn calculate_hoc<T: Service>(
@ -331,6 +340,9 @@ fn main() -> Result<()> {
.service(web::resource("/github/{user}/{repo}").to_async(calculate_hoc::<GitHub>))
.service(web::resource("/gitlab/{user}/{repo}").to_async(calculate_hoc::<Gitlab>))
.service(web::resource("/bitbucket/{user}/{repo}").to_async(calculate_hoc::<Bitbucket>))
.service(web::resource("/github/{user}/{repo}/json").to_async(json_hoc::<GitHub>))
.service(web::resource("/gitlab/{user}/{repo}/json").to_async(json_hoc::<Gitlab>))
.service(web::resource("/bitbucket/{user}/{repo}/json").to_async(json_hoc::<Bitbucket>))
.service(web::resource("/view/github/{user}/{repo}").to_async(overview::<GitHub>))
.service(web::resource("/view/gitlab/{user}/{repo}").to_async(overview::<Gitlab>))
.service(web::resource("/view/bitbucket/{user}/{repo}").to_async(overview::<Bitbucket>))

View File

@ -36,6 +36,10 @@
<li>
<small>HoC v@version_info.version - <a href="https://github.com/vbrandl/hoc/commit/@version_info.commit">@version_info.commit</a></small>
</li>
</ul>
</nav>
<nav>
<ul>
<li>
<small>Currently serving @repo_count repositories</small>
</li>

View File

@ -45,6 +45,21 @@ would render this badge:
alt="example badge" /></a>
</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>
<form method="post" action="/generate">