Compare commits
147 Commits
feature/re
...
fix/clippy
Author | SHA1 | Date | |
---|---|---|---|
c0648c2b3c
|
|||
bfa9ac5621 | |||
7ad2ce62ce | |||
4eded27928 | |||
b1c6f6ddcb | |||
71a7948795 | |||
65be7b7182 | |||
800a57dea2 | |||
ef77138915 | |||
6e51f3068b | |||
9fb5cd83bb | |||
f6efaf5425 | |||
24bd6f0c57 | |||
a2eb11aa4f | |||
cfa484dd18 | |||
f3eaa83786 | |||
0281aa3100 | |||
ebfd779ac6 | |||
5a6a200dfc | |||
cafe5667e2 | |||
c8bd205e01 | |||
cc98174b5b | |||
3d84199cfb | |||
3888c8fbb1 | |||
620db7d074 | |||
eaec42be89 | |||
8e22814b4d | |||
e8cbbf6db8 | |||
24ca8b0bbc | |||
8df821536b | |||
751d52b640 | |||
5be61a3682 | |||
e88f058240 | |||
3e21b8342f | |||
77f6030b06 | |||
c993d9551e | |||
a6657a9f01 | |||
34d4bbcbf6 | |||
eda109e63a | |||
a4e8abfe70 | |||
43bca353d5 | |||
a9810ae704 | |||
d72eea53f0 | |||
3dd6d70371 | |||
81f99dba3d | |||
2d17185a39 | |||
88a3b3611b | |||
4b8730d6e0 | |||
25aea0f04d | |||
410a602638 | |||
894afaa75d | |||
29710d9263 | |||
d49a8d330b | |||
cb746c949b | |||
f4a83aad2c | |||
5765016163 | |||
8ded2da3ee | |||
a5c99fa7f5 | |||
caee48f4a4 | |||
18af42ed58 | |||
5505331599 | |||
deec0a0fa6 | |||
514960324c | |||
f86c59fe41 | |||
f7366f8939 | |||
0c0c2331b1 | |||
92f3a15384 | |||
93de768362 | |||
ebee3bb272 | |||
23587a7099 | |||
648e2b47ba | |||
6f58f1f769 | |||
b4bd8d2176 | |||
19bc8126a8 | |||
a790b6cca6 | |||
ae22e0f385 | |||
c9ccb2891c | |||
9fbbad7157 | |||
3789ddd152 | |||
f25e883fd1 | |||
a684341cd3 | |||
3f42a03fa8 | |||
8a71b308df | |||
37f8a1d32e | |||
84686aecdb | |||
208a6db95c | |||
d43ef2402e | |||
14e353fd26 | |||
0735399ff9 | |||
ef1e53637e | |||
453963193f | |||
7ebc300d6f | |||
0520679022 | |||
7b50187daa | |||
eb0c8904d8 | |||
0088b5f4b2 | |||
40b19c259c | |||
caebd865f6 | |||
232c870078 | |||
e12195a9b1 | |||
cb6423565c | |||
9ea6f7c96c | |||
9f0df6cdb4 | |||
13806d73ab | |||
b80817943b | |||
be39e8b757 | |||
49ba32ba94 | |||
2c08b3d6af | |||
fa0982b35c | |||
ca2fd495d7 | |||
a5c4c33d15 | |||
1431f7263f | |||
e5df767723 | |||
e446b77536 | |||
c6ca7401ce | |||
e3ed0a2417 | |||
87bae1bbd1 | |||
a64f55f362 | |||
9f3c2813ab | |||
4ce8c9e523 | |||
361eacbe1d | |||
b07c732475 | |||
fddb3dd3d6 | |||
f433f27229 | |||
8d7e97ba11 | |||
59ce8e2b57 | |||
2e5dcf4ef5 | |||
739162d2cd | |||
4be1d9881b | |||
f9e5175773 | |||
96ca6bda04 | |||
df96fcb091 | |||
1bae5a2b99 | |||
5924f2ab23 | |||
202c9ba03e | |||
8123b59e33 | |||
7bb8e82c3b | |||
5f1fc70a05 | |||
d60462f7ce | |||
4ce55c8e32 | |||
1a8db00ce4 | |||
c304164935 | |||
e2594b3c5b | |||
12c400e5b8 | |||
745a9021cd | |||
4bb0c8adc7 | |||
e7cf23c625 |
2
.github/workflows/audit.yml
vendored
2
.github/workflows/audit.yml
vendored
@ -16,6 +16,6 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions-rs/audit-check@v1
|
- uses: rustsec/audit-check@v1
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
37
.github/workflows/rust.yml
vendored
37
.github/workflows/rust.yml
vendored
@ -16,18 +16,11 @@ jobs:
|
|||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Install stable toolchain
|
- name: Install stable toolchain
|
||||||
uses: actions-rs/toolchain@v1
|
uses: dtolnay/rust-toolchain@stable
|
||||||
with:
|
|
||||||
toolchain: stable
|
|
||||||
profile: minimal
|
|
||||||
override: true
|
|
||||||
components: rustfmt
|
|
||||||
|
|
||||||
- name: Check Formatting
|
- name: Check Formatting
|
||||||
uses: actions-rs/cargo@v1
|
run: cargo fmt --all -- --check
|
||||||
with:
|
|
||||||
command: fmt
|
|
||||||
args: --all -- --check
|
|
||||||
|
|
||||||
clippy:
|
clippy:
|
||||||
name: Clippy
|
name: Clippy
|
||||||
@ -37,12 +30,7 @@ jobs:
|
|||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Install stable toolchain
|
- name: Install stable toolchain
|
||||||
uses: actions-rs/toolchain@v1
|
uses: dtolnay/rust-toolchain@stable
|
||||||
with:
|
|
||||||
toolchain: stable
|
|
||||||
profile: minimal
|
|
||||||
override: true
|
|
||||||
components: rustfmt
|
|
||||||
|
|
||||||
- name: Cache cargo registry, index and build directory
|
- name: Cache cargo registry, index and build directory
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v3
|
||||||
@ -54,10 +42,9 @@ jobs:
|
|||||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
|
||||||
- name: Clippy Linting
|
- name: Clippy Linting
|
||||||
uses: actions-rs/cargo@v1
|
run: cargo clippy --all-features -- -Dclippy::all -Dclippy::pedantic
|
||||||
with:
|
- name: Clippy Test Linting
|
||||||
command: clippy
|
run: cargo clippy --tests -- -Dclippy::all -Dclippy::pedantic
|
||||||
args: -- -D warnings
|
|
||||||
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@ -74,11 +61,7 @@ jobs:
|
|||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Install stable toolchain
|
- name: Install stable toolchain
|
||||||
uses: actions-rs/toolchain@v1
|
uses: dtolnay/rust-toolchain@stable
|
||||||
with:
|
|
||||||
toolchain: stable
|
|
||||||
profile: minimal
|
|
||||||
override: true
|
|
||||||
|
|
||||||
- name: Cache cargo registry, index and build directory
|
- name: Cache cargo registry, index and build directory
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v3
|
||||||
@ -90,6 +73,4 @@ jobs:
|
|||||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
|
||||||
- name: Run Tests
|
- name: Run Tests
|
||||||
uses: actions-rs/cargo@v1
|
run: cargo test
|
||||||
with:
|
|
||||||
command: test
|
|
||||||
|
14
CHANGELOG.md
14
CHANGELOG.md
@ -5,9 +5,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
### Dependencies
|
### Dependencies
|
||||||
- Bump `serde` from 1.0.160 to 1.0.163 (#613, #617)
|
- Bump `serde` from 1.0.160 to 1.0.183 (#613, #617, #627, #636, #639, #640, #645, [#648](https://github.com/vbrandl/hoc/pull/648), [#650](https://github.com/vbrandl/hoc/pull/650), [#652](https://github.com/vbrandl/hoc/pull/652), [#653](https://github.com/vbrandl/hoc/pull/653), [#654](https://github.com/vbrandl/hoc/pull/654), [#655](https://github.com/vbrandl/hoc/pull/655), [#657](https://github.com/vbrandl/hoc/pull/657))
|
||||||
- Bump `actions/cache` from 2 to 3 (#616)
|
- Bump `actions/cache` from 2 to 3 (#616)
|
||||||
- Bump `tokio` from 1.28.0 to 1.28.1 (#618)
|
- Bump `tokio` from 1.28.0 to 1.32.0 (#618, #625, #633, #634, [#659](https://github.com/vbrandl/hoc/pull/659), [#660](https://github.com/vbrandl/hoc/pull/660), [#665](https://github.com/vbrandl/hoc/pull/665))
|
||||||
|
- Bump `reqwest` from 0.11.17 to 0.11.18 (#619)
|
||||||
|
- Bump `vergen` from 8.1.3 to 8.2.4 (#621, #622, #635, #638)
|
||||||
|
- Bump `tracing-actix-web` from 0.7.4 to 0.7.6 (#623, [#656](https://github.com/vbrandl/hoc/pull/656))
|
||||||
|
- Bump `git2` from 0.17.1 to 0.17.2 (#624)
|
||||||
|
- Bump `tempfile` from 3.5.0 to 3.8.0 (#626, [#646](https://github.com/vbrandl/hoc/pull/646), [#658](https://github.com/vbrandl/hoc/pull/658), [#667](https://github.com/vbrandl/hoc/pull/667))
|
||||||
|
- Bump `serde_json` from 1.0.96 to 1.0.105 (#630, #632, #637, #641, #644, [#649](https://github.com/vbrandl/hoc/pull/649), [#663](https://github.com/vbrandl/hoc/pull/663))
|
||||||
|
- Bump `openssl` from 0.10.50 to 0.10.55 (#631)
|
||||||
|
- Bump `tracing-bunyan-formatter` from 0.3.7 to 0.3.9 (#642, [#661](https://github.com/vbrandl/hoc/pull/661))
|
||||||
|
- Bump `anyhow` from 1.0.71 to 1.0.75 (#643, [#662](https://github.com/vbrandl/hoc/pull/662), [#664](https://github.com/vbrandl/hoc/pull/664))
|
||||||
|
- Bump `ructe` from 0.16.1 to 0.17.0 ([#647](https://github.com/vbrandl/hoc/pull/647))
|
||||||
|
|
||||||
|
|
||||||
## [0.35.0] 2023-05-04
|
## [0.35.0] 2023-05-04
|
||||||
|
890
Cargo.lock
generated
890
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
28
Cargo.toml
28
Cargo.toml
@ -19,30 +19,30 @@ badgers = "1.2.0"
|
|||||||
bytes = "1.4.0"
|
bytes = "1.4.0"
|
||||||
config = { version = "0.13.3", features = ["toml"] }
|
config = { version = "0.13.3", features = ["toml"] }
|
||||||
dotenvy = "0.15.7"
|
dotenvy = "0.15.7"
|
||||||
futures = "0.3.27"
|
futures = "0.3.28"
|
||||||
git2 = "0.17.1"
|
git2 = "0.17.2"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
mime = "0.3"
|
mime = "0.3"
|
||||||
number_prefix = "0.4.0"
|
number_prefix = "0.4.0"
|
||||||
openssl-probe = "0.1.5"
|
openssl-probe = "0.1.5"
|
||||||
reqwest = "0.11.17"
|
reqwest = "0.11.18"
|
||||||
serde = "1.0.163"
|
serde = "1.0.183"
|
||||||
serde_derive = "1.0.137"
|
serde_derive = "1.0.166"
|
||||||
serde_json = "1.0.94"
|
serde_json = "1.0.105"
|
||||||
tracing = "0.1.37"
|
tracing = "0.1.37"
|
||||||
tracing-actix-web = "0.7.3"
|
tracing-actix-web = "0.7.6"
|
||||||
tracing-bunyan-formatter = "0.3.6"
|
tracing-bunyan-formatter = "0.3.9"
|
||||||
tracing-futures = "0.2.5"
|
tracing-futures = "0.2.5"
|
||||||
tracing-log = "0.1.3"
|
tracing-log = "0.1.3"
|
||||||
tracing-subscriber = { version = "0.3.17", features = ["registry", "env-filter"] }
|
tracing-subscriber = { version = "0.3.17", features = ["registry", "env-filter"] }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
anyhow = "1.0.71"
|
anyhow = "1.0.75"
|
||||||
ructe = { version = "0.16.1", features = ["mime03"] }
|
ructe = { version = "0.17.0", features = ["mime03"] }
|
||||||
vergen = { version = "8.1.3", default-features = false, features = ["git", "gitoxide"] }
|
vergen = { version = "8.2.4", default-features = false, features = ["git", "gitoxide"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
awc = "3.1.1"
|
awc = "3.1.1"
|
||||||
ructe = "0.16.1"
|
ructe = "0.17.0"
|
||||||
tempfile = "3.5.0"
|
tempfile = "3.8.0"
|
||||||
tokio = "1.28.1"
|
tokio = "1.32.0"
|
||||||
|
15
src/cache.rs
15
src/cache.rs
@ -36,10 +36,10 @@ impl<'a> CacheState<'a> {
|
|||||||
trace!("Reading cache");
|
trace!("Reading cache");
|
||||||
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)?))?;
|
||||||
Ok(cache
|
Ok(cache.entries.get(branch).map_or_else(
|
||||||
.entries
|
// TODO: get rid of clone
|
||||||
.get(branch)
|
|| CacheState::NoneForBranch(cache.clone()),
|
||||||
.map(|c| {
|
|c| {
|
||||||
if c.head == head {
|
if c.head == head {
|
||||||
trace!("Cache is up to date");
|
trace!("Cache is up to date");
|
||||||
CacheState::Current {
|
CacheState::Current {
|
||||||
@ -56,9 +56,8 @@ impl<'a> CacheState<'a> {
|
|||||||
cache: cache.clone(),
|
cache: cache.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
},
|
||||||
// TODO: get rid of clone
|
))
|
||||||
.unwrap_or_else(|| CacheState::NoneForBranch(cache.clone())))
|
|
||||||
} else {
|
} else {
|
||||||
Ok(CacheState::No)
|
Ok(CacheState::No)
|
||||||
}
|
}
|
||||||
@ -75,7 +74,7 @@ impl<'a> CacheState<'a> {
|
|||||||
trace!("Calculating new cache");
|
trace!("Calculating new cache");
|
||||||
match self {
|
match self {
|
||||||
CacheState::Old { mut cache, .. } => {
|
CacheState::Old { mut cache, .. } => {
|
||||||
if let Some(mut cache) = cache.entries.get_mut(branch) {
|
if let Some(cache) = cache.entries.get_mut(branch) {
|
||||||
cache.head = head;
|
cache.head = head;
|
||||||
cache.count += count;
|
cache.count += count;
|
||||||
cache.commits += commits;
|
cache.commits += commits;
|
||||||
|
@ -18,6 +18,12 @@ pub struct Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Settings {
|
impl Settings {
|
||||||
|
/// Load the configuration from file and environment.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// * File cannot be read or parsed
|
||||||
|
/// * Environment variables cannot be parsed
|
||||||
pub fn load() -> Result<Self, ConfigError> {
|
pub fn load() -> Result<Self, ConfigError> {
|
||||||
Config::builder()
|
Config::builder()
|
||||||
.add_source(File::with_name("hoc.toml").required(false))
|
.add_source(File::with_name("hoc.toml").required(false))
|
||||||
|
19
src/error.rs
19
src/error.rs
@ -41,17 +41,14 @@ impl ResponseError for Error {
|
|||||||
|
|
||||||
fn error_response(&self) -> HttpResponse {
|
fn error_response(&self) -> HttpResponse {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
match self {
|
if let Error::BranchNotFound = self {
|
||||||
Error::BranchNotFound => {
|
templates::p404_no_master_html(&mut buf, VERSION_INFO, 0).unwrap();
|
||||||
templates::p404_no_master_html(&mut buf, VERSION_INFO, 0).unwrap();
|
HttpResponse::NotFound().content_type("text/html").body(buf)
|
||||||
HttpResponse::NotFound().content_type("text/html").body(buf)
|
} else {
|
||||||
}
|
templates::p500_html(&mut buf, VERSION_INFO, 0).unwrap();
|
||||||
_ => {
|
HttpResponse::InternalServerError()
|
||||||
templates::p500_html(&mut buf, VERSION_INFO, 0).unwrap();
|
.content_type("text/html")
|
||||||
HttpResponse::InternalServerError()
|
.body(buf)
|
||||||
.content_type("text/html")
|
|
||||||
.body(buf)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
32
src/lib.rs
32
src/lib.rs
@ -22,7 +22,7 @@ use crate::{
|
|||||||
cache::CacheState,
|
cache::CacheState,
|
||||||
config::Settings,
|
config::Settings,
|
||||||
error::{Error, Result},
|
error::{Error, Result},
|
||||||
service::{Bitbucket, FormService, GitHub, Gitlab, Service, Sourcehut},
|
service::{Bitbucket, FormValue, GitHub, Gitlab, Service, Sourcehut},
|
||||||
statics::{CLIENT, VERSION_INFO},
|
statics::{CLIENT, VERSION_INFO},
|
||||||
template::{RepoGeneratorInfo, RepoInfo},
|
template::{RepoGeneratorInfo, RepoInfo},
|
||||||
};
|
};
|
||||||
@ -53,7 +53,7 @@ include!(concat!(env!("OUT_DIR"), "/templates.rs"));
|
|||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
struct GeneratorForm<'a> {
|
struct GeneratorForm<'a> {
|
||||||
service: FormService,
|
service: FormValue,
|
||||||
user: Cow<'a, str>,
|
user: Cow<'a, str>,
|
||||||
repo: Cow<'a, str>,
|
repo: Cow<'a, str>,
|
||||||
branch: Option<Cow<'a, str>>,
|
branch: Option<Cow<'a, str>>,
|
||||||
@ -282,6 +282,7 @@ where
|
|||||||
}
|
}
|
||||||
pull(&path)?;
|
pull(&path)?;
|
||||||
let (hoc, head, commits) = hoc(&service_url, &state.repos(), &state.cache(), branch)?;
|
let (hoc, head, commits) = hoc(&service_url, &state.repos(), &state.cache(), branch)?;
|
||||||
|
#[allow(clippy::cast_precision_loss)]
|
||||||
let hoc_pretty = match NumberPrefix::decimal(hoc as f64) {
|
let hoc_pretty = match NumberPrefix::decimal(hoc as f64) {
|
||||||
NumberPrefix::Standalone(hoc) => hoc.to_string(),
|
NumberPrefix::Standalone(hoc) => hoc.to_string(),
|
||||||
NumberPrefix::Prefixed(prefix, hoc) => format!("{hoc:.1}{prefix}"),
|
NumberPrefix::Prefixed(prefix, hoc) => format!("{hoc:.1}{prefix}"),
|
||||||
@ -309,7 +310,7 @@ pub(crate) async fn json_hoc<T: Service>(
|
|||||||
let branch = branch.branch.as_deref().unwrap_or("master");
|
let branch = branch.branch.as_deref().unwrap_or("master");
|
||||||
let rc_clone = repo_count.clone();
|
let rc_clone = repo_count.clone();
|
||||||
let mapper = move |r| match r {
|
let mapper = move |r| match r {
|
||||||
HocResult::NotFound => p404(rc_clone),
|
HocResult::NotFound => p404(&rc_clone),
|
||||||
HocResult::Hoc {
|
HocResult::Hoc {
|
||||||
hoc, head, commits, ..
|
hoc, head, commits, ..
|
||||||
} => Ok(HttpResponse::Ok().json(JsonResponse {
|
} => Ok(HttpResponse::Ok().json(JsonResponse {
|
||||||
@ -345,7 +346,7 @@ pub(crate) async fn calculate_hoc<T: Service>(
|
|||||||
let rc_clone = repo_count.clone();
|
let rc_clone = repo_count.clone();
|
||||||
let label = query.label.clone();
|
let label = query.label.clone();
|
||||||
let mapper = move |r| match r {
|
let mapper = move |r| match r {
|
||||||
HocResult::NotFound => p404(rc_clone),
|
HocResult::NotFound => p404(&rc_clone),
|
||||||
HocResult::Hoc { hoc_pretty, .. } => {
|
HocResult::Hoc { hoc_pretty, .. } => {
|
||||||
let badge_opt = BadgeOptions {
|
let badge_opt = BadgeOptions {
|
||||||
subject: label,
|
subject: label,
|
||||||
@ -386,7 +387,7 @@ async fn overview<T: Service>(
|
|||||||
let base_url = state.settings.base_url.clone();
|
let base_url = state.settings.base_url.clone();
|
||||||
let rc_clone = repo_count.clone();
|
let rc_clone = repo_count.clone();
|
||||||
let mapper = move |r| match r {
|
let mapper = move |r| match r {
|
||||||
HocResult::NotFound => p404(rc_clone),
|
HocResult::NotFound => p404(&rc_clone),
|
||||||
HocResult::Hoc {
|
HocResult::Hoc {
|
||||||
hoc,
|
hoc,
|
||||||
commits,
|
commits,
|
||||||
@ -413,7 +414,7 @@ async fn overview<T: Service>(
|
|||||||
VERSION_INFO,
|
VERSION_INFO,
|
||||||
rc_clone.load(Ordering::Relaxed),
|
rc_clone.load(Ordering::Relaxed),
|
||||||
repo_info,
|
repo_info,
|
||||||
label,
|
&label,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().content_type("text/html").body(buf))
|
Ok(HttpResponse::Ok().content_type("text/html").body(buf))
|
||||||
@ -423,11 +424,13 @@ async fn overview<T: Service>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[get("/health_check")]
|
#[get("/health_check")]
|
||||||
|
#[allow(clippy::unused_async)]
|
||||||
async fn health_check() -> HttpResponse {
|
async fn health_check() -> HttpResponse {
|
||||||
HttpResponse::Ok().finish()
|
HttpResponse::Ok().finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
|
#[allow(clippy::unused_async)]
|
||||||
async fn index(
|
async fn index(
|
||||||
state: web::Data<State>,
|
state: web::Data<State>,
|
||||||
repo_count: web::Data<AtomicUsize>,
|
repo_count: web::Data<AtomicUsize>,
|
||||||
@ -443,6 +446,7 @@ async fn index(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[post("/generate")]
|
#[post("/generate")]
|
||||||
|
#[allow(clippy::unused_async)]
|
||||||
async fn generate(
|
async fn generate(
|
||||||
params: web::Form<GeneratorForm<'_>>,
|
params: web::Form<GeneratorForm<'_>>,
|
||||||
state: web::Data<State>,
|
state: web::Data<State>,
|
||||||
@ -470,20 +474,22 @@ async fn generate(
|
|||||||
Ok(HttpResponse::Ok().content_type("text/html").body(buf))
|
Ok(HttpResponse::Ok().content_type("text/html").body(buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn p404(repo_count: web::Data<AtomicUsize>) -> Result<HttpResponse> {
|
fn p404(repo_count: &web::Data<AtomicUsize>) -> Result<HttpResponse> {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
templates::p404_html(&mut buf, VERSION_INFO, repo_count.load(Ordering::Relaxed))?;
|
templates::p404_html(&mut buf, VERSION_INFO, repo_count.load(Ordering::Relaxed))?;
|
||||||
Ok(HttpResponse::NotFound().content_type("text/html").body(buf))
|
Ok(HttpResponse::NotFound().content_type("text/html").body(buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::unused_async)]
|
||||||
async fn async_p404(repo_count: web::Data<AtomicUsize>) -> Result<HttpResponse> {
|
async fn async_p404(repo_count: web::Data<AtomicUsize>) -> Result<HttpResponse> {
|
||||||
p404(repo_count)
|
p404(&repo_count)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A duration to add to current time for a far expires header.
|
/// A duration to add to current time for a far expires header.
|
||||||
static FAR: Duration = Duration::from_secs(180 * 24 * 60 * 60);
|
static FAR: Duration = Duration::from_secs(180 * 24 * 60 * 60);
|
||||||
|
|
||||||
#[get("/static/{filename}")]
|
#[get("/static/{filename}")]
|
||||||
|
#[allow(clippy::unused_async)]
|
||||||
async fn static_file(
|
async fn static_file(
|
||||||
path: web::Path<String>,
|
path: web::Path<String>,
|
||||||
repo_count: web::Data<AtomicUsize>,
|
repo_count: web::Data<AtomicUsize>,
|
||||||
@ -496,11 +502,11 @@ async fn static_file(
|
|||||||
.content_type(data.mime.clone())
|
.content_type(data.mime.clone())
|
||||||
.body(data.content)
|
.body(data.content)
|
||||||
})
|
})
|
||||||
.map(Result::Ok)
|
.map_or_else(|| p404(&repo_count), Result::Ok)
|
||||||
.unwrap_or_else(|| p404(repo_count))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/favicon.ico")]
|
#[get("/favicon.ico")]
|
||||||
|
#[allow(clippy::unused_async)]
|
||||||
async fn favicon32() -> HttpResponse {
|
async fn favicon32() -> HttpResponse {
|
||||||
let data = &template_statics::favicon32_png;
|
let data = &template_statics::favicon32_png;
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
@ -508,6 +514,7 @@ async fn favicon32() -> HttpResponse {
|
|||||||
.body(data.content)
|
.body(data.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::unused_async)]
|
||||||
async fn start_server(listener: TcpListener, settings: Settings) -> std::io::Result<Server> {
|
async fn start_server(listener: TcpListener, settings: Settings) -> std::io::Result<Server> {
|
||||||
let workers = settings.workers;
|
let workers = settings.workers;
|
||||||
let repo_count =
|
let repo_count =
|
||||||
@ -536,6 +543,11 @@ async fn start_server(listener: TcpListener, settings: Settings) -> std::io::Res
|
|||||||
.run())
|
.run())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Start the server.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// * server cannot bind to `listener`
|
||||||
pub async fn run(listener: TcpListener, settings: Settings) -> std::io::Result<Server> {
|
pub async fn run(listener: TcpListener, settings: Settings) -> std::io::Result<Server> {
|
||||||
let span = info_span!("hoc", version = env!("CARGO_PKG_VERSION"));
|
let span = info_span!("hoc", version = env!("CARGO_PKG_VERSION"));
|
||||||
let _ = span.enter();
|
let _ = span.enter();
|
||||||
|
@ -6,7 +6,7 @@ fn init() {
|
|||||||
dotenvy::dotenv().ok();
|
dotenvy::dotenv().ok();
|
||||||
openssl_probe::init_ssl_cert_env_vars();
|
openssl_probe::init_ssl_cert_env_vars();
|
||||||
|
|
||||||
telemetry::init_subscriber(telemetry::get_subscriber("hoc", "info"))
|
telemetry::init_subscriber(telemetry::get_subscriber("hoc", "info"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::main]
|
#[actix_rt::main]
|
||||||
|
@ -29,7 +29,7 @@ pub(crate) trait Service: Sized + 'static {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Clone, Copy)]
|
#[derive(Deserialize, Serialize, Clone, Copy)]
|
||||||
pub enum FormService {
|
pub enum FormValue {
|
||||||
#[serde(rename = "github")]
|
#[serde(rename = "github")]
|
||||||
GitHub,
|
GitHub,
|
||||||
#[serde(rename = "gitlab")]
|
#[serde(rename = "gitlab")]
|
||||||
@ -40,22 +40,22 @@ pub enum FormService {
|
|||||||
Sourcehut,
|
Sourcehut,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FormService {
|
impl FormValue {
|
||||||
pub(crate) fn url(&self) -> &str {
|
pub(crate) fn url(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
FormService::GitHub => "github.com",
|
FormValue::GitHub => "github.com",
|
||||||
FormService::Gitlab => "gitlab.com",
|
FormValue::Gitlab => "gitlab.com",
|
||||||
FormService::Bitbucket => "bitbucket.org",
|
FormValue::Bitbucket => "bitbucket.org",
|
||||||
FormService::Sourcehut => "git.sr.ht",
|
FormValue::Sourcehut => "git.sr.ht",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn service(&self) -> &str {
|
pub(crate) fn service(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
FormService::GitHub => "github",
|
FormValue::GitHub => "github",
|
||||||
FormService::Gitlab => "gitlab",
|
FormValue::Gitlab => "gitlab",
|
||||||
FormService::Bitbucket => "bitbucket",
|
FormValue::Bitbucket => "bitbucket",
|
||||||
FormService::Sourcehut => "sourcehut",
|
FormValue::Sourcehut => "sourcehut",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#[derive(Clone, Copy)]
|
||||||
pub struct VersionInfo<'a> {
|
pub struct VersionInfo<'a> {
|
||||||
pub commit: &'a str,
|
pub commit: &'a str,
|
||||||
pub version: &'a str,
|
pub version: &'a str,
|
||||||
|
@ -15,6 +15,10 @@ pub fn get_subscriber(name: &str, env_filter: &str) -> impl Subscriber + Send +
|
|||||||
.with(formatting_layer)
|
.with(formatting_layer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// This panics if the `LogTracer` cannot be initialized or `subscriber` cannot be set as global
|
||||||
|
/// default.
|
||||||
pub fn init_subscriber(subscriber: impl Subscriber + Send + Sync) {
|
pub fn init_subscriber(subscriber: impl Subscriber + Send + Sync) {
|
||||||
LogTracer::init().expect("Failed to set logger");
|
LogTracer::init().expect("Failed to set logger");
|
||||||
set_global_default(subscriber).expect("Failed to set tracing subscriber");
|
set_global_default(subscriber).expect("Failed to set tracing subscriber");
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use crate::service::FormService;
|
use crate::service::FormValue;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
pub struct RepoInfo<'a> {
|
pub struct RepoInfo<'a> {
|
||||||
pub commit_url: &'a str,
|
pub commit_url: &'a str,
|
||||||
pub commits: u64,
|
pub commits: u64,
|
||||||
@ -13,7 +14,7 @@ pub struct RepoInfo<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct RepoGeneratorInfo<'a> {
|
pub struct RepoGeneratorInfo<'a> {
|
||||||
pub service: FormService,
|
pub service: FormValue,
|
||||||
pub user: &'a str,
|
pub user: &'a str,
|
||||||
pub repo: &'a str,
|
pub repo: &'a str,
|
||||||
pub branch: &'a str,
|
pub branch: &'a str,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
@use super::statics::*;
|
@use super::statics::tacit_css_min_css;
|
||||||
@use crate::statics::VersionInfo;
|
@use crate::statics::VersionInfo;
|
||||||
|
|
||||||
@(title: &str, header: &str, content: Content, version_info: VersionInfo, repo_count: usize)
|
@(title: &str, header: &str, content: Content, version_info: VersionInfo, repo_count: usize)
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
@use crate::statics::VersionInfo;
|
@use crate::statics::VersionInfo;
|
||||||
@use crate::template::RepoInfo;
|
@use crate::template::RepoInfo;
|
||||||
|
|
||||||
@(version_info: VersionInfo, repo_count: usize, repo_info: RepoInfo, label: String)
|
@(version_info: VersionInfo, repo_count: usize, repo_info: RepoInfo, label: &str)
|
||||||
|
|
||||||
@:base_html("Hits-of-Code Badges", "Overview", {
|
@:base_html("Hits-of-Code Badges", "Overview", {
|
||||||
|
|
||||||
|
@ -5,14 +5,14 @@ use tempfile::TempDir;
|
|||||||
#[test]
|
#[test]
|
||||||
fn no_repos() {
|
fn no_repos() {
|
||||||
let repos = TempDir::new().unwrap();
|
let repos = TempDir::new().unwrap();
|
||||||
assert_eq!(0, count_repositories(&repos).unwrap())
|
assert_eq!(0, count_repositories(&repos).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn no_repos_for_provider() {
|
fn no_repos_for_provider() {
|
||||||
let repos = TempDir::new().unwrap();
|
let repos = TempDir::new().unwrap();
|
||||||
let _provider = TempDir::new_in(&repos).unwrap();
|
let _provider = TempDir::new_in(&repos).unwrap();
|
||||||
assert_eq!(0, count_repositories(&repos).unwrap())
|
assert_eq!(0, count_repositories(&repos).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -20,7 +20,7 @@ fn no_repos_for_owner() {
|
|||||||
let repos = TempDir::new().unwrap();
|
let repos = TempDir::new().unwrap();
|
||||||
let provider = TempDir::new_in(&repos).unwrap();
|
let provider = TempDir::new_in(&repos).unwrap();
|
||||||
let _owner = TempDir::new_in(&provider).unwrap();
|
let _owner = TempDir::new_in(&provider).unwrap();
|
||||||
assert_eq!(0, count_repositories(&repos).unwrap())
|
assert_eq!(0, count_repositories(&repos).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -29,7 +29,7 @@ fn one_repo_for_owner() {
|
|||||||
let provider = TempDir::new_in(&repos).unwrap();
|
let provider = TempDir::new_in(&repos).unwrap();
|
||||||
let owner = TempDir::new_in(&provider).unwrap();
|
let owner = TempDir::new_in(&provider).unwrap();
|
||||||
let _repo = TempDir::new_in(&owner).unwrap();
|
let _repo = TempDir::new_in(&owner).unwrap();
|
||||||
assert_eq!(1, count_repositories(&repos).unwrap())
|
assert_eq!(1, count_repositories(&repos).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -39,7 +39,7 @@ fn two_repos_for_owner() {
|
|||||||
let owner = TempDir::new_in(&provider).unwrap();
|
let owner = TempDir::new_in(&provider).unwrap();
|
||||||
let _repo1 = TempDir::new_in(&owner).unwrap();
|
let _repo1 = TempDir::new_in(&owner).unwrap();
|
||||||
let _repo2 = TempDir::new_in(&owner).unwrap();
|
let _repo2 = TempDir::new_in(&owner).unwrap();
|
||||||
assert_eq!(2, count_repositories(&repos).unwrap())
|
assert_eq!(2, count_repositories(&repos).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -51,7 +51,7 @@ fn two_repos_for_two_providers() {
|
|||||||
let provider2 = TempDir::new_in(&repos).unwrap();
|
let provider2 = TempDir::new_in(&repos).unwrap();
|
||||||
let owner2 = TempDir::new_in(&provider2).unwrap();
|
let owner2 = TempDir::new_in(&provider2).unwrap();
|
||||||
let _repo2 = TempDir::new_in(&owner2).unwrap();
|
let _repo2 = TempDir::new_in(&owner2).unwrap();
|
||||||
assert_eq!(2, count_repositories(&repos).unwrap())
|
assert_eq!(2, count_repositories(&repos).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -62,5 +62,5 @@ fn two_subdirs_in_one_repo() {
|
|||||||
let repo = TempDir::new_in(&owner).unwrap();
|
let repo = TempDir::new_in(&owner).unwrap();
|
||||||
let _subdir1 = TempDir::new_in(&repo).unwrap();
|
let _subdir1 = TempDir::new_in(&repo).unwrap();
|
||||||
let _subdir2 = TempDir::new_in(&repo).unwrap();
|
let _subdir2 = TempDir::new_in(&repo).unwrap();
|
||||||
assert_eq!(1, count_repositories(&repos).unwrap())
|
assert_eq!(1, count_repositories(&repos).unwrap());
|
||||||
}
|
}
|
||||||
|
@ -25,24 +25,26 @@ pub async fn spawn_app() -> TestApp {
|
|||||||
let listener = TcpListener::bind("127.0.0.1:0").expect("Failed to bind random port");
|
let listener = TcpListener::bind("127.0.0.1:0").expect("Failed to bind random port");
|
||||||
|
|
||||||
let port = listener.local_addr().unwrap().port();
|
let port = listener.local_addr().unwrap().port();
|
||||||
let address = format!("http://127.0.0.1:{}", port);
|
let address = format!("http://127.0.0.1:{port}");
|
||||||
|
|
||||||
let _repo_dir = tempdir().expect("Cannot create repo_dir");
|
let repo_dir = tempdir().expect("Cannot create repo_dir");
|
||||||
let _cache_dir = tempdir().expect("Cannot create cache_dir");
|
let cache_dir = tempdir().expect("Cannot create cache_dir");
|
||||||
|
|
||||||
let mut settings = Settings::load().expect("Failed to read configuration.");
|
let mut settings = Settings::load().expect("Failed to read configuration.");
|
||||||
settings.repodir = _repo_dir.path().to_path_buf();
|
settings.repodir = repo_dir.path().to_path_buf();
|
||||||
settings.cachedir = _cache_dir.path().to_path_buf();
|
settings.cachedir = cache_dir.path().to_path_buf();
|
||||||
|
|
||||||
let server = hoc::run(listener, settings)
|
let server = hoc::run(listener, settings)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to bind address");
|
.expect("Failed to bind address");
|
||||||
|
|
||||||
|
#[allow(clippy::let_underscore_future)]
|
||||||
|
// don't await so the test server runs in the background
|
||||||
let _ = tokio::spawn(server);
|
let _ = tokio::spawn(server);
|
||||||
|
|
||||||
TestApp {
|
TestApp {
|
||||||
address,
|
address,
|
||||||
_repo_dir,
|
_repo_dir: repo_dir,
|
||||||
_cache_dir,
|
_cache_dir: cache_dir,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user