Compare commits
51 Commits
v0.35.0
...
fix/rust-c
Author | SHA1 | Date | |
---|---|---|---|
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 | |||
78078132ce | |||
6aa253d44e | |||
d461a8f6a1 | |||
4847cc4f1f | |||
bef518d594 | |||
c22cc59924 | |||
a4e28984ef | |||
f4372c3248 | |||
e9554a20a7 | |||
7862446e16 | |||
b4a7444442 | |||
66861cb4d3 | |||
e6b1dfece8
|
|||
6837660a79 | |||
109886ad9a | |||
dcadae98b6 | |||
4845826023 | |||
ce9db6b4a7
|
|||
24f2d43550
|
|||
43bbf4d377 |
12
.github/dependabot.yml
vendored
12
.github/dependabot.yml
vendored
@ -10,3 +10,15 @@ updates:
|
|||||||
- vbrandl
|
- vbrandl
|
||||||
labels:
|
labels:
|
||||||
- dependencies
|
- dependencies
|
||||||
|
- dependabot
|
||||||
|
|
||||||
|
- package-ecosystem: 'github-actions'
|
||||||
|
directory: '/'
|
||||||
|
schedule:
|
||||||
|
interval: 'daily'
|
||||||
|
open-pull-requests-limit: 10
|
||||||
|
assignees:
|
||||||
|
- vbrandl
|
||||||
|
labels:
|
||||||
|
- dependabot
|
||||||
|
- dependencies
|
||||||
|
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 }}
|
||||||
|
26
.github/workflows/dependabot-changelog.yml
vendored
Normal file
26
.github/workflows/dependabot-changelog.yml
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
name: 'Dependabot Changelog'
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types:
|
||||||
|
- opened
|
||||||
|
- synchronize
|
||||||
|
- reopened
|
||||||
|
- ready_for_review
|
||||||
|
- labeled
|
||||||
|
- unlabeled
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
changelog:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.ACTION_TOKEN }}
|
||||||
|
- uses: dangoslen/dependabot-changelog-helper@v3
|
||||||
|
with:
|
||||||
|
activationLabel: 'dependabot'
|
||||||
|
- uses: stefanzweifel/git-auto-commit-action@v4
|
||||||
|
with:
|
||||||
|
commit_message: "Update Changelog"
|
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@ -42,7 +42,7 @@ jobs:
|
|||||||
override: true
|
override: true
|
||||||
|
|
||||||
- name: Cache cargo registry, index and build directory
|
- name: Cache cargo registry, index and build directory
|
||||||
uses: actions/cache@v2
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
~/.cargo/registry
|
~/.cargo/registry
|
||||||
|
41
.github/workflows/rust.yml
vendored
41
.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,13 @@ 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
|
||||||
with:
|
# TODO
|
||||||
command: clippy
|
# run: cargo clippy --all-features -- -Dclippy::all -Dclippy::pedantic
|
||||||
args: -- -D warnings
|
- name: Clippy Test Linting
|
||||||
|
run: cargo clippy --tests -- -Dclippy::all
|
||||||
|
# TODO
|
||||||
|
# run: cargo clippy --tests -- -Dclippy::all -Dclippy::pedantic
|
||||||
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@ -74,11 +65,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 +77,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
|
|
||||||
|
11
CHANGELOG.md
11
CHANGELOG.md
@ -4,6 +4,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
### Dependencies
|
||||||
|
- Bump `serde` from 1.0.160 to 1.0.164 (#613, #617, #627)
|
||||||
|
- Bump `actions/cache` from 2 to 3 (#616)
|
||||||
|
- Bump `tokio` from 1.28.0 to 1.28.2 (#618, #625)
|
||||||
|
- Bump `reqwest` from 0.11.17 to 0.11.18 (#619)
|
||||||
|
- Bump `vergen` from 8.1.3 to 8.2.1 (#621, #622)
|
||||||
|
- Bump `tracing-actix-web` from 0.7.4 to 0.7.5 (#623)
|
||||||
|
- Bump `git2` from 0.17.1 to 0.17.2 (#624)
|
||||||
|
- Bump `tempfile` from 3.5.0 to 3.6.0 (#626)
|
||||||
|
|
||||||
|
|
||||||
## [0.35.0] 2023-05-04
|
## [0.35.0] 2023-05-04
|
||||||
@ -227,4 +236,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
[#502]: https://github.com/vbrandl/hoc/pull/502
|
[#502]: https://github.com/vbrandl/hoc/pull/502
|
||||||
[#503]: https://github.com/vbrandl/hoc/pull/503
|
[#503]: https://github.com/vbrandl/hoc/pull/503
|
||||||
[#504]: https://github.com/vbrandl/hoc/pull/504
|
[#504]: https://github.com/vbrandl/hoc/pull/504
|
||||||
[#508]: https://github.com/vbrandl/hoc/pull/508
|
[#508]: https://github.com/vbrandl/hoc/pull/508
|
39
Cargo.lock
generated
39
Cargo.lock
generated
@ -807,9 +807,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "git2"
|
name = "git2"
|
||||||
version = "0.17.1"
|
version = "0.17.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8b7905cdfe33d31a88bb2e8419ddd054451f5432d1da9eaf2ac7804ee1ea12d5"
|
checksum = "7b989d6a7ca95a362cf2cfc5ad688b3a467be1f87e480b8dad07fee8c79b0044"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"libc",
|
"libc",
|
||||||
@ -1671,9 +1671,9 @@ checksum = "6a987beff54b60ffa6d51982e1aa1146bc42f19bd26be28b0586f252fccf5317"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libgit2-sys"
|
name = "libgit2-sys"
|
||||||
version = "0.15.1+1.6.4"
|
version = "0.15.2+1.6.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fb4577bde8cdfc7d6a2a4bcb7b049598597de33ffd337276e9c7db6cd4a2cee7"
|
checksum = "a80df2e11fb4a61f4ba2ab42dbe7f74468da143f1a75c74e11dee7c813f694fa"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"libc",
|
"libc",
|
||||||
@ -2197,9 +2197,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "reqwest"
|
name = "reqwest"
|
||||||
version = "0.11.17"
|
version = "0.11.18"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "13293b639a097af28fc8a90f22add145a9c954e49d77da06263d58cf44d5fb91"
|
checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.21.0",
|
"base64 0.21.0",
|
||||||
"bytes",
|
"bytes",
|
||||||
@ -2357,18 +2357,18 @@ checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.160"
|
version = "1.0.164"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c"
|
checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.160"
|
version = "1.0.164"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df"
|
checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -2509,15 +2509,16 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tempfile"
|
name = "tempfile"
|
||||||
version = "3.5.0"
|
version = "3.6.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998"
|
checksum = "31c0432476357e58790aaa47a8efb0c5138f137343f3b5f23bd36a27e3b0a6d6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"fastrand",
|
"fastrand",
|
||||||
"redox_syscall 0.3.5",
|
"redox_syscall 0.3.5",
|
||||||
"rustix",
|
"rustix",
|
||||||
"windows-sys 0.45.0",
|
"windows-sys 0.48.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2596,9 +2597,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio"
|
name = "tokio"
|
||||||
version = "1.28.0"
|
version = "1.28.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c3c786bf8134e5a3a166db9b29ab8f48134739014a3eca7bc6bfa95d673b136f"
|
checksum = "94d7b1cfd2aa4011f2de74c2c4c63665e27a71006b0a192dcd2710272e73dfa2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"autocfg",
|
"autocfg",
|
||||||
"bytes",
|
"bytes",
|
||||||
@ -2665,9 +2666,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing-actix-web"
|
name = "tracing-actix-web"
|
||||||
version = "0.7.4"
|
version = "0.7.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e2def0ffabc0116481e14e82cf705fef814f5178171d445b6790137ff8a85a73"
|
checksum = "ce52ffaf2d544e317d3bef63f49a6a22022866505fa4840a4339b1756834a2a9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"pin-project",
|
"pin-project",
|
||||||
@ -2838,9 +2839,9 @@ checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vergen"
|
name = "vergen"
|
||||||
version = "8.1.3"
|
version = "8.2.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6e03272e388fb78fc79481a493424f78d77be1d55f21bcd314b5a6716e195afe"
|
checksum = "8b3c89c2c7e50f33e4d35527e5bf9c11d6d132226dbbd1753f0fbe9f19ef88c6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"gix",
|
"gix",
|
||||||
|
14
Cargo.toml
14
Cargo.toml
@ -20,17 +20,17 @@ 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.27"
|
||||||
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.158"
|
serde = "1.0.164"
|
||||||
serde_derive = "1.0.137"
|
serde_derive = "1.0.137"
|
||||||
serde_json = "1.0.94"
|
serde_json = "1.0.94"
|
||||||
tracing = "0.1.37"
|
tracing = "0.1.37"
|
||||||
tracing-actix-web = "0.7.3"
|
tracing-actix-web = "0.7.5"
|
||||||
tracing-bunyan-formatter = "0.3.6"
|
tracing-bunyan-formatter = "0.3.6"
|
||||||
tracing-futures = "0.2.5"
|
tracing-futures = "0.2.5"
|
||||||
tracing-log = "0.1.3"
|
tracing-log = "0.1.3"
|
||||||
@ -39,10 +39,10 @@ tracing-subscriber = { version = "0.3.17", features = ["registry", "env-filter"]
|
|||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
anyhow = "1.0.71"
|
anyhow = "1.0.71"
|
||||||
ructe = { version = "0.16.1", features = ["mime03"] }
|
ructe = { version = "0.16.1", features = ["mime03"] }
|
||||||
vergen = { version = "8.1.3", default-features = false, features = ["git", "gitoxide"] }
|
vergen = { version = "8.2.1", default-features = false, features = ["git", "gitoxide"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
awc = "3.1.1"
|
awc = "3.1.1"
|
||||||
ructe = "0.16.1"
|
ructe = "0.16.1"
|
||||||
tempfile = "3.5.0"
|
tempfile = "3.6.0"
|
||||||
tokio = "1.28.0"
|
tokio = "1.28.2"
|
||||||
|
13
src/cache.rs
13
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)
|
||||||
}
|
}
|
||||||
|
@ -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))
|
||||||
|
31
src/lib.rs
31
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>>,
|
||||||
@ -309,7 +309,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 +345,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 +386,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 +413,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 +423,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 +445,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 +473,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 +501,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 +513,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 +542,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();
|
||||||
|
@ -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,
|
||||||
|
@ -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", {
|
||||||
|
|
||||||
|
@ -38,6 +38,8 @@ pub async fn spawn_app() -> TestApp {
|
|||||||
.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 {
|
||||||
|
Reference in New Issue
Block a user