Compare commits
51 Commits
Author | SHA1 | Date | |
---|---|---|---|
25a179dad6 | |||
6ee44f7ba3 | |||
e9ebbee957 | |||
5211481226 | |||
fd230db0cb | |||
92a95f33d4 | |||
7e13f93ee3 | |||
36afc8732e | |||
abeed1f971 | |||
03a0743517 | |||
cbfd56b33a | |||
9c5208d6e4 | |||
92d7b6668a | |||
97510fa325 | |||
65ba104de1 | |||
9599d934a2 | |||
61e2dd174a | |||
fe00cddd47 | |||
9b73c99922 | |||
ed3da3a2c3 | |||
504476b145 | |||
9bc1b42750 | |||
140265b713 | |||
4446d9b879 | |||
ac8ba338bb | |||
d609f9bf43 | |||
6bc783451e | |||
21243e6cfb | |||
05736ee3ba | |||
d23588172b | |||
ce77854754 | |||
70e83d8cee | |||
284e41c591 | |||
ec8bbe0325 | |||
8d4de48c11 | |||
eb718990ec | |||
60dc242e5a | |||
615460c87b | |||
ba6fc7d394 | |||
5551c6f3e4 | |||
38399b0bcd | |||
ad4d87ca2f | |||
137f264bdf | |||
8cfe84c763 | |||
787ff55444 | |||
3901fe9e9c | |||
e0b6ee69f1 | |||
75398a3613 | |||
a944e8b149 | |||
d9faf25648 | |||
d2977eee32 |
641
Cargo.lock
generated
641
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
18
Cargo.toml
18
Cargo.toml
@ -1,27 +1,27 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "hoc"
|
name = "hoc"
|
||||||
version = "0.6.0"
|
version = "0.9.6"
|
||||||
authors = ["Valentin Brandl <vbrandl@riseup.net>"]
|
authors = ["Valentin Brandl <vbrandl@riseup.net>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "1.0.0-rc"
|
actix-web = "1.0.2"
|
||||||
badge = "0.2.0"
|
badge = "0.2.0"
|
||||||
bytes = "0.4.12"
|
bytes = "0.4.12"
|
||||||
futures = "0.1.27"
|
futures = "0.1.28"
|
||||||
git2 = "0.8.0"
|
git2 = "0.9.1"
|
||||||
lazy_static = "1.3.0"
|
lazy_static = "1.3.0"
|
||||||
log = "0.4.6"
|
log = "0.4.6"
|
||||||
log4rs = "0.8.3"
|
log4rs = "0.8.3"
|
||||||
number_prefix = "0.3.0"
|
number_prefix = "0.3.0"
|
||||||
openssl-probe = "0.1.2"
|
openssl-probe = "0.1.2"
|
||||||
reqwest = "0.9.17"
|
reqwest = "0.9.17"
|
||||||
serde = "1.0.91"
|
serde = "1.0.93"
|
||||||
serde_derive = "1.0.91"
|
serde_derive = "1.0.94"
|
||||||
serde_json = "1.0.39"
|
serde_json = "1.0.40"
|
||||||
structopt = "0.2.15"
|
structopt = "0.2.18"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
ructe = "0.6.2"
|
ructe = "0.6.4"
|
||||||
vergen = "3.0.4"
|
vergen = "3.0.4"
|
||||||
|
@ -29,10 +29,14 @@ FROM alpine:latest
|
|||||||
|
|
||||||
RUN apk --no-cache add --update git
|
RUN apk --no-cache add --update git
|
||||||
|
|
||||||
|
RUN adduser -D hoc
|
||||||
|
WORKDIR /home/hoc
|
||||||
|
USER hoc
|
||||||
|
|
||||||
# once we don't need a git binary anymore, this should be enough
|
# once we don't need a git binary anymore, this should be enough
|
||||||
# FROM scratch
|
# FROM scratch
|
||||||
# COPY --from=linuxkit/ca-certificates:v0.7 / /
|
# COPY --from=linuxkit/ca-certificates:v0.7 / /
|
||||||
|
|
||||||
COPY --from=builder /home/rust/src/target/x86_64-unknown-linux-musl/release/hoc /hoc
|
COPY --from=builder /home/rust/src/target/x86_64-unknown-linux-musl/release/hoc .
|
||||||
|
|
||||||
ENTRYPOINT ["/hoc"]
|
ENTRYPOINT ["/home/hoc/hoc"]
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -2,11 +2,10 @@ version: "2"
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
hoc:
|
hoc:
|
||||||
# build: .
|
image: vbrandl/hits-of-code:latest
|
||||||
# image: local/hoc:latest
|
|
||||||
image: registry.gitlab.com/vbrandl/hoc:latest
|
|
||||||
volumes:
|
volumes:
|
||||||
- ./repos:/repos
|
- ./repos:/home/hoc/repos
|
||||||
- ./cache:/cache
|
- ./cache:/home/hoc/cache
|
||||||
ports:
|
# ports:
|
||||||
- "127.0.0.1:8080:8080"
|
# - "127.0.0.1:8080:8080"
|
||||||
|
restart: always
|
||||||
|
9
scripts/list.sh
Executable file
9
scripts/list.sh
Executable file
@ -0,0 +1,9 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
DIR=${1:-repos}
|
||||||
|
|
||||||
|
find "$DIR" -mindepth 3 -maxdepth 3 -type d \
|
||||||
|
| sed -e "s/$DIR/https:\//g" \
|
||||||
|
| sort
|
@ -1,4 +1,4 @@
|
|||||||
use crate::Error;
|
use crate::error::{Error, Result};
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
fs::{create_dir_all, File, OpenOptions},
|
fs::{create_dir_all, File, OpenOptions},
|
||||||
@ -17,7 +17,7 @@ pub(crate) enum CacheState<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> CacheState<'a> {
|
impl<'a> CacheState<'a> {
|
||||||
pub(crate) fn read_from_file(path: impl AsRef<Path>, head: &str) -> Result<CacheState, Error> {
|
pub(crate) fn read_from_file(path: impl AsRef<Path>, head: &str) -> Result<CacheState> {
|
||||||
if path.as_ref().exists() {
|
if path.as_ref().exists() {
|
||||||
let cache: Cache = serde_json::from_reader(BufReader::new(File::open(path)?))?;
|
let cache: Cache = serde_json::from_reader(BufReader::new(File::open(path)?))?;
|
||||||
if cache.head == head {
|
if cache.head == head {
|
||||||
@ -49,7 +49,7 @@ pub(crate) struct Cache<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Cache<'a> {
|
impl<'a> Cache<'a> {
|
||||||
pub(crate) fn write_to_file(&self, path: impl AsRef<Path>) -> Result<(), Error> {
|
pub(crate) fn write_to_file(&self, path: impl AsRef<Path>) -> Result<()> {
|
||||||
create_dir_all(path.as_ref().parent().ok_or(Error::Internal)?)?;
|
create_dir_all(path.as_ref().parent().ok_or(Error::Internal)?)?;
|
||||||
serde_json::to_writer(
|
serde_json::to_writer(
|
||||||
OpenOptions::new()
|
OpenOptions::new()
|
||||||
|
24
src/count.rs
Normal file
24
src/count.rs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
use crate::error::Result;
|
||||||
|
use std::{fs::read_dir, path::Path, result::Result as StdResult};
|
||||||
|
|
||||||
|
pub(crate) fn count_repositories<P>(repo_path: P) -> Result<usize>
|
||||||
|
where
|
||||||
|
P: AsRef<Path>,
|
||||||
|
{
|
||||||
|
Ok(read_dir(repo_path)?
|
||||||
|
.filter_map(StdResult::ok)
|
||||||
|
.filter(|entry| entry.file_type().map(|ft| ft.is_dir()).unwrap_or(false))
|
||||||
|
.map(|entry| read_dir(entry.path()))
|
||||||
|
.filter_map(StdResult::ok)
|
||||||
|
.flat_map(|dir| {
|
||||||
|
dir.filter_map(StdResult::ok)
|
||||||
|
.filter(|entry| entry.file_type().map(|ft| ft.is_dir()).unwrap_or(false))
|
||||||
|
})
|
||||||
|
.map(|entry| read_dir(entry.path()))
|
||||||
|
.filter_map(StdResult::ok)
|
||||||
|
.flat_map(|dir| {
|
||||||
|
dir.filter_map(StdResult::ok)
|
||||||
|
.filter(|entry| entry.file_type().map(|ft| ft.is_dir()).unwrap_or(false))
|
||||||
|
})
|
||||||
|
.count())
|
||||||
|
}
|
15
src/error.rs
15
src/error.rs
@ -1,6 +1,9 @@
|
|||||||
use crate::P500;
|
use crate::{
|
||||||
|
statics::{REPO_COUNT, VERSION_INFO},
|
||||||
|
templates,
|
||||||
|
};
|
||||||
use actix_web::{HttpResponse, ResponseError};
|
use actix_web::{HttpResponse, ResponseError};
|
||||||
use std::fmt;
|
use std::{fmt, sync::atomic::Ordering};
|
||||||
|
|
||||||
pub(crate) type Result<T> = std::result::Result<T, Error>;
|
pub(crate) type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
@ -33,15 +36,15 @@ impl fmt::Display for Error {
|
|||||||
|
|
||||||
impl ResponseError for Error {
|
impl ResponseError for Error {
|
||||||
fn error_response(&self) -> HttpResponse {
|
fn error_response(&self) -> HttpResponse {
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
templates::p500(&mut buf, VERSION_INFO, REPO_COUNT.load(Ordering::Relaxed)).unwrap();
|
||||||
HttpResponse::InternalServerError()
|
HttpResponse::InternalServerError()
|
||||||
.content_type("text/html")
|
.content_type("text/html")
|
||||||
.body(P500.as_slice())
|
.body(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_response(&self) -> HttpResponse {
|
fn render_response(&self) -> HttpResponse {
|
||||||
HttpResponse::InternalServerError()
|
self.error_response()
|
||||||
.content_type("text/html")
|
|
||||||
.body(P500.as_slice())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
122
src/main.rs
122
src/main.rs
@ -1,3 +1,5 @@
|
|||||||
|
#![type_length_limit = "2257138"]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate actix_web;
|
extern crate actix_web;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@ -9,6 +11,7 @@ extern crate serde_derive;
|
|||||||
|
|
||||||
mod cache;
|
mod cache;
|
||||||
mod config;
|
mod config;
|
||||||
|
mod count;
|
||||||
mod error;
|
mod error;
|
||||||
mod service;
|
mod service;
|
||||||
mod statics;
|
mod statics;
|
||||||
@ -17,7 +20,7 @@ use crate::{
|
|||||||
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, INDEX, OPT, P404, P500, VERSION_INFO},
|
statics::{CLIENT, CSS, FAVICON, OPT, REPO_COUNT, VERSION_INFO},
|
||||||
};
|
};
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
error::ErrorBadRequest,
|
error::ErrorBadRequest,
|
||||||
@ -34,6 +37,7 @@ use std::{
|
|||||||
fs::create_dir_all,
|
fs::create_dir_all,
|
||||||
path::Path,
|
path::Path,
|
||||||
process::Command,
|
process::Command,
|
||||||
|
sync::atomic::Ordering,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
time::{Duration, SystemTime},
|
time::{Duration, SystemTime},
|
||||||
};
|
};
|
||||||
@ -52,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")?;
|
||||||
@ -146,45 +156,55 @@ where
|
|||||||
T: Service,
|
T: Service,
|
||||||
F: Fn(HocResult) -> Result<HttpResponse>,
|
F: Fn(HocResult) -> Result<HttpResponse>,
|
||||||
{
|
{
|
||||||
hoc_request::<T>(state, data).and_then(mapper)
|
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);
|
||||||
|
let file = Path::new(&path);
|
||||||
|
let url = format!("https://{}", service_path);
|
||||||
|
if !file.exists() {
|
||||||
|
if !remote_exists(&url)? {
|
||||||
|
warn!("Repository does not exist: {}", url);
|
||||||
|
return Ok(HocResult::NotFound);
|
||||||
|
}
|
||||||
|
info!("Cloning {} for the first time", url);
|
||||||
|
create_dir_all(file)?;
|
||||||
|
let repo = Repository::init_bare(file)?;
|
||||||
|
repo.remote_add_fetch("origin", "refs/heads/*:refs/heads/*")?;
|
||||||
|
repo.remote_set_url("origin", &url)?;
|
||||||
|
REPO_COUNT.fetch_add(1, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
pull(&path)?;
|
||||||
|
let (hoc, head) = hoc(&service_path, &state.repos, &state.cache)?;
|
||||||
|
let hoc_pretty = match NumberPrefix::decimal(hoc as f64) {
|
||||||
|
Standalone(hoc) => hoc.to_string(),
|
||||||
|
Prefixed(prefix, hoc) => format!("{:.1}{}", hoc, prefix),
|
||||||
|
};
|
||||||
|
Ok(HocResult::Hoc {
|
||||||
|
hoc,
|
||||||
|
hoc_pretty,
|
||||||
|
head,
|
||||||
|
url,
|
||||||
|
repo,
|
||||||
|
service_path,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.and_then(mapper)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hoc_request<T: Service>(
|
fn json_hoc<T: Service>(
|
||||||
state: web::Data<Arc<State>>,
|
state: web::Data<Arc<State>>,
|
||||||
data: web::Path<(String, String)>,
|
data: web::Path<(String, String)>,
|
||||||
) -> impl Future<Item = HocResult, Error = Error> {
|
) -> impl Future<Item = HttpResponse, Error = Error> {
|
||||||
futures::future::result(Ok(())).and_then(move |_| {
|
let mapper = |r| match r {
|
||||||
let repo = format!("{}/{}", data.0.to_lowercase(), data.1.to_lowercase());
|
HocResult::NotFound => p404(),
|
||||||
let service_path = format!("{}/{}", T::domain(), repo);
|
HocResult::Hoc { hoc, head, .. } => Ok(HttpResponse::Ok().json(JsonResponse {
|
||||||
let path = format!("{}/{}", state.repos, service_path);
|
head: &head,
|
||||||
let file = Path::new(&path);
|
count: hoc,
|
||||||
let url = format!("https://{}", service_path);
|
})),
|
||||||
if !file.exists() {
|
};
|
||||||
if !remote_exists(&url)? {
|
handle_hoc_request::<T, _>(state, data, mapper)
|
||||||
warn!("Repository does not exist: {}", url);
|
|
||||||
return Ok(HocResult::NotFound);
|
|
||||||
}
|
|
||||||
info!("Cloning {} for the first time", url);
|
|
||||||
create_dir_all(file)?;
|
|
||||||
let repo = Repository::init_bare(file)?;
|
|
||||||
repo.remote_add_fetch("origin", "refs/heads/*:refs/heads/*")?;
|
|
||||||
repo.remote_set_url("origin", &url)?;
|
|
||||||
}
|
|
||||||
pull(&path)?;
|
|
||||||
let (hoc, head) = hoc(&service_path, &state.repos, &state.cache)?;
|
|
||||||
let hoc_pretty = match NumberPrefix::decimal(hoc as f64) {
|
|
||||||
Standalone(hoc) => hoc.to_string(),
|
|
||||||
Prefixed(prefix, hoc) => format!("{:.1}{}", hoc, prefix),
|
|
||||||
};
|
|
||||||
Ok(HocResult::Hoc {
|
|
||||||
hoc,
|
|
||||||
hoc_pretty,
|
|
||||||
head,
|
|
||||||
url,
|
|
||||||
repo,
|
|
||||||
service_path,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn calculate_hoc<T: Service>(
|
fn calculate_hoc<T: Service>(
|
||||||
@ -192,7 +212,7 @@ fn calculate_hoc<T: Service>(
|
|||||||
data: web::Path<(String, String)>,
|
data: web::Path<(String, String)>,
|
||||||
) -> impl Future<Item = HttpResponse, Error = Error> {
|
) -> impl Future<Item = HttpResponse, Error = Error> {
|
||||||
let mapper = |r| match r {
|
let mapper = |r| match r {
|
||||||
HocResult::NotFound => Ok(p404()),
|
HocResult::NotFound => p404(),
|
||||||
HocResult::Hoc { hoc_pretty, .. } => {
|
HocResult::Hoc { hoc_pretty, .. } => {
|
||||||
let badge_opt = BadgeOptions {
|
let badge_opt = BadgeOptions {
|
||||||
subject: "Hits-of-Code".to_string(),
|
subject: "Hits-of-Code".to_string(),
|
||||||
@ -225,7 +245,7 @@ fn overview<T: Service>(
|
|||||||
data: web::Path<(String, String)>,
|
data: web::Path<(String, String)>,
|
||||||
) -> impl Future<Item = HttpResponse, Error = Error> {
|
) -> impl Future<Item = HttpResponse, Error = Error> {
|
||||||
let mapper = |r| match r {
|
let mapper = |r| match r {
|
||||||
HocResult::NotFound => Ok(p404()),
|
HocResult::NotFound => p404(),
|
||||||
HocResult::Hoc {
|
HocResult::Hoc {
|
||||||
hoc,
|
hoc,
|
||||||
hoc_pretty,
|
hoc_pretty,
|
||||||
@ -238,6 +258,7 @@ fn overview<T: Service>(
|
|||||||
templates::overview(
|
templates::overview(
|
||||||
&mut buf,
|
&mut buf,
|
||||||
VERSION_INFO,
|
VERSION_INFO,
|
||||||
|
REPO_COUNT.load(Ordering::Relaxed),
|
||||||
&OPT.domain,
|
&OPT.domain,
|
||||||
&service_path,
|
&service_path,
|
||||||
&url,
|
&url,
|
||||||
@ -259,10 +280,15 @@ fn overview<T: Service>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
fn index() -> HttpResponse {
|
fn index() -> Result<HttpResponse> {
|
||||||
HttpResponse::Ok()
|
let mut buf = Vec::new();
|
||||||
.content_type("text/html")
|
templates::index(
|
||||||
.body(INDEX.as_slice())
|
&mut buf,
|
||||||
|
VERSION_INFO,
|
||||||
|
REPO_COUNT.load(Ordering::Relaxed),
|
||||||
|
&OPT.domain,
|
||||||
|
)?;
|
||||||
|
Ok(HttpResponse::Ok().content_type("text/html").body(buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/generate")]
|
#[post("/generate")]
|
||||||
@ -272,6 +298,7 @@ fn generate(params: web::Form<GeneratorForm>) -> Result<HttpResponse> {
|
|||||||
templates::generate(
|
templates::generate(
|
||||||
&mut buf,
|
&mut buf,
|
||||||
VERSION_INFO,
|
VERSION_INFO,
|
||||||
|
REPO_COUNT.load(Ordering::Relaxed),
|
||||||
&OPT.domain,
|
&OPT.domain,
|
||||||
params.service.url(),
|
params.service.url(),
|
||||||
params.service.service(),
|
params.service.service(),
|
||||||
@ -285,10 +312,10 @@ fn generate(params: web::Form<GeneratorForm>) -> Result<HttpResponse> {
|
|||||||
.streaming(rx_body.map_err(|_| ErrorBadRequest("bad request"))))
|
.streaming(rx_body.map_err(|_| ErrorBadRequest("bad request"))))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn p404() -> HttpResponse {
|
fn p404() -> Result<HttpResponse> {
|
||||||
HttpResponse::NotFound()
|
let mut buf = Vec::new();
|
||||||
.content_type("text/html")
|
templates::p404(&mut buf, VERSION_INFO, REPO_COUNT.load(Ordering::Relaxed))?;
|
||||||
.body(P404.as_slice())
|
Ok(HttpResponse::NotFound().content_type("text/html").body(buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/tacit-css.min.css")]
|
#[get("/tacit-css.min.css")]
|
||||||
@ -319,6 +346,9 @@ fn main() -> Result<()> {
|
|||||||
.service(web::resource("/github/{user}/{repo}").to_async(calculate_hoc::<GitHub>))
|
.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("/gitlab/{user}/{repo}").to_async(calculate_hoc::<Gitlab>))
|
||||||
.service(web::resource("/bitbucket/{user}/{repo}").to_async(calculate_hoc::<Bitbucket>))
|
.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/github/{user}/{repo}").to_async(overview::<GitHub>))
|
||||||
.service(web::resource("/view/gitlab/{user}/{repo}").to_async(overview::<Gitlab>))
|
.service(web::resource("/view/gitlab/{user}/{repo}").to_async(overview::<Gitlab>))
|
||||||
.service(web::resource("/view/bitbucket/{user}/{repo}").to_async(overview::<Bitbucket>))
|
.service(web::resource("/view/bitbucket/{user}/{repo}").to_async(overview::<Bitbucket>))
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use crate::{config::Opt, templates};
|
use crate::{config::Opt, count::count_repositories};
|
||||||
|
use std::sync::atomic::AtomicUsize;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
pub struct VersionInfo<'a> {
|
pub struct VersionInfo<'a> {
|
||||||
@ -16,19 +17,6 @@ pub(crate) const FAVICON: &[u8] = include_bytes!("../static/favicon32.png");
|
|||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub(crate) static ref CLIENT: reqwest::Client = reqwest::Client::new();
|
pub(crate) static ref CLIENT: reqwest::Client = reqwest::Client::new();
|
||||||
pub(crate) static ref OPT: Opt = Opt::from_args();
|
pub(crate) static ref OPT: Opt = Opt::from_args();
|
||||||
pub(crate) static ref INDEX: Vec<u8> = {
|
pub(crate) static ref REPO_COUNT: AtomicUsize =
|
||||||
let mut buf = Vec::new();
|
AtomicUsize::new(count_repositories(&OPT.outdir).unwrap());
|
||||||
templates::index(&mut buf, VERSION_INFO, &OPT.domain).unwrap();
|
|
||||||
buf
|
|
||||||
};
|
|
||||||
pub(crate) static ref P404: Vec<u8> = {
|
|
||||||
let mut buf = Vec::new();
|
|
||||||
templates::p404(&mut buf, VERSION_INFO).unwrap();
|
|
||||||
buf
|
|
||||||
};
|
|
||||||
pub(crate) static ref P500: Vec<u8> = {
|
|
||||||
let mut buf = Vec::new();
|
|
||||||
templates::p500(&mut buf, VERSION_INFO).unwrap();
|
|
||||||
buf
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
@use crate::statics::VersionInfo;
|
@use crate::statics::VersionInfo;
|
||||||
|
|
||||||
@(title: &str, header: &str, content: Content, version_info: VersionInfo)
|
@(title: &str, header: &str, content: Content, version_info: VersionInfo, repo_count: usize)
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
@ -38,6 +38,13 @@
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
<nav>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<small>Currently serving @repo_count repositories</small>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
<nav>
|
<nav>
|
||||||
<ul>
|
<ul>
|
||||||
<li><small><a href="https://github.com/vbrandl/hoc">GitHub</a></small></li>
|
<li><small><a href="https://github.com/vbrandl/hoc">GitHub</a></small></li>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
@use super::base;
|
@use super::base;
|
||||||
@use crate::statics::VersionInfo;
|
@use crate::statics::VersionInfo;
|
||||||
|
|
||||||
@(version_info: VersionInfo, domain: &str, url: &str, service: &str, path: &str)
|
@(version_info: VersionInfo, repo_count: usize, domain: &str, url: &str, service: &str, path: &str)
|
||||||
|
|
||||||
@:base("Hits-of-Code Badges", "Badge Generator", {
|
@:base("Hits-of-Code Badges", "Badge Generator", {
|
||||||
|
|
||||||
@ -20,4 +20,4 @@ It will be rendered like this
|
|||||||
<pre>
|
<pre>
|
||||||
<a href="https://@domain/view/@service/@path"><img src="https://@domain/@service/@path" alt="example badge" /></a>
|
<a href="https://@domain/view/@service/@path"><img src="https://@domain/@service/@path" alt="example badge" /></a>
|
||||||
</pre>
|
</pre>
|
||||||
}, version_info)
|
}, version_info, repo_count)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
@use super::base;
|
@use super::base;
|
||||||
@use crate::statics::VersionInfo;
|
@use crate::statics::VersionInfo;
|
||||||
|
|
||||||
@(version_info: VersionInfo, domain: &str)
|
@(version_info: VersionInfo, repo_count: usize, domain: &str)
|
||||||
|
|
||||||
@:base("Hits-of-Code Badges", "Hits-of-Code Badges", {
|
@:base("Hits-of-Code Badges", "Hits-of-Code Badges", {
|
||||||
|
|
||||||
@ -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>
|
||||||
|
{
|
||||||
|
"head" : "05736ee3ba256ec9a7227c436aef2bf43db109ab",
|
||||||
|
"count": 7582
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
|
||||||
<h2>Badge Generator</h2>
|
<h2>Badge Generator</h2>
|
||||||
|
|
||||||
<form method="post" action="/generate">
|
<form method="post" action="/generate">
|
||||||
@ -76,4 +91,4 @@ my <a href="https://mirror.oldsql.cc/key.asc">GPG key</a>
|
|||||||
(<a href="http://pool.sks-keyservers.net/pks/lookup?op=get&search=0x1FFE431282F4B8CC0A7579167FB009175885FC76">from a
|
(<a href="http://pool.sks-keyservers.net/pks/lookup?op=get&search=0x1FFE431282F4B8CC0A7579167FB009175885FC76">from a
|
||||||
keyserver</a>), or by using any other UID from my key.
|
keyserver</a>), or by using any other UID from my key.
|
||||||
</p>
|
</p>
|
||||||
}, version_info)
|
}, version_info, repo_count)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
@use super::base;
|
@use super::base;
|
||||||
@use crate::statics::VersionInfo;
|
@use crate::statics::VersionInfo;
|
||||||
|
|
||||||
@(version_info: VersionInfo, domain: &str, path: &str, url: &str, hoc: u64, hoc_pretty: &str, head: &str, commit_url: &str)
|
@(version_info: VersionInfo, repo_count: usize, domain: &str, path: &str, url: &str, hoc: u64, hoc_pretty: &str, head: &str, commit_url: &str)
|
||||||
|
|
||||||
@:base("Hits-of-Code Badges", "Overview", {
|
@:base("Hits-of-Code Badges", "Overview", {
|
||||||
|
|
||||||
@ -16,4 +16,4 @@ To include the badge in your readme, use the following markdown:
|
|||||||
<pre>
|
<pre>
|
||||||
[](https://@domain/view/@path)
|
[](https://@domain/view/@path)
|
||||||
</pre>
|
</pre>
|
||||||
}, version_info)
|
}, version_info, repo_count)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
@use super::base;
|
@use super::base;
|
||||||
@use crate::statics::VersionInfo;
|
@use crate::statics::VersionInfo;
|
||||||
|
|
||||||
@(version_info: VersionInfo)
|
@(version_info: VersionInfo, repo_count: usize)
|
||||||
|
|
||||||
@:base("Page not Found - Hits-of-Code Badges", "404 - Page not Found", {
|
@:base("Page not Found - Hits-of-Code Badges", "404 - Page not Found", {
|
||||||
<p>
|
<p>
|
||||||
@ -11,4 +11,4 @@
|
|||||||
<p>
|
<p>
|
||||||
If you think, this is a mistake on my side, please <a href="mailto:mail+hoc@@vbrandl.net">drop me a mail</a>.
|
If you think, this is a mistake on my side, please <a href="mailto:mail+hoc@@vbrandl.net">drop me a mail</a>.
|
||||||
</p>
|
</p>
|
||||||
}, version_info)
|
}, version_info, repo_count)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
@use super::base;
|
@use super::base;
|
||||||
@use crate::statics::VersionInfo;
|
@use crate::statics::VersionInfo;
|
||||||
|
|
||||||
@(version_info: VersionInfo)
|
@(version_info: VersionInfo, repo_count: usize)
|
||||||
|
|
||||||
@:base("Internal Server Error - Hits-of-Code Badges", "500 - Internal Server Error", {
|
@:base("Internal Server Error - Hits-of-Code Badges", "500 - Internal Server Error", {
|
||||||
<p>
|
<p>
|
||||||
@ -11,4 +11,4 @@
|
|||||||
<p>
|
<p>
|
||||||
If you think, this is a bug, please <a href="mailto:mail+hoc@@vbrandl.net">drop me a mail</a>.
|
If you think, this is a bug, please <a href="mailto:mail+hoc@@vbrandl.net">drop me a mail</a>.
|
||||||
</p>
|
</p>
|
||||||
}, version_info)
|
}, version_info, repo_count)
|
||||||
|
Reference in New Issue
Block a user