Compare commits
80 Commits
feature/tr
...
v0.20.2
Author | SHA1 | Date | |
---|---|---|---|
bdd25aefd6 | |||
2444b29734 | |||
d298e5ecdb | |||
3ecab29cdd | |||
c4638dc8aa | |||
7ffa2ba9a2 | |||
10f4390b75 | |||
a3b224a8df | |||
45e20edb2b | |||
db763ff817 | |||
449e1347f4 | |||
d57df16509 | |||
c1c499e003 | |||
225d652545 | |||
948f06ba33 | |||
dcd8c41bb3 | |||
0ab2c60f06 | |||
d20da8b1e3 | |||
ffd1378b44 | |||
ecce255ee2 | |||
69410f10b6 | |||
340220d4ce | |||
27fb116d26 | |||
228a1767f2 | |||
7a45bc2d2e | |||
f02b05f4e9 | |||
04b58e53a6 | |||
849ccb58d2 | |||
aeeb688be2 | |||
89b5d8cc60 | |||
19cae24133 | |||
656cc009e1 | |||
47c8229eb1 | |||
fba5070e8f | |||
732f7b0ed9 | |||
ecf34928f7 | |||
d0242e6e2e | |||
aacff0e63e | |||
d5f4304a60 | |||
622a5a335a | |||
8f16fdf33c | |||
792a1f5743 | |||
9900518d62 | |||
d37f5ba32b | |||
bcb5650cc9 | |||
dff8151938 | |||
9d71ef14fc | |||
888e85b1f4 | |||
73e0bfad92 | |||
ae4266044b | |||
c5bae481da | |||
d71656295f | |||
565a2e3129 | |||
e2da36d2e9 | |||
ad770f71ec | |||
f6d47baefd | |||
44d47b1d5f | |||
f87b6ee8f4 | |||
6322e6e7e3 | |||
39592effd2 | |||
632638ddd8 | |||
c4e31f2f67 | |||
46d7ae030e | |||
3a57fcca9d | |||
3051bdc0c7 | |||
e267a4fc8a | |||
441ab76ca6 | |||
155d79a019 | |||
1fe39fbd3c | |||
1fae322993 | |||
13c193d04a | |||
701299ab5b | |||
2277931d3c | |||
6c59acc0ab | |||
79d947fb36 | |||
a1133259c2 | |||
9eb47bd94b | |||
8f6c52a6f5 | |||
b50112c7c0 | |||
62c80a81de |
1414
Cargo.lock
generated
1414
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
37
Cargo.toml
37
Cargo.toml
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "hoc"
|
name = "hoc"
|
||||||
version = "0.17.2"
|
version = "0.20.2"
|
||||||
authors = ["Valentin Brandl <vbrandl@riseup.net>"]
|
authors = ["Valentin Brandl <vbrandl@riseup.net>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
@ -13,33 +13,34 @@ path = "src/main.rs"
|
|||||||
name = "hoc"
|
name = "hoc"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-rt = "1.1.1"
|
actix-rt = "2.3.0"
|
||||||
actix-web = "3.3.2"
|
actix-web = "4.0.0-beta.8"
|
||||||
badge = "0.3.0"
|
badge = "0.3.0"
|
||||||
bytes = "1.0.1"
|
bytes = "1.1.0"
|
||||||
config = { version = "0.11.0", features = ["toml"] }
|
config = { version = "0.11.0", features = ["toml"] }
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
futures = "0.3.15"
|
futures = "0.3.17"
|
||||||
git2 = "0.13.18"
|
git2 = "0.13.23"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
number_prefix = "0.4.0"
|
number_prefix = "0.4.0"
|
||||||
openssl-probe = "0.1.4"
|
openssl-probe = "0.1.4"
|
||||||
reqwest = "0.10.10"
|
reqwest = "0.11.6"
|
||||||
serde = "1.0.126"
|
serde = "1.0.130"
|
||||||
serde_derive = "1.0.123"
|
serde_derive = "1.0.130"
|
||||||
serde_json = "1.0.64"
|
serde_json = "1.0.68"
|
||||||
tracing = "0.1.26"
|
tracing = "0.1.29"
|
||||||
tracing-actix-web = "0.2.1"
|
tracing-actix-web = "0.4.0-beta.14"
|
||||||
tracing-bunyan-formatter = "0.2.4"
|
tracing-bunyan-formatter = "0.3.0"
|
||||||
tracing-futures = "0.2.5"
|
tracing-futures = "0.2.5"
|
||||||
tracing-log = "0.1.2"
|
tracing-log = "0.1.2"
|
||||||
tracing-subscriber = { version = "0.2.18", features = ["registry", "env-filter"] }
|
tracing-subscriber = { version = "0.3.1", features = ["registry", "env-filter"] }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
ructe = "0.13.2"
|
ructe = "0.13.4"
|
||||||
vergen = { version = "5.1.2", default-features = false, features = ["git"] }
|
vergen = { version = "5.1.16", default-features = false, features = ["git"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
ructe = "0.13.2"
|
awc = "3.0.0-beta.9"
|
||||||
|
ructe = "0.13.4"
|
||||||
tempfile = "3.2.0"
|
tempfile = "3.2.0"
|
||||||
tokio = "0.2.25"
|
tokio = "1.12.0"
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
FROM ekidd/rust-musl-builder:stable as builder
|
FROM ekidd/rust-musl-builder:stable as builder
|
||||||
|
|
||||||
# create new cargo project
|
# create new cargo project
|
||||||
RUN USER=rust cargo init --bin
|
RUN USER=rust cargo init --lib
|
||||||
|
RUN echo 'fn main() { println!("Hello, world!"); }' >> src/main.rs
|
||||||
# copy build config
|
# copy build config
|
||||||
COPY --chown=rust ./Cargo.lock ./Cargo.lock
|
COPY --chown=rust ./Cargo.lock ./Cargo.lock
|
||||||
COPY ./Cargo.toml ./Cargo.toml
|
COPY ./Cargo.toml ./Cargo.toml
|
||||||
|
@ -19,8 +19,8 @@ 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`. The HoC data can also be received as JSON by appending
|
where `<service>` is one of `gitub`, `gitlab`, `bitbucket` or `sourcehut`. The HoC data can also be received as JSON by
|
||||||
`/json` to the reuqest path:
|
appending `/json` to the reuqest path:
|
||||||
|
|
||||||
```
|
```
|
||||||
https://<host>/<service>/<user>/<repo>/json
|
https://<host>/<service>/<user>/<repo>/json
|
||||||
|
23
src/lib.rs
23
src/lib.rs
@ -22,14 +22,14 @@ use crate::{
|
|||||||
cache::CacheState,
|
cache::CacheState,
|
||||||
config::Settings,
|
config::Settings,
|
||||||
error::{Error, Result},
|
error::{Error, Result},
|
||||||
service::{Bitbucket, FormService, GitHub, Gitlab, Service},
|
service::{Bitbucket, FormService, GitHub, Gitlab, Service, Sourcehut},
|
||||||
statics::{CLIENT, CSS, FAVICON, VERSION_INFO},
|
statics::{CLIENT, CSS, FAVICON, VERSION_INFO},
|
||||||
template::RepoInfo,
|
template::RepoInfo,
|
||||||
};
|
};
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
dev::Server,
|
dev::Server,
|
||||||
http::header::{CacheControl, CacheDirective, Expires, LOCATION},
|
http::header::{CacheControl, CacheDirective, Expires, LOCATION},
|
||||||
middleware::{self, normalize::TrailingSlash},
|
middleware::{self, TrailingSlash},
|
||||||
web, App, HttpResponse, HttpServer, Responder,
|
web, App, HttpResponse, HttpServer, Responder,
|
||||||
};
|
};
|
||||||
use badge::{Badge, BadgeOptions};
|
use badge::{Badge, BadgeOptions};
|
||||||
@ -224,10 +224,10 @@ where
|
|||||||
})?;
|
})?;
|
||||||
repo_count.fetch_sub(1, Ordering::Relaxed);
|
repo_count.fetch_sub(1, Ordering::Relaxed);
|
||||||
Ok(HttpResponse::TemporaryRedirect()
|
Ok(HttpResponse::TemporaryRedirect()
|
||||||
.header(
|
.insert_header((
|
||||||
LOCATION,
|
LOCATION,
|
||||||
format!("/{}/{}/{}/view", T::url_path(), data.0, data.1),
|
format!("/{}/{}/{}/view", T::url_path(), data.0, data.1),
|
||||||
)
|
))
|
||||||
.finish())
|
.finish())
|
||||||
};
|
};
|
||||||
future.instrument(span).await
|
future.instrument(span).await
|
||||||
@ -318,8 +318,8 @@ fn no_cache_response(body: Vec<u8>) -> HttpResponse {
|
|||||||
let expiration = SystemTime::now() + Duration::from_secs(30);
|
let expiration = SystemTime::now() + Duration::from_secs(30);
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.content_type("image/svg+xml")
|
.content_type("image/svg+xml")
|
||||||
.set(Expires(expiration.into()))
|
.insert_header(Expires(expiration.into()))
|
||||||
.set(CacheControl(vec![
|
.insert_header(CacheControl(vec![
|
||||||
CacheDirective::MaxAge(0u32),
|
CacheDirective::MaxAge(0u32),
|
||||||
CacheDirective::MustRevalidate,
|
CacheDirective::MustRevalidate,
|
||||||
CacheDirective::NoCache,
|
CacheDirective::NoCache,
|
||||||
@ -480,7 +480,7 @@ async fn start_server(listener: TcpListener, settings: Settings) -> std::io::Res
|
|||||||
App::new()
|
App::new()
|
||||||
.app_data(state.clone())
|
.app_data(state.clone())
|
||||||
.app_data(repo_count.clone())
|
.app_data(repo_count.clone())
|
||||||
.wrap(tracing_actix_web::TracingLogger)
|
.wrap(tracing_actix_web::TracingLogger::default())
|
||||||
.wrap(middleware::NormalizePath::new(TrailingSlash::Trim))
|
.wrap(middleware::NormalizePath::new(TrailingSlash::Trim))
|
||||||
.service(index)
|
.service(index)
|
||||||
.service(health_check)
|
.service(health_check)
|
||||||
@ -490,6 +490,7 @@ async fn start_server(listener: TcpListener, settings: Settings) -> std::io::Res
|
|||||||
.service(web::resource("/github/{user}/{repo}").to(calculate_hoc::<GitHub>))
|
.service(web::resource("/github/{user}/{repo}").to(calculate_hoc::<GitHub>))
|
||||||
.service(web::resource("/gitlab/{user}/{repo}").to(calculate_hoc::<Gitlab>))
|
.service(web::resource("/gitlab/{user}/{repo}").to(calculate_hoc::<Gitlab>))
|
||||||
.service(web::resource("/bitbucket/{user}/{repo}").to(calculate_hoc::<Bitbucket>))
|
.service(web::resource("/bitbucket/{user}/{repo}").to(calculate_hoc::<Bitbucket>))
|
||||||
|
.service(web::resource("/sourcehut/{user}/{repo}").to(calculate_hoc::<Sourcehut>))
|
||||||
.service(
|
.service(
|
||||||
web::resource("/github/{user}/{repo}/delete")
|
web::resource("/github/{user}/{repo}/delete")
|
||||||
.route(web::post().to(delete_repo_and_cache::<GitHub>)),
|
.route(web::post().to(delete_repo_and_cache::<GitHub>)),
|
||||||
@ -502,16 +503,22 @@ async fn start_server(listener: TcpListener, settings: Settings) -> std::io::Res
|
|||||||
web::resource("/bitbucket/{user}/{repo}/delete")
|
web::resource("/bitbucket/{user}/{repo}/delete")
|
||||||
.route(web::post().to(delete_repo_and_cache::<Bitbucket>)),
|
.route(web::post().to(delete_repo_and_cache::<Bitbucket>)),
|
||||||
)
|
)
|
||||||
|
.service(
|
||||||
|
web::resource("/sourcehut/{user}/{repo}/delete")
|
||||||
|
.route(web::post().to(delete_repo_and_cache::<Sourcehut>)),
|
||||||
|
)
|
||||||
.service(web::resource("/github/{user}/{repo}/json").to(json_hoc::<GitHub>))
|
.service(web::resource("/github/{user}/{repo}/json").to(json_hoc::<GitHub>))
|
||||||
.service(web::resource("/gitlab/{user}/{repo}/json").to(json_hoc::<Gitlab>))
|
.service(web::resource("/gitlab/{user}/{repo}/json").to(json_hoc::<Gitlab>))
|
||||||
.service(web::resource("/bitbucket/{user}/{repo}/json").to(json_hoc::<Bitbucket>))
|
.service(web::resource("/bitbucket/{user}/{repo}/json").to(json_hoc::<Bitbucket>))
|
||||||
|
.service(web::resource("/sourcehut/{user}/{repo}/json").to(json_hoc::<Sourcehut>))
|
||||||
.service(web::resource("/view/github/{user}/{repo}").to(overview::<GitHub>))
|
.service(web::resource("/view/github/{user}/{repo}").to(overview::<GitHub>))
|
||||||
.service(web::resource("/view/gitlab/{user}/{repo}").to(overview::<Gitlab>))
|
.service(web::resource("/view/gitlab/{user}/{repo}").to(overview::<Gitlab>))
|
||||||
.service(web::resource("/view/bitbucket/{user}/{repo}").to(overview::<Bitbucket>))
|
.service(web::resource("/view/bitbucket/{user}/{repo}").to(overview::<Bitbucket>))
|
||||||
.service(web::resource("/github/{user}/{repo}/view").to(overview::<GitHub>))
|
.service(web::resource("/github/{user}/{repo}/view").to(overview::<GitHub>))
|
||||||
.service(web::resource("/gitlab/{user}/{repo}/view").to(overview::<Gitlab>))
|
.service(web::resource("/gitlab/{user}/{repo}/view").to(overview::<Gitlab>))
|
||||||
.service(web::resource("/bitbucket/{user}/{repo}/view").to(overview::<Bitbucket>))
|
.service(web::resource("/bitbucket/{user}/{repo}/view").to(overview::<Bitbucket>))
|
||||||
.default_service(web::resource("").route(web::get().to(async_p404)))
|
.service(web::resource("/sourcehut/{user}/{repo}/view").to(overview::<Sourcehut>))
|
||||||
|
.default_service(web::to(async_p404))
|
||||||
})
|
})
|
||||||
.workers(workers)
|
.workers(workers)
|
||||||
.listen(listener)?
|
.listen(listener)?
|
||||||
|
@ -12,6 +12,8 @@ pub(crate) enum FormService {
|
|||||||
Gitlab,
|
Gitlab,
|
||||||
#[serde(rename = "bitbucket")]
|
#[serde(rename = "bitbucket")]
|
||||||
Bitbucket,
|
Bitbucket,
|
||||||
|
#[serde(rename = "sourcehut")]
|
||||||
|
Sourcehut,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FormService {
|
impl FormService {
|
||||||
@ -20,6 +22,7 @@ impl FormService {
|
|||||||
FormService::GitHub => "github.com",
|
FormService::GitHub => "github.com",
|
||||||
FormService::Gitlab => "gitlab.com",
|
FormService::Gitlab => "gitlab.com",
|
||||||
FormService::Bitbucket => "bitbucket.org",
|
FormService::Bitbucket => "bitbucket.org",
|
||||||
|
FormService::Sourcehut => "git.sr.ht",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,6 +31,7 @@ impl FormService {
|
|||||||
FormService::GitHub => "github",
|
FormService::GitHub => "github",
|
||||||
FormService::Gitlab => "gitlab",
|
FormService::Gitlab => "gitlab",
|
||||||
FormService::Bitbucket => "bitbucket",
|
FormService::Bitbucket => "bitbucket",
|
||||||
|
FormService::Sourcehut => "sourcehut",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,3 +77,17 @@ impl Service for Bitbucket {
|
|||||||
format!("https://{}/{}/commits/{}", Self::domain(), repo, commit_ref)
|
format!("https://{}/{}/commits/{}", Self::domain(), repo, commit_ref)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) struct Sourcehut;
|
||||||
|
|
||||||
|
impl Service for Sourcehut {
|
||||||
|
fn domain() -> &'static str {
|
||||||
|
"git.sr.ht"
|
||||||
|
}
|
||||||
|
fn url_path() -> &'static str {
|
||||||
|
"sourcehut"
|
||||||
|
}
|
||||||
|
fn commit_url(repo: &str, commit_ref: &str) -> String {
|
||||||
|
format!("https://{}/{}/commit/{}", Self::domain(), repo, commit_ref)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
4
static/tacit-css.min.css
vendored
4
static/tacit-css.min.css
vendored
File diff suppressed because one or more lines are too long
@ -20,7 +20,7 @@ gives an overview about the amount of work put into a codebase.
|
|||||||
<p>
|
<p>
|
||||||
There is a <a href="https://github.com/yegor256/hoc/">command-line tool</a> to calculate the HoC of a repository, but
|
There is a <a href="https://github.com/yegor256/hoc/">command-line tool</a> to calculate the HoC of a repository, but
|
||||||
some people might want a nice badge to put in their README, that's why I implemented this API. Currently the API can be
|
some people might want a nice badge to put in their README, that's why I implemented this API. Currently the API can be
|
||||||
used for GitHub, GitLab and Bitbucket repositories. Just put the following code in your README:
|
used for GitHub, GitLab, Bitbucket and Sourcehut repositories. Just put the following code in your README:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
@ -28,8 +28,8 @@ used for GitHub, GitLab and Bitbucket repositories. Just put the following code
|
|||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
where <code><service></code> is one of <code>github</code>, <code>gitlab</code> or <code>bitbucket</code>. So the
|
where <code><service></code> is one of <code>github</code>, <code>gitlab</code>, <code>bitbucket</code> or
|
||||||
following Markdown
|
<code>sourcehut</code>. So the following Markdown
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
@ -74,6 +74,7 @@ the lines of
|
|||||||
<option value="github">GitHub</option>
|
<option value="github">GitHub</option>
|
||||||
<option value="gitlab">Gitlab</option>
|
<option value="gitlab">Gitlab</option>
|
||||||
<option value="bitbucket">Bitbucket</option>
|
<option value="bitbucket">Bitbucket</option>
|
||||||
|
<option value="sourcehut">Sourcehut</option>
|
||||||
</select>
|
</select>
|
||||||
<label>/</label>
|
<label>/</label>
|
||||||
<input name="user" id="user" type="text" placeholder="user" />
|
<input name="user" id="user" type="text" placeholder="user" />
|
||||||
@ -94,7 +95,7 @@ welcome.
|
|||||||
|
|
||||||
<p>
|
<p>
|
||||||
You can reach me via mail: <a href="mailto:mail+hoc@@vbrandl.net">mail+hoc@@vbrandl.net</a> preferably using
|
You can reach me via mail: <a href="mailto:mail+hoc@@vbrandl.net">mail+hoc@@vbrandl.net</a> preferably using
|
||||||
my <a href="https://mirror.oldsql.cc/key.asc">GPG key</a>
|
my <a href="https://www.vbrandl.net/static/keys/0x1FFE431282F4B8CC0A7579167FB009175885FC76.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>
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
use actix_web::client;
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn badge_succeeds() {
|
async fn badge_succeeds() {
|
||||||
let test_app = util::spawn_app().await;
|
let test_app = util::spawn_app().await;
|
||||||
|
|
||||||
let client = client::Client::default();
|
let client = awc::Client::default();
|
||||||
|
|
||||||
let response = client
|
let response = client
|
||||||
.get(&format!("{}/github/vbrandl/hoc", test_app.address))
|
.get(&format!("{}/github/vbrandl/hoc", test_app.address))
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
use actix_web::client;
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn health_check_works() {
|
async fn health_check_works() {
|
||||||
let test_app = util::spawn_app().await;
|
let test_app = util::spawn_app().await;
|
||||||
|
|
||||||
let client = client::Client::default();
|
let client = awc::Client::default();
|
||||||
|
|
||||||
let response = client
|
let response = client
|
||||||
.get(&format!("{}/health_check", test_app.address))
|
.get(&format!("{}/health_check", test_app.address))
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
use actix_web::client;
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn index_returns_success() {
|
async fn index_returns_success() {
|
||||||
let test_app = util::spawn_app().await;
|
let test_app = util::spawn_app().await;
|
||||||
|
|
||||||
let client = client::Client::default();
|
let client = awc::Client::default();
|
||||||
|
|
||||||
let response = client
|
let response = client
|
||||||
.get(&format!("{}/", test_app.address))
|
.get(&format!("{}/", test_app.address))
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
use actix_web::client;
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn json_returns_success() {
|
async fn json_returns_success() {
|
||||||
let test_app = util::spawn_app().await;
|
let test_app = util::spawn_app().await;
|
||||||
|
|
||||||
let client = client::Client::default();
|
let client = awc::Client::default();
|
||||||
|
|
||||||
let response = client
|
let response = client
|
||||||
.get(&format!("{}/github/vbrandl/hoc/json", test_app.address))
|
.get(&format!("{}/github/vbrandl/hoc/json", test_app.address))
|
||||||
|
Reference in New Issue
Block a user