Compare commits
28 Commits
v0.17.0
...
feature/te
Author | SHA1 | Date | |
---|---|---|---|
5493af0c0c | |||
56b973607c | |||
cbdda8a561 | |||
6ac399a41b | |||
35c13fa486 | |||
6570daef02 | |||
6ac389e3ee | |||
36196975ac | |||
1dd83829b2 | |||
1b0817bc25 | |||
f57dc8e890 | |||
bdda6292d2 | |||
a2826c9922 | |||
3b2a368df0 | |||
8b7444bd7c | |||
9d719e7d85 | |||
584379e047 | |||
951124e038 | |||
e574f4bdd0 | |||
5c8e3fa35d | |||
4c0df1fa19 | |||
f6b46a1e90 | |||
5eb16ac38e | |||
3486d44bc5 | |||
1311e724ce | |||
5da9e74992 | |||
8dadc0ddea | |||
cba235eadf |
3
.github/workflows/rust.yml
vendored
3
.github/workflows/rust.yml
vendored
@ -69,7 +69,8 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
# add windows-latest when it is clear why tests are failing
|
# add windows-latest when it is clear why tests are failing
|
||||||
os: [ubuntu-latest, macos-latest]
|
# os: [ubuntu-latest, macos-latest]
|
||||||
|
os: [ubuntu-latest]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout sources
|
- name: Checkout sources
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,5 +4,4 @@ repos
|
|||||||
cache
|
cache
|
||||||
hoc.log
|
hoc.log
|
||||||
result
|
result
|
||||||
hoc.toml
|
|
||||||
.env
|
.env
|
||||||
|
295
Cargo.lock
generated
295
Cargo.lock
generated
@ -17,7 +17,7 @@ dependencies = [
|
|||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-sink",
|
"futures-sink",
|
||||||
"log",
|
"log",
|
||||||
"pin-project 0.4.27",
|
"pin-project 0.4.28",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-util",
|
"tokio-util",
|
||||||
]
|
]
|
||||||
@ -80,7 +80,7 @@ dependencies = [
|
|||||||
"pin-project 1.0.5",
|
"pin-project 1.0.5",
|
||||||
"rand 0.7.3",
|
"rand 0.7.3",
|
||||||
"regex",
|
"regex",
|
||||||
"serde 1.0.123",
|
"serde 1.0.125",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_urlencoded",
|
"serde_urlencoded",
|
||||||
"sha-1",
|
"sha-1",
|
||||||
@ -108,7 +108,7 @@ dependencies = [
|
|||||||
"http",
|
"http",
|
||||||
"log",
|
"log",
|
||||||
"regex",
|
"regex",
|
||||||
"serde 1.0.123",
|
"serde 1.0.125",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -153,7 +153,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "0052435d581b5be835d11f4eb3bce417c8af18d87ddf8ace99f8e67e595882bb"
|
checksum = "0052435d581b5be835d11f4eb3bce417c8af18d87ddf8ace99f8e67e595882bb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"pin-project 0.4.27",
|
"pin-project 0.4.28",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -213,7 +213,7 @@ dependencies = [
|
|||||||
"futures-sink",
|
"futures-sink",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"log",
|
"log",
|
||||||
"pin-project 0.4.27",
|
"pin-project 0.4.28",
|
||||||
"slab",
|
"slab",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -247,7 +247,7 @@ dependencies = [
|
|||||||
"mime",
|
"mime",
|
||||||
"pin-project 1.0.5",
|
"pin-project 1.0.5",
|
||||||
"regex",
|
"regex",
|
||||||
"serde 1.0.123",
|
"serde 1.0.125",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_urlencoded",
|
"serde_urlencoded",
|
||||||
"socket2",
|
"socket2",
|
||||||
@ -268,12 +268,17 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "addr2line"
|
name = "actix-web-opentelemetry"
|
||||||
version = "0.14.1"
|
version = "0.10.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a55f82cfe485775d02112886f4169bde0c5894d75e79ead7eafe7e40a25e45f7"
|
checksum = "4ac71801f541f5225e71f522d56901b0be7fd6ee2181724a7e551b74249d0129"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"gimli",
|
"actix-http",
|
||||||
|
"actix-web",
|
||||||
|
"futures",
|
||||||
|
"opentelemetry",
|
||||||
|
"opentelemetry-semantic-conventions",
|
||||||
|
"serde 1.0.125",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -300,6 +305,12 @@ dependencies = [
|
|||||||
"winapi 0.3.9",
|
"winapi 0.3.9",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anyhow"
|
||||||
|
version = "1.0.40"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "28b2cd92db5cbd74e8e5028f7e27dd7aa3090e89e4f2a197cc7c8dfb69c7063b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "arrayvec"
|
name = "arrayvec"
|
||||||
version = "0.5.2"
|
version = "0.5.2"
|
||||||
@ -342,25 +353,11 @@ dependencies = [
|
|||||||
"mime",
|
"mime",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"rand 0.7.3",
|
"rand 0.7.3",
|
||||||
"serde 1.0.123",
|
"serde 1.0.125",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_urlencoded",
|
"serde_urlencoded",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "backtrace"
|
|
||||||
version = "0.3.56"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9d117600f438b1707d4e4ae15d3595657288f8235a0eb593e80ecc98ab34e1bc"
|
|
||||||
dependencies = [
|
|
||||||
"addr2line",
|
|
||||||
"cfg-if 1.0.0",
|
|
||||||
"libc",
|
|
||||||
"miniz_oxide",
|
|
||||||
"object",
|
|
||||||
"rustc-demangle",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "badge"
|
name = "badge"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
@ -500,14 +497,14 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "config"
|
name = "config"
|
||||||
version = "0.10.1"
|
version = "0.11.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "19b076e143e1d9538dde65da30f8481c2a6c44040edb8e02b9bf1351edb92ce3"
|
checksum = "1b1b9d958c2b1368a663f05538fc1b5975adce1e19f435acceae987aceeeb369"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"nom",
|
"nom",
|
||||||
"rust-ini",
|
"rust-ini",
|
||||||
"serde 1.0.123",
|
"serde 1.0.125",
|
||||||
"serde-hjson",
|
"serde-hjson",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"toml",
|
"toml",
|
||||||
@ -568,6 +565,16 @@ dependencies = [
|
|||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dashmap"
|
||||||
|
version = "4.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if 1.0.0",
|
||||||
|
"num_cpus",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "derive_more"
|
name = "derive_more"
|
||||||
version = "0.99.11"
|
version = "0.99.11"
|
||||||
@ -817,6 +824,16 @@ dependencies = [
|
|||||||
"version_check",
|
"version_check",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gethostname"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e692e296bfac1d2533ef168d0b60ff5897b8b70a4009276834014dd8924cc028"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"winapi 0.3.9",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.1.16"
|
version = "0.1.16"
|
||||||
@ -851,12 +868,6 @@ dependencies = [
|
|||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "gimli"
|
|
||||||
version = "0.23.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f6503fe142514ca4799d4c26297c4248239fe8838d827db6bd6065c6ed29a6ce"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "git2"
|
name = "git2"
|
||||||
version = "0.13.17"
|
version = "0.13.17"
|
||||||
@ -918,10 +929,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hoc"
|
name = "hoc"
|
||||||
version = "0.17.0"
|
version = "0.17.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-rt",
|
"actix-rt",
|
||||||
"actix-web",
|
"actix-web",
|
||||||
|
"actix-web-opentelemetry",
|
||||||
"badge",
|
"badge",
|
||||||
"bytes 1.0.1",
|
"bytes 1.0.1",
|
||||||
"config",
|
"config",
|
||||||
@ -931,15 +943,21 @@ dependencies = [
|
|||||||
"lazy_static",
|
"lazy_static",
|
||||||
"number_prefix",
|
"number_prefix",
|
||||||
"openssl-probe",
|
"openssl-probe",
|
||||||
|
"opentelemetry",
|
||||||
|
"opentelemetry-jaeger",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"ructe",
|
"ructe",
|
||||||
"serde 1.0.123",
|
"serde 1.0.125",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-actix-web",
|
"tracing-actix-web",
|
||||||
|
"tracing-bunyan-formatter",
|
||||||
"tracing-futures",
|
"tracing-futures",
|
||||||
|
"tracing-log",
|
||||||
|
"tracing-opentelemetry",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
"vergen",
|
"vergen",
|
||||||
]
|
]
|
||||||
@ -1055,6 +1073,12 @@ dependencies = [
|
|||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "integer-encoding"
|
||||||
|
version = "1.1.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "48dc51180a9b377fd75814d0cc02199c20f8e99433d6762f650d39cdbbd3b56f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iovec"
|
name = "iovec"
|
||||||
version = "0.1.4"
|
version = "0.1.4"
|
||||||
@ -1196,16 +1220,6 @@ dependencies = [
|
|||||||
"vcpkg",
|
"vcpkg",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "linked-hash-map"
|
|
||||||
version = "0.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6d262045c5b87c0861b3f004610afd0e2c851e2908d08b6c870cbb9d5f494ecd"
|
|
||||||
dependencies = [
|
|
||||||
"serde 0.8.23",
|
|
||||||
"serde_test",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "linked-hash-map"
|
name = "linked-hash-map"
|
||||||
version = "0.5.4"
|
version = "0.5.4"
|
||||||
@ -1236,7 +1250,7 @@ version = "0.1.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c"
|
checksum = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"linked-hash-map 0.5.4",
|
"linked-hash-map",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1424,12 +1438,6 @@ version = "0.4.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
|
checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "object"
|
|
||||||
version = "0.23.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a9a7ab5d64814df0fe4a4b5ead45ed6c5f181ee3ff04ba344313a6c80446c5d4"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.7.0"
|
version = "1.7.0"
|
||||||
@ -1475,6 +1483,55 @@ dependencies = [
|
|||||||
"vcpkg",
|
"vcpkg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "opentelemetry"
|
||||||
|
version = "0.12.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "514d24875c140ed269eecc2d1b56d7b71b573716922a763c317fb1b1b4b58f15"
|
||||||
|
dependencies = [
|
||||||
|
"async-trait",
|
||||||
|
"dashmap",
|
||||||
|
"fnv",
|
||||||
|
"futures",
|
||||||
|
"js-sys",
|
||||||
|
"lazy_static",
|
||||||
|
"percent-encoding",
|
||||||
|
"pin-project 1.0.5",
|
||||||
|
"rand 0.8.3",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "opentelemetry-jaeger"
|
||||||
|
version = "0.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a5677b3a361784aff6e2b1b30dbdb5f85f4ec57ff2ced41d9a481ad70a9d0b57"
|
||||||
|
dependencies = [
|
||||||
|
"async-trait",
|
||||||
|
"lazy_static",
|
||||||
|
"opentelemetry",
|
||||||
|
"thiserror",
|
||||||
|
"thrift",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "opentelemetry-semantic-conventions"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0ecb679b997c41108a498e3ce8b933fe2f643a9a722ad8ca33f95edab84df106"
|
||||||
|
dependencies = [
|
||||||
|
"opentelemetry",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ordered-float"
|
||||||
|
version = "1.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3305af35278dd29f46fcdd139e0b1fbfae2153f0e5928b39b035542dd31e37b7"
|
||||||
|
dependencies = [
|
||||||
|
"num-traits 0.2.14",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "owned_ttf_parser"
|
name = "owned_ttf_parser"
|
||||||
version = "0.6.0"
|
version = "0.6.0"
|
||||||
@ -1517,11 +1574,11 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pin-project"
|
name = "pin-project"
|
||||||
version = "0.4.27"
|
version = "0.4.28"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2ffbc8e94b38ea3d2d8ba92aea2983b503cd75d0888d75b86bb37970b5698e15"
|
checksum = "918192b5c59119d51e0cd221f4d49dde9112824ba717369e903c97d076083d0f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"pin-project-internal 0.4.27",
|
"pin-project-internal 0.4.28",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1535,9 +1592,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pin-project-internal"
|
name = "pin-project-internal"
|
||||||
version = "0.4.27"
|
version = "0.4.28"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "65ad2ae56b6abe3a1ee25f15ee605bacadb9a764edaba9c2bf4103800d4a1895"
|
checksum = "3be26700300be6d9d23264c73211d8190e755b6b5ca7a1b28230025511b52a5e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -1796,7 +1853,7 @@ dependencies = [
|
|||||||
"native-tls",
|
"native-tls",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"pin-project-lite 0.2.4",
|
"pin-project-lite 0.2.4",
|
||||||
"serde 1.0.123",
|
"serde 1.0.125",
|
||||||
"serde_urlencoded",
|
"serde_urlencoded",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-tls",
|
"tokio-tls",
|
||||||
@ -1836,12 +1893,6 @@ version = "0.13.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3e52c148ef37f8c375d49d5a73aa70713125b7f19095948a923f80afdeb22ec2"
|
checksum = "3e52c148ef37f8c375d49d5a73aa70713125b7f19095948a923f80afdeb22ec2"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rustc-demangle"
|
|
||||||
version = "0.1.18"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc_version"
|
name = "rustc_version"
|
||||||
version = "0.2.3"
|
version = "0.2.3"
|
||||||
@ -1861,6 +1912,12 @@ dependencies = [
|
|||||||
"owned_ttf_parser",
|
"owned_ttf_parser",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustversion"
|
||||||
|
version = "1.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cb5d2a036dc6d2d8fd16fde3498b04306e29bd193bf306a57427019b823d5acd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ryu"
|
name = "ryu"
|
||||||
version = "1.0.5"
|
version = "1.0.5"
|
||||||
@ -1929,9 +1986,9 @@ checksum = "9dad3f759919b92c3068c696c15c3d17238234498bbdcc80f2c469606f948ac8"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.123"
|
version = "1.0.125"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae"
|
checksum = "558dc50e1a5a5fa7112ca2ce4effcb321b0300c0d4ccf0776a9f60cd89031171"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
@ -1943,7 +2000,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "6a3a4e0ea8a88553209f6cc6cfe8724ecad22e1acf372793c27d995290fe74f8"
|
checksum = "6a3a4e0ea8a88553209f6cc6cfe8724ecad22e1acf372793c27d995290fe74f8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"linked-hash-map 0.3.0",
|
|
||||||
"num-traits 0.1.43",
|
"num-traits 0.1.43",
|
||||||
"regex",
|
"regex",
|
||||||
"serde 0.8.23",
|
"serde 0.8.23",
|
||||||
@ -1951,9 +2007,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.123"
|
version = "1.0.125"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9391c295d64fc0abb2c556bad848f33cb8296276b1ad2677d1ae1ace4f258f31"
|
checksum = "b093b7a2bb58203b5da3056c05b4ec1fed827dcfdb37347a8841695263b3d06d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -1962,22 +2018,13 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.63"
|
version = "1.0.64"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "43535db9747a4ba938c0ce0a98cc631a46ebf943c9e1d604e091df6007620bf6"
|
checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
"ryu",
|
"ryu",
|
||||||
"serde 1.0.123",
|
"serde 1.0.125",
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "serde_test"
|
|
||||||
version = "0.8.23"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "110b3dbdf8607ec493c22d5d947753282f3bae73c0f56d322af1e8c78e4c23d5"
|
|
||||||
dependencies = [
|
|
||||||
"serde 0.8.23",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1989,7 +2036,7 @@ dependencies = [
|
|||||||
"form_urlencoded",
|
"form_urlencoded",
|
||||||
"itoa",
|
"itoa",
|
||||||
"ryu",
|
"ryu",
|
||||||
"serde 1.0.123",
|
"serde 1.0.125",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2089,7 +2136,7 @@ checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"serde 1.0.123",
|
"serde 1.0.125",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
@ -2103,7 +2150,7 @@ dependencies = [
|
|||||||
"base-x",
|
"base-x",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"serde 1.0.123",
|
"serde 1.0.125",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"sha1",
|
"sha1",
|
||||||
@ -2179,6 +2226,19 @@ dependencies = [
|
|||||||
"num_cpus",
|
"num_cpus",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thrift"
|
||||||
|
version = "0.13.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0c6d965454947cc7266d22716ebfd07b18d84ebaf35eec558586bbb2a8cb6b5b"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder",
|
||||||
|
"integer-encoding",
|
||||||
|
"log",
|
||||||
|
"ordered-float",
|
||||||
|
"threadpool",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "time"
|
name = "time"
|
||||||
version = "0.1.43"
|
version = "0.1.43"
|
||||||
@ -2293,7 +2353,7 @@ version = "0.5.8"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa"
|
checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde 1.0.123",
|
"serde 1.0.125",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2339,6 +2399,23 @@ dependencies = [
|
|||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing-bunyan-formatter"
|
||||||
|
version = "0.1.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "06718867c20ea03700d41a9413610cccf5d772caea792f34cc73cdd43f0e14a6"
|
||||||
|
dependencies = [
|
||||||
|
"chrono",
|
||||||
|
"gethostname",
|
||||||
|
"log",
|
||||||
|
"serde 1.0.125",
|
||||||
|
"serde_json",
|
||||||
|
"tracing",
|
||||||
|
"tracing-core",
|
||||||
|
"tracing-log",
|
||||||
|
"tracing-subscriber",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing-core"
|
name = "tracing-core"
|
||||||
version = "0.1.17"
|
version = "0.1.17"
|
||||||
@ -2369,28 +2446,41 @@ dependencies = [
|
|||||||
"tracing-core",
|
"tracing-core",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing-opentelemetry"
|
||||||
|
version = "0.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cccdf13c28f1654fe806838f28c5b9cb23ca4c0eae71450daa489f50e523ceb1"
|
||||||
|
dependencies = [
|
||||||
|
"opentelemetry",
|
||||||
|
"tracing",
|
||||||
|
"tracing-core",
|
||||||
|
"tracing-log",
|
||||||
|
"tracing-subscriber",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing-serde"
|
name = "tracing-serde"
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fb65ea441fbb84f9f6748fd496cf7f63ec9af5bca94dd86456978d055e8eb28b"
|
checksum = "fb65ea441fbb84f9f6748fd496cf7f63ec9af5bca94dd86456978d055e8eb28b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde 1.0.123",
|
"serde 1.0.125",
|
||||||
"tracing-core",
|
"tracing-core",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing-subscriber"
|
name = "tracing-subscriber"
|
||||||
version = "0.2.16"
|
version = "0.2.17"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8ab8966ac3ca27126141f7999361cc97dd6fb4b71da04c02044fa9045d98bb96"
|
checksum = "705096c6f83bf68ea5d357a6aa01829ddbdac531b357b45abeca842938085baa"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ansi_term",
|
"ansi_term",
|
||||||
"chrono",
|
"chrono",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"matchers",
|
"matchers",
|
||||||
"regex",
|
"regex",
|
||||||
"serde 1.0.123",
|
"serde 1.0.125",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"sharded-slab",
|
"sharded-slab",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
@ -2403,12 +2493,12 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "trust-dns-proto"
|
name = "trust-dns-proto"
|
||||||
version = "0.19.6"
|
version = "0.19.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "53861fcb288a166aae4c508ae558ed18b53838db728d4d310aad08270a7d4c2b"
|
checksum = "1cad71a0c0d68ab9941d2fb6e82f8fb2e86d9945b94e1661dd0aaea2b88215a9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"backtrace",
|
"cfg-if 1.0.0",
|
||||||
"enum-as-inner",
|
"enum-as-inner",
|
||||||
"futures",
|
"futures",
|
||||||
"idna",
|
"idna",
|
||||||
@ -2423,11 +2513,10 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "trust-dns-resolver"
|
name = "trust-dns-resolver"
|
||||||
version = "0.19.6"
|
version = "0.19.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6759e8efc40465547b0dfce9500d733c65f969a4cbbfbe3ccf68daaa46ef179e"
|
checksum = "710f593b371175db53a26d0b38ed2978fafb9e9e8d3868b1acd753ea18df0ceb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"backtrace",
|
|
||||||
"cfg-if 0.1.10",
|
"cfg-if 0.1.10",
|
||||||
"futures",
|
"futures",
|
||||||
"ipconfig",
|
"ipconfig",
|
||||||
@ -2527,17 +2616,17 @@ checksum = "b00bca6106a5e23f3eee943593759b7fcddb00554332e856d990c893966879fb"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vergen"
|
name = "vergen"
|
||||||
version = "4.1.0"
|
version = "5.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7559dbf502657d16ddfdee53eea0827fc40ea7e3a53bc8b92d7317417cf9420e"
|
checksum = "dfbc87f9a7a9d61b15d51d1d3547284f67b6b4f1494ce3fc5814c101f35a5183"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
"enum-iterator",
|
"enum-iterator",
|
||||||
"getset",
|
"getset",
|
||||||
"git2",
|
"git2",
|
||||||
"serde 1.0.123",
|
"rustversion",
|
||||||
"serde_derive",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2575,7 +2664,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "55c0f7123de74f0dab9b7d00fd614e7b19349cd1e2f5252bbe9b1754b59433be"
|
checksum = "55c0f7123de74f0dab9b7d00fd614e7b19349cd1e2f5252bbe9b1754b59433be"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"serde 1.0.123",
|
"serde 1.0.125",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"wasm-bindgen-macro",
|
"wasm-bindgen-macro",
|
||||||
]
|
]
|
||||||
@ -2720,5 +2809,5 @@ version = "0.4.5"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
|
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"linked-hash-map 0.5.4",
|
"linked-hash-map",
|
||||||
]
|
]
|
||||||
|
29
Cargo.toml
29
Cargo.toml
@ -1,34 +1,51 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "hoc"
|
name = "hoc"
|
||||||
version = "0.17.0"
|
version = "0.17.1"
|
||||||
authors = ["Valentin Brandl <vbrandl@riseup.net>"]
|
authors = ["Valentin Brandl <vbrandl@riseup.net>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
path = "src/lib.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
path = "src/main.rs"
|
||||||
|
name = "hoc"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-rt = "1.1.1"
|
actix-rt = "1.1.1"
|
||||||
actix-web = "3.3.2"
|
actix-web = "3.3.2"
|
||||||
|
actix-web-opentelemetry = "0.10.0"
|
||||||
badge = "0.3.0"
|
badge = "0.3.0"
|
||||||
bytes = "1.0.1"
|
bytes = "1.0.1"
|
||||||
config = { version = "0.10.1", features = ["toml"] }
|
config = { version = "0.11.0", features = ["toml"] }
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
futures = "0.3.13"
|
futures = "0.3.13"
|
||||||
git2 = "0.13.17"
|
git2 = "0.13.17"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
number_prefix = "0.4.0"
|
number_prefix = "0.4.0"
|
||||||
openssl-probe = "0.1.2"
|
openssl-probe = "0.1.2"
|
||||||
|
# TODO: upgrade
|
||||||
|
opentelemetry = { version = "0.12.0", default-features = false, features = ["trace"] }
|
||||||
|
# TODO: upgrade
|
||||||
|
opentelemetry-jaeger = "0.11.0"
|
||||||
reqwest = "0.10.10"
|
reqwest = "0.10.10"
|
||||||
serde = "1.0.123"
|
serde = "1.0.125"
|
||||||
serde_derive = "1.0.123"
|
serde_derive = "1.0.123"
|
||||||
serde_json = "1.0.63"
|
serde_json = "1.0.64"
|
||||||
tracing = "0.1.25"
|
tracing = "0.1.25"
|
||||||
tracing-actix-web = "0.2.1"
|
tracing-actix-web = "0.2.1"
|
||||||
|
tracing-bunyan-formatter = "0.1.7"
|
||||||
tracing-futures = "0.2.5"
|
tracing-futures = "0.2.5"
|
||||||
tracing-subscriber = "0.2.16"
|
tracing-log = "0.1.2"
|
||||||
|
tracing-opentelemetry = "0.11.0"
|
||||||
|
tracing-subscriber = { version = "0.2.17", features = ["registry", "env-filter"] }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
ructe = "0.13.0"
|
ructe = "0.13.0"
|
||||||
vergen = { version = "4.1.0", default-features = false, features = ["git"] }
|
vergen = { version = "5.1.0", default-features = false, features = ["git"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
ructe = "0.13.0"
|
||||||
tempfile = "3.2.0"
|
tempfile = "3.2.0"
|
||||||
|
tokio = "0.2.25"
|
||||||
|
7
build.rs
7
build.rs
@ -2,11 +2,12 @@ extern crate ructe;
|
|||||||
extern crate vergen;
|
extern crate vergen;
|
||||||
|
|
||||||
use ructe::Ructe;
|
use ructe::Ructe;
|
||||||
use vergen::{gen, ConstantsFlags};
|
use vergen::{vergen, Config, ShaKind};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let flags = ConstantsFlags::SHA_SHORT;
|
let mut config = Config::default();
|
||||||
gen(flags).expect("Unable to generate the cargo keys!");
|
*config.git_mut().sha_kind_mut() = ShaKind::Short;
|
||||||
|
vergen(config).expect("Unable to generate static repo info");
|
||||||
Ructe::from_env()
|
Ructe::from_env()
|
||||||
.expect("ructe")
|
.expect("ructe")
|
||||||
.compile_templates("templates")
|
.compile_templates("templates")
|
||||||
|
15
hoc.toml
Normal file
15
hoc.toml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# every parameter can also be set (or overwritten) by passing an environment
|
||||||
|
# variable namend `HOC_<PARAMETERNAME>`, e.g.
|
||||||
|
# `HOC_BASE_URL='https://hitsofcode.com' ./hoc`
|
||||||
|
|
||||||
|
# these config parameters have default values and must not explicitly be set
|
||||||
|
repodir = "./repos"
|
||||||
|
cachedir = "./cache"
|
||||||
|
port = 8080
|
||||||
|
host = "0.0.0.0"
|
||||||
|
workers = 4
|
||||||
|
|
||||||
|
# these parameters don't have default values and must be set
|
||||||
|
|
||||||
|
# this should be the public base URL of the service, e.g. `https://hitsofcode.com`
|
||||||
|
base_url = "http://0.0.0.0:8080"
|
@ -17,16 +17,13 @@ pub struct Settings {
|
|||||||
pub workers: usize,
|
pub workers: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn init() {
|
|
||||||
dotenv::dotenv().ok();
|
|
||||||
std::env::set_var("RUST_LOG", "actix_web=info,hoc=info");
|
|
||||||
openssl_probe::init_ssl_cert_env_vars();
|
|
||||||
|
|
||||||
tracing_subscriber::fmt().init();
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Settings {
|
impl Settings {
|
||||||
|
#[deprecated]
|
||||||
pub fn new() -> Result<Self, ConfigError> {
|
pub fn new() -> Result<Self, ConfigError> {
|
||||||
|
Self::load()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load() -> Result<Self, ConfigError> {
|
||||||
let mut config = Config::new();
|
let mut config = Config::new();
|
||||||
config
|
config
|
||||||
.merge(File::with_name("hoc.toml").required(false))?
|
.merge(File::with_name("hoc.toml").required(false))?
|
||||||
|
26
src/error.rs
26
src/error.rs
@ -1,9 +1,6 @@
|
|||||||
use crate::{
|
use crate::{statics::VERSION_INFO, templates};
|
||||||
statics::{REPO_COUNT, VERSION_INFO},
|
use actix_web::{http::StatusCode, HttpResponse, ResponseError};
|
||||||
templates,
|
use std::fmt;
|
||||||
};
|
|
||||||
use actix_web::{HttpResponse, ResponseError};
|
|
||||||
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>;
|
||||||
|
|
||||||
@ -35,21 +32,22 @@ impl fmt::Display for Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ResponseError for Error {
|
impl ResponseError for Error {
|
||||||
|
fn status_code(&self) -> StatusCode {
|
||||||
|
match self {
|
||||||
|
Error::BranchNotFound => StatusCode::NOT_FOUND,
|
||||||
|
_ => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn error_response(&self) -> HttpResponse {
|
fn error_response(&self) -> HttpResponse {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
match self {
|
match self {
|
||||||
Error::BranchNotFound => {
|
Error::BranchNotFound => {
|
||||||
templates::p404_no_master(
|
templates::p404_no_master(&mut buf, VERSION_INFO, 0).unwrap();
|
||||||
&mut buf,
|
|
||||||
VERSION_INFO,
|
|
||||||
REPO_COUNT.load(Ordering::Relaxed),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
HttpResponse::NotFound().content_type("text/html").body(buf)
|
HttpResponse::NotFound().content_type("text/html").body(buf)
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
templates::p500(&mut buf, VERSION_INFO, REPO_COUNT.load(Ordering::Relaxed))
|
templates::p500(&mut buf, VERSION_INFO, 0).unwrap();
|
||||||
.unwrap();
|
|
||||||
HttpResponse::InternalServerError()
|
HttpResponse::InternalServerError()
|
||||||
.content_type("text/html")
|
.content_type("text/html")
|
||||||
.body(buf)
|
.body(buf)
|
||||||
|
527
src/lib.rs
Normal file
527
src/lib.rs
Normal file
@ -0,0 +1,527 @@
|
|||||||
|
#![type_length_limit = "2257138"]
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate actix_web;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate lazy_static;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate serde_derive;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate tracing;
|
||||||
|
|
||||||
|
mod cache;
|
||||||
|
pub mod config;
|
||||||
|
mod count;
|
||||||
|
mod error;
|
||||||
|
mod service;
|
||||||
|
mod statics;
|
||||||
|
pub mod telemetry;
|
||||||
|
mod template;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
cache::CacheState,
|
||||||
|
config::Settings,
|
||||||
|
error::{Error, Result},
|
||||||
|
service::{Bitbucket, FormService, GitHub, Gitlab, Service},
|
||||||
|
statics::{CLIENT, CSS, FAVICON, VERSION_INFO},
|
||||||
|
template::RepoInfo,
|
||||||
|
};
|
||||||
|
use actix_web::{
|
||||||
|
dev::Server,
|
||||||
|
http::header::{CacheControl, CacheDirective, Expires, LOCATION},
|
||||||
|
middleware::{self, normalize::TrailingSlash},
|
||||||
|
web, App, HttpResponse, HttpServer, Responder,
|
||||||
|
};
|
||||||
|
use actix_web_opentelemetry::RequestTracing;
|
||||||
|
use badge::{Badge, BadgeOptions};
|
||||||
|
use git2::{BranchType, Repository};
|
||||||
|
use number_prefix::NumberPrefix;
|
||||||
|
use std::{
|
||||||
|
borrow::Cow,
|
||||||
|
fs::create_dir_all,
|
||||||
|
io,
|
||||||
|
net::TcpListener,
|
||||||
|
path::Path,
|
||||||
|
process::Command,
|
||||||
|
sync::atomic::AtomicUsize,
|
||||||
|
sync::atomic::Ordering,
|
||||||
|
time::{Duration, SystemTime},
|
||||||
|
};
|
||||||
|
use tracing::Instrument;
|
||||||
|
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/templates.rs"));
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize)]
|
||||||
|
struct GeneratorForm<'a> {
|
||||||
|
service: FormService,
|
||||||
|
user: Cow<'a, str>,
|
||||||
|
repo: Cow<'a, str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub(crate) struct State {
|
||||||
|
settings: Settings,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl State {
|
||||||
|
fn repos(&self) -> String {
|
||||||
|
self.settings.repodir.display().to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cache(&self) -> String {
|
||||||
|
self.settings.cachedir.display().to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct JsonResponse<'a> {
|
||||||
|
head: &'a str,
|
||||||
|
branch: &'a str,
|
||||||
|
count: u64,
|
||||||
|
commits: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug)]
|
||||||
|
struct BranchQuery {
|
||||||
|
branch: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn pull(path: impl AsRef<Path>) -> Result<()> {
|
||||||
|
let repo = Repository::open_bare(path)?;
|
||||||
|
let mut origin = repo.find_remote("origin")?;
|
||||||
|
origin.fetch(&["refs/heads/*:refs/heads/*"], None, None)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hoc(repo: &str, repo_dir: &str, cache_dir: &str, branch: &str) -> Result<(u64, String, u64)> {
|
||||||
|
let repo_dir = format!("{}/{}", repo_dir, repo);
|
||||||
|
let cache_dir = format!("{}/{}.json", cache_dir, repo);
|
||||||
|
let cache_dir = Path::new(&cache_dir);
|
||||||
|
let repo = Repository::open_bare(&repo_dir)?;
|
||||||
|
// TODO: do better...
|
||||||
|
let head = repo
|
||||||
|
.find_branch(branch, BranchType::Local)
|
||||||
|
.map_err(|_| Error::BranchNotFound)?
|
||||||
|
.into_reference();
|
||||||
|
let head = format!("{}", head.target().ok_or(Error::BranchNotFound)?);
|
||||||
|
let mut arg_commit_count = vec!["rev-list".to_string(), "--count".to_string()];
|
||||||
|
let mut arg = vec![
|
||||||
|
"log".to_string(),
|
||||||
|
"--pretty=tformat:".to_string(),
|
||||||
|
"--numstat".to_string(),
|
||||||
|
"--ignore-space-change".to_string(),
|
||||||
|
"--ignore-all-space".to_string(),
|
||||||
|
"--ignore-submodules".to_string(),
|
||||||
|
"--no-color".to_string(),
|
||||||
|
"--find-copies-harder".to_string(),
|
||||||
|
"-M".to_string(),
|
||||||
|
"--diff-filter=ACDM".to_string(),
|
||||||
|
];
|
||||||
|
let cache = CacheState::read_from_file(&cache_dir, branch, &head)?;
|
||||||
|
match &cache {
|
||||||
|
CacheState::Current { count, commits, .. } => {
|
||||||
|
info!("Using cache");
|
||||||
|
return Ok((*count, head, *commits));
|
||||||
|
}
|
||||||
|
CacheState::Old { head, .. } => {
|
||||||
|
info!("Updating cache");
|
||||||
|
arg.push(format!("{}..{}", head, branch));
|
||||||
|
arg_commit_count.push(format!("{}..{}", head, branch));
|
||||||
|
}
|
||||||
|
CacheState::No | CacheState::NoneForBranch(..) => {
|
||||||
|
info!("Creating cache");
|
||||||
|
arg.push(branch.to_string());
|
||||||
|
arg_commit_count.push(branch.to_string());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
arg.push("--".to_string());
|
||||||
|
arg.push(".".to_string());
|
||||||
|
let output = Command::new("git")
|
||||||
|
.args(&arg)
|
||||||
|
.current_dir(&repo_dir)
|
||||||
|
.output()?
|
||||||
|
.stdout;
|
||||||
|
let output = String::from_utf8_lossy(&output);
|
||||||
|
let output_commits = Command::new("git")
|
||||||
|
.args(&arg_commit_count)
|
||||||
|
.current_dir(&repo_dir)
|
||||||
|
.output()?
|
||||||
|
.stdout;
|
||||||
|
let output_commits = String::from_utf8_lossy(&output_commits);
|
||||||
|
let commits: u64 = output_commits.trim().parse()?;
|
||||||
|
let count: u64 = output
|
||||||
|
.lines()
|
||||||
|
.map(|s| {
|
||||||
|
s.split_whitespace()
|
||||||
|
.take(2)
|
||||||
|
.map(str::parse::<u64>)
|
||||||
|
.filter_map(std::result::Result::ok)
|
||||||
|
.sum::<u64>()
|
||||||
|
})
|
||||||
|
.sum();
|
||||||
|
|
||||||
|
let cache = cache.calculate_new_cache(count, commits, (&head).into(), branch);
|
||||||
|
cache.write_to_file(cache_dir)?;
|
||||||
|
|
||||||
|
Ok((count, head, commits))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn remote_exists(url: &str) -> Result<bool> {
|
||||||
|
let resp = CLIENT.head(url).send().await?;
|
||||||
|
Ok(resp.status() == reqwest::StatusCode::OK)
|
||||||
|
}
|
||||||
|
|
||||||
|
enum HocResult {
|
||||||
|
Hoc {
|
||||||
|
hoc: u64,
|
||||||
|
commits: u64,
|
||||||
|
hoc_pretty: String,
|
||||||
|
head: String,
|
||||||
|
url: String,
|
||||||
|
repo: String,
|
||||||
|
service_path: String,
|
||||||
|
},
|
||||||
|
NotFound,
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn delete_repo_and_cache<T>(
|
||||||
|
state: web::Data<State>,
|
||||||
|
repo_count: web::Data<AtomicUsize>,
|
||||||
|
data: web::Path<(String, String)>,
|
||||||
|
) -> Result<impl Responder>
|
||||||
|
where
|
||||||
|
T: Service,
|
||||||
|
{
|
||||||
|
let data = data.into_inner();
|
||||||
|
let span = info_span!(
|
||||||
|
"deleting repository and cache",
|
||||||
|
service = T::domain(),
|
||||||
|
user = data.0.as_str(),
|
||||||
|
repo = data.1.as_str()
|
||||||
|
);
|
||||||
|
let future = async {
|
||||||
|
let repo = format!(
|
||||||
|
"{}/{}/{}",
|
||||||
|
T::domain(),
|
||||||
|
data.0.to_lowercase(),
|
||||||
|
data.1.to_lowercase()
|
||||||
|
);
|
||||||
|
info!("Deleting cache and repository");
|
||||||
|
let cache_dir = format!("{}/{}.json", &state.cache(), repo);
|
||||||
|
let repo_dir = format!("{}/{}", &state.repos(), repo);
|
||||||
|
std::fs::remove_file(&cache_dir).or_else(|e| {
|
||||||
|
if e.kind() == io::ErrorKind::NotFound {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(e)
|
||||||
|
}
|
||||||
|
})?;
|
||||||
|
std::fs::remove_dir_all(&repo_dir).or_else(|e| {
|
||||||
|
if e.kind() == io::ErrorKind::NotFound {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(e)
|
||||||
|
}
|
||||||
|
})?;
|
||||||
|
repo_count.fetch_sub(1, Ordering::Relaxed);
|
||||||
|
Ok(HttpResponse::TemporaryRedirect()
|
||||||
|
.header(
|
||||||
|
LOCATION,
|
||||||
|
format!("/{}/{}/{}/view", T::url_path(), data.0, data.1),
|
||||||
|
)
|
||||||
|
.finish())
|
||||||
|
};
|
||||||
|
future.instrument(span).await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn handle_hoc_request<T, F>(
|
||||||
|
state: web::Data<State>,
|
||||||
|
repo_count: web::Data<AtomicUsize>,
|
||||||
|
data: web::Path<(String, String)>,
|
||||||
|
branch: &str,
|
||||||
|
mapper: F,
|
||||||
|
) -> Result<HttpResponse>
|
||||||
|
where
|
||||||
|
T: Service,
|
||||||
|
F: FnOnce(HocResult) -> Result<HttpResponse>,
|
||||||
|
{
|
||||||
|
let data = data.into_inner();
|
||||||
|
let span = info_span!(
|
||||||
|
"handling hoc calculation",
|
||||||
|
service = T::domain(),
|
||||||
|
user = data.0.as_str(),
|
||||||
|
repo = data.1.as_str(),
|
||||||
|
branch
|
||||||
|
);
|
||||||
|
let future = async {
|
||||||
|
let repo = format!("{}/{}", data.0.to_lowercase(), data.1.to_lowercase());
|
||||||
|
let service_path = format!("{}/{}", T::url_path(), repo);
|
||||||
|
let service_url = format!("{}/{}", T::domain(), repo);
|
||||||
|
let path = format!("{}/{}", state.repos(), service_url);
|
||||||
|
let url = format!("https://{}", service_url);
|
||||||
|
let remote_exists = remote_exists(&url).await?;
|
||||||
|
let file = Path::new(&path);
|
||||||
|
if !file.exists() {
|
||||||
|
if !remote_exists {
|
||||||
|
warn!("Repository does not exist");
|
||||||
|
return mapper(HocResult::NotFound);
|
||||||
|
}
|
||||||
|
info!("Cloning for the first time");
|
||||||
|
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, commits) = hoc(&service_url, &state.repos(), &state.cache(), branch)?;
|
||||||
|
let hoc_pretty = match NumberPrefix::decimal(hoc as f64) {
|
||||||
|
NumberPrefix::Standalone(hoc) => hoc.to_string(),
|
||||||
|
NumberPrefix::Prefixed(prefix, hoc) => format!("{:.1}{}", hoc, prefix),
|
||||||
|
};
|
||||||
|
let res = HocResult::Hoc {
|
||||||
|
hoc,
|
||||||
|
commits,
|
||||||
|
hoc_pretty,
|
||||||
|
head,
|
||||||
|
url,
|
||||||
|
repo,
|
||||||
|
service_path,
|
||||||
|
};
|
||||||
|
mapper(res)
|
||||||
|
};
|
||||||
|
future.instrument(span).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn json_hoc<T: Service>(
|
||||||
|
state: web::Data<State>,
|
||||||
|
repo_count: web::Data<AtomicUsize>,
|
||||||
|
data: web::Path<(String, String)>,
|
||||||
|
branch: web::Query<BranchQuery>,
|
||||||
|
) -> Result<HttpResponse> {
|
||||||
|
let branch = branch.branch.as_deref().unwrap_or("master");
|
||||||
|
let rc_clone = repo_count.clone();
|
||||||
|
let mapper = move |r| match r {
|
||||||
|
HocResult::NotFound => p404(rc_clone),
|
||||||
|
HocResult::Hoc {
|
||||||
|
hoc, head, commits, ..
|
||||||
|
} => Ok(HttpResponse::Ok().json(JsonResponse {
|
||||||
|
branch,
|
||||||
|
head: &head,
|
||||||
|
count: hoc,
|
||||||
|
commits,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
handle_hoc_request::<T, _>(state, repo_count, data, branch, mapper).await
|
||||||
|
}
|
||||||
|
|
||||||
|
fn no_cache_response(body: Vec<u8>) -> HttpResponse {
|
||||||
|
let expiration = SystemTime::now() + Duration::from_secs(30);
|
||||||
|
HttpResponse::Ok()
|
||||||
|
.content_type("image/svg+xml")
|
||||||
|
.set(Expires(expiration.into()))
|
||||||
|
.set(CacheControl(vec![
|
||||||
|
CacheDirective::MaxAge(0u32),
|
||||||
|
CacheDirective::MustRevalidate,
|
||||||
|
CacheDirective::NoCache,
|
||||||
|
CacheDirective::NoStore,
|
||||||
|
]))
|
||||||
|
.body(body)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn calculate_hoc<T: Service>(
|
||||||
|
state: web::Data<State>,
|
||||||
|
repo_count: web::Data<AtomicUsize>,
|
||||||
|
data: web::Path<(String, String)>,
|
||||||
|
branch: web::Query<BranchQuery>,
|
||||||
|
) -> HttpResponse {
|
||||||
|
let rc_clone = repo_count.clone();
|
||||||
|
let mapper = move |r| match r {
|
||||||
|
HocResult::NotFound => p404(rc_clone),
|
||||||
|
HocResult::Hoc { hoc_pretty, .. } => {
|
||||||
|
let badge_opt = BadgeOptions {
|
||||||
|
subject: "Hits-of-Code".to_string(),
|
||||||
|
color: "#007ec6".to_string(),
|
||||||
|
status: hoc_pretty,
|
||||||
|
};
|
||||||
|
let badge = Badge::new(badge_opt)?;
|
||||||
|
// TODO: remove clone
|
||||||
|
let body = badge.to_svg().as_bytes().to_vec();
|
||||||
|
|
||||||
|
Ok(no_cache_response(body))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let branch = branch.branch.as_deref().unwrap_or("master");
|
||||||
|
let error_badge = |_| {
|
||||||
|
let error_badge = Badge::new(BadgeOptions {
|
||||||
|
subject: "Hits-of-Code".to_string(),
|
||||||
|
color: "#ff0000".to_string(),
|
||||||
|
status: "error".to_string(),
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
let body = error_badge.to_svg().as_bytes().to_vec();
|
||||||
|
no_cache_response(body)
|
||||||
|
};
|
||||||
|
handle_hoc_request::<T, _>(state, repo_count, data, branch, mapper)
|
||||||
|
.await
|
||||||
|
.unwrap_or_else(error_badge)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn overview<T: Service>(
|
||||||
|
state: web::Data<State>,
|
||||||
|
repo_count: web::Data<AtomicUsize>,
|
||||||
|
data: web::Path<(String, String)>,
|
||||||
|
branch: web::Query<BranchQuery>,
|
||||||
|
) -> Result<HttpResponse> {
|
||||||
|
let branch = branch.branch.as_deref().unwrap_or("master");
|
||||||
|
let base_url = state.settings.base_url.clone();
|
||||||
|
let rc_clone = repo_count.clone();
|
||||||
|
let mapper = move |r| match r {
|
||||||
|
HocResult::NotFound => p404(rc_clone),
|
||||||
|
HocResult::Hoc {
|
||||||
|
hoc,
|
||||||
|
commits,
|
||||||
|
hoc_pretty,
|
||||||
|
url,
|
||||||
|
head,
|
||||||
|
repo,
|
||||||
|
service_path,
|
||||||
|
} => {
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
let repo_info = RepoInfo {
|
||||||
|
commit_url: &T::commit_url(&repo, &head),
|
||||||
|
commits,
|
||||||
|
base_url: &base_url,
|
||||||
|
head: &head,
|
||||||
|
hoc,
|
||||||
|
hoc_pretty: &hoc_pretty,
|
||||||
|
path: &service_path,
|
||||||
|
url: &url,
|
||||||
|
branch,
|
||||||
|
};
|
||||||
|
templates::overview(
|
||||||
|
&mut buf,
|
||||||
|
VERSION_INFO,
|
||||||
|
rc_clone.load(Ordering::Relaxed),
|
||||||
|
repo_info,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
Ok(HttpResponse::Ok().content_type("text/html").body(buf))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
handle_hoc_request::<T, _>(state, repo_count, data, branch, mapper).await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/health_check")]
|
||||||
|
async fn health_check() -> HttpResponse {
|
||||||
|
HttpResponse::Ok().finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/")]
|
||||||
|
async fn index(
|
||||||
|
state: web::Data<State>,
|
||||||
|
repo_count: web::Data<AtomicUsize>,
|
||||||
|
) -> Result<HttpResponse> {
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
templates::index(
|
||||||
|
&mut buf,
|
||||||
|
VERSION_INFO,
|
||||||
|
repo_count.load(Ordering::Relaxed),
|
||||||
|
&state.settings.base_url,
|
||||||
|
)?;
|
||||||
|
Ok(HttpResponse::Ok().content_type("text/html").body(buf))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[post("/generate")]
|
||||||
|
async fn generate(
|
||||||
|
params: web::Form<GeneratorForm<'_>>,
|
||||||
|
state: web::Data<State>,
|
||||||
|
repo_count: web::Data<AtomicUsize>,
|
||||||
|
) -> Result<HttpResponse> {
|
||||||
|
let repo = format!("{}/{}", params.user, params.repo);
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
templates::generate(
|
||||||
|
&mut buf,
|
||||||
|
VERSION_INFO,
|
||||||
|
repo_count.load(Ordering::Relaxed),
|
||||||
|
&state.settings.base_url,
|
||||||
|
params.service.url(),
|
||||||
|
params.service.service(),
|
||||||
|
&repo,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
Ok(HttpResponse::Ok().content_type("text/html").body(buf))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn p404(repo_count: web::Data<AtomicUsize>) -> Result<HttpResponse> {
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
templates::p404(&mut buf, VERSION_INFO, repo_count.load(Ordering::Relaxed))?;
|
||||||
|
Ok(HttpResponse::NotFound().content_type("text/html").body(buf))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn async_p404(repo_count: web::Data<AtomicUsize>) -> Result<HttpResponse> {
|
||||||
|
p404(repo_count)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn css() -> HttpResponse {
|
||||||
|
HttpResponse::Ok().content_type("text/css").body(CSS)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn favicon32() -> HttpResponse {
|
||||||
|
HttpResponse::Ok().content_type("image/png").body(FAVICON)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn start_server(listener: TcpListener, settings: Settings) -> std::io::Result<Server> {
|
||||||
|
let workers = settings.workers;
|
||||||
|
let repo_count =
|
||||||
|
// TODO: errorhandling
|
||||||
|
web::Data::new(AtomicUsize::new(count::count_repositories(&settings.repodir).unwrap()));
|
||||||
|
let state = web::Data::new(State { settings });
|
||||||
|
Ok(HttpServer::new(move || {
|
||||||
|
App::new()
|
||||||
|
.app_data(state.clone())
|
||||||
|
.app_data(repo_count.clone())
|
||||||
|
.wrap(RequestTracing::new())
|
||||||
|
.wrap(tracing_actix_web::TracingLogger)
|
||||||
|
.wrap(middleware::NormalizePath::new(TrailingSlash::Trim))
|
||||||
|
.service(index)
|
||||||
|
.service(health_check)
|
||||||
|
.service(web::resource("/tacit-css.min.css").route(web::get().to(css)))
|
||||||
|
.service(web::resource("/favicon.ico").route(web::get().to(favicon32)))
|
||||||
|
.service(generate)
|
||||||
|
.service(web::resource("/github/{user}/{repo}").to(calculate_hoc::<GitHub>))
|
||||||
|
.service(web::resource("/gitlab/{user}/{repo}").to(calculate_hoc::<Gitlab>))
|
||||||
|
.service(web::resource("/bitbucket/{user}/{repo}").to(calculate_hoc::<Bitbucket>))
|
||||||
|
.service(
|
||||||
|
web::resource("/github/{user}/{repo}/delete")
|
||||||
|
.route(web::post().to(delete_repo_and_cache::<GitHub>)),
|
||||||
|
)
|
||||||
|
.service(
|
||||||
|
web::resource("/gitlab/{user}/{repo}/delete")
|
||||||
|
.route(web::post().to(delete_repo_and_cache::<Gitlab>)),
|
||||||
|
)
|
||||||
|
.service(
|
||||||
|
web::resource("/bitbucket/{user}/{repo}/delete")
|
||||||
|
.route(web::post().to(delete_repo_and_cache::<Bitbucket>)),
|
||||||
|
)
|
||||||
|
.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("/bitbucket/{user}/{repo}/json").to(json_hoc::<Bitbucket>))
|
||||||
|
.service(web::resource("/view/github/{user}/{repo}").to(overview::<GitHub>))
|
||||||
|
.service(web::resource("/view/gitlab/{user}/{repo}").to(overview::<Gitlab>))
|
||||||
|
.service(web::resource("/view/bitbucket/{user}/{repo}").to(overview::<Bitbucket>))
|
||||||
|
.service(web::resource("/github/{user}/{repo}/view").to(overview::<GitHub>))
|
||||||
|
.service(web::resource("/gitlab/{user}/{repo}/view").to(overview::<Gitlab>))
|
||||||
|
.service(web::resource("/bitbucket/{user}/{repo}/view").to(overview::<Bitbucket>))
|
||||||
|
.default_service(web::resource("").route(web::get().to(async_p404)))
|
||||||
|
})
|
||||||
|
.workers(workers)
|
||||||
|
.listen(listener)?
|
||||||
|
.run())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn run(listener: TcpListener, settings: Settings) -> std::io::Result<Server> {
|
||||||
|
let span = info_span!("hoc", version = env!("CARGO_PKG_VERSION"));
|
||||||
|
let _ = span.enter();
|
||||||
|
start_server(listener, settings).instrument(span).await
|
||||||
|
}
|
509
src/main.rs
509
src/main.rs
@ -1,495 +1,28 @@
|
|||||||
#![type_length_limit = "2257138"]
|
use hoc::{config::Settings, telemetry};
|
||||||
|
use std::net::TcpListener;
|
||||||
|
|
||||||
#[macro_use]
|
fn init() -> opentelemetry_jaeger::Uninstall {
|
||||||
extern crate actix_web;
|
dotenv::dotenv().ok();
|
||||||
#[macro_use]
|
openssl_probe::init_ssl_cert_env_vars();
|
||||||
extern crate lazy_static;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate serde_derive;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate tracing;
|
|
||||||
|
|
||||||
mod cache;
|
let (subscriber, uninstall) = telemetry::get_subscriber("hoc", "info");
|
||||||
mod config;
|
telemetry::init_subscriber(subscriber);
|
||||||
mod count;
|
uninstall
|
||||||
mod error;
|
|
||||||
mod service;
|
|
||||||
mod statics;
|
|
||||||
mod template;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests;
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
cache::CacheState,
|
|
||||||
error::{Error, Result},
|
|
||||||
service::{Bitbucket, FormService, GitHub, Gitlab, Service},
|
|
||||||
statics::{CLIENT, CSS, FAVICON, OPT, REPO_COUNT, VERSION_INFO},
|
|
||||||
template::RepoInfo,
|
|
||||||
};
|
|
||||||
use actix_web::{
|
|
||||||
http::header::{CacheControl, CacheDirective, Expires, LOCATION},
|
|
||||||
middleware::{self, normalize::TrailingSlash},
|
|
||||||
web, App, HttpResponse, HttpServer, Responder,
|
|
||||||
};
|
|
||||||
use badge::{Badge, BadgeOptions};
|
|
||||||
use git2::{BranchType, Repository};
|
|
||||||
use number_prefix::NumberPrefix;
|
|
||||||
use std::{
|
|
||||||
borrow::Cow,
|
|
||||||
fs::create_dir_all,
|
|
||||||
io,
|
|
||||||
path::Path,
|
|
||||||
process::Command,
|
|
||||||
sync::atomic::Ordering,
|
|
||||||
sync::Arc,
|
|
||||||
time::{Duration, SystemTime},
|
|
||||||
};
|
|
||||||
use tracing::Instrument;
|
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/templates.rs"));
|
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
|
||||||
struct GeneratorForm<'a> {
|
|
||||||
service: FormService,
|
|
||||||
user: Cow<'a, str>,
|
|
||||||
repo: Cow<'a, str>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub(crate) struct State {
|
|
||||||
repos: String,
|
|
||||||
cache: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
|
||||||
struct JsonResponse<'a> {
|
|
||||||
head: &'a str,
|
|
||||||
branch: &'a str,
|
|
||||||
count: u64,
|
|
||||||
commits: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
|
||||||
struct BranchQuery {
|
|
||||||
branch: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn pull(path: impl AsRef<Path>) -> Result<()> {
|
|
||||||
let repo = Repository::open_bare(path)?;
|
|
||||||
let mut origin = repo.find_remote("origin")?;
|
|
||||||
origin.fetch(&["refs/heads/*:refs/heads/*"], None, None)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn hoc(repo: &str, repo_dir: &str, cache_dir: &str, branch: &str) -> Result<(u64, String, u64)> {
|
|
||||||
let repo_dir = format!("{}/{}", repo_dir, repo);
|
|
||||||
let cache_dir = format!("{}/{}.json", cache_dir, repo);
|
|
||||||
let cache_dir = Path::new(&cache_dir);
|
|
||||||
let repo = Repository::open_bare(&repo_dir)?;
|
|
||||||
// TODO: do better...
|
|
||||||
let head = repo
|
|
||||||
.find_branch(branch, BranchType::Local)
|
|
||||||
.map_err(|_| Error::BranchNotFound)?
|
|
||||||
.into_reference();
|
|
||||||
let head = format!("{}", head.target().ok_or(Error::BranchNotFound)?);
|
|
||||||
let mut arg_commit_count = vec!["rev-list".to_string(), "--count".to_string()];
|
|
||||||
let mut arg = vec![
|
|
||||||
"log".to_string(),
|
|
||||||
"--pretty=tformat:".to_string(),
|
|
||||||
"--numstat".to_string(),
|
|
||||||
"--ignore-space-change".to_string(),
|
|
||||||
"--ignore-all-space".to_string(),
|
|
||||||
"--ignore-submodules".to_string(),
|
|
||||||
"--no-color".to_string(),
|
|
||||||
"--find-copies-harder".to_string(),
|
|
||||||
"-M".to_string(),
|
|
||||||
"--diff-filter=ACDM".to_string(),
|
|
||||||
];
|
|
||||||
let cache = CacheState::read_from_file(&cache_dir, branch, &head)?;
|
|
||||||
match &cache {
|
|
||||||
CacheState::Current { count, commits, .. } => {
|
|
||||||
info!("Using cache");
|
|
||||||
return Ok((*count, head, *commits));
|
|
||||||
}
|
|
||||||
CacheState::Old { head, .. } => {
|
|
||||||
info!("Updating cache");
|
|
||||||
arg.push(format!("{}..{}", head, branch));
|
|
||||||
arg_commit_count.push(format!("{}..{}", head, branch));
|
|
||||||
}
|
|
||||||
CacheState::No | CacheState::NoneForBranch(..) => {
|
|
||||||
info!("Creating cache");
|
|
||||||
arg.push(branch.to_string());
|
|
||||||
arg_commit_count.push(branch.to_string());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
arg.push("--".to_string());
|
|
||||||
arg.push(".".to_string());
|
|
||||||
let output = Command::new("git")
|
|
||||||
.args(&arg)
|
|
||||||
.current_dir(&repo_dir)
|
|
||||||
.output()?
|
|
||||||
.stdout;
|
|
||||||
let output = String::from_utf8_lossy(&output);
|
|
||||||
let output_commits = Command::new("git")
|
|
||||||
.args(&arg_commit_count)
|
|
||||||
.current_dir(&repo_dir)
|
|
||||||
.output()?
|
|
||||||
.stdout;
|
|
||||||
let output_commits = String::from_utf8_lossy(&output_commits);
|
|
||||||
let commits: u64 = output_commits.trim().parse()?;
|
|
||||||
let count: u64 = output
|
|
||||||
.lines()
|
|
||||||
.map(|s| {
|
|
||||||
s.split_whitespace()
|
|
||||||
.take(2)
|
|
||||||
.map(str::parse::<u64>)
|
|
||||||
.filter_map(std::result::Result::ok)
|
|
||||||
.sum::<u64>()
|
|
||||||
})
|
|
||||||
.sum();
|
|
||||||
|
|
||||||
let cache = cache.calculate_new_cache(count, commits, (&head).into(), branch);
|
|
||||||
cache.write_to_file(cache_dir)?;
|
|
||||||
|
|
||||||
Ok((count, head, commits))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn remote_exists(url: &str) -> Result<bool> {
|
|
||||||
let resp = CLIENT.head(url).send().await?;
|
|
||||||
Ok(resp.status() == reqwest::StatusCode::OK)
|
|
||||||
}
|
|
||||||
|
|
||||||
enum HocResult {
|
|
||||||
Hoc {
|
|
||||||
hoc: u64,
|
|
||||||
commits: u64,
|
|
||||||
hoc_pretty: String,
|
|
||||||
head: String,
|
|
||||||
url: String,
|
|
||||||
repo: String,
|
|
||||||
service_path: String,
|
|
||||||
},
|
|
||||||
NotFound,
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn delete_repo_and_cache<T>(
|
|
||||||
state: web::Data<Arc<State>>,
|
|
||||||
data: web::Path<(String, String)>,
|
|
||||||
) -> Result<impl Responder>
|
|
||||||
where
|
|
||||||
T: Service,
|
|
||||||
{
|
|
||||||
let data = data.into_inner();
|
|
||||||
let span = info_span!(
|
|
||||||
"deleting repository and cache",
|
|
||||||
service = T::domain(),
|
|
||||||
user = data.0.as_str(),
|
|
||||||
repo = data.1.as_str()
|
|
||||||
);
|
|
||||||
let future = async {
|
|
||||||
let repo = format!(
|
|
||||||
"{}/{}/{}",
|
|
||||||
T::domain(),
|
|
||||||
data.0.to_lowercase(),
|
|
||||||
data.1.to_lowercase()
|
|
||||||
);
|
|
||||||
info!("Deleting cache and repository");
|
|
||||||
let cache_dir = format!("{}/{}.json", &state.cache, repo);
|
|
||||||
let repo_dir = format!("{}/{}", &state.repos, repo);
|
|
||||||
std::fs::remove_file(&cache_dir).or_else(|e| {
|
|
||||||
if e.kind() == io::ErrorKind::NotFound {
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err(e)
|
|
||||||
}
|
|
||||||
})?;
|
|
||||||
std::fs::remove_dir_all(&repo_dir).or_else(|e| {
|
|
||||||
if e.kind() == io::ErrorKind::NotFound {
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err(e)
|
|
||||||
}
|
|
||||||
})?;
|
|
||||||
REPO_COUNT.fetch_sub(1, Ordering::Relaxed);
|
|
||||||
Ok(HttpResponse::TemporaryRedirect()
|
|
||||||
.header(
|
|
||||||
LOCATION,
|
|
||||||
format!("/{}/{}/{}/view", T::url_path(), data.0, data.1),
|
|
||||||
)
|
|
||||||
.finish())
|
|
||||||
};
|
|
||||||
future.instrument(span).await
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn handle_hoc_request<T, F>(
|
|
||||||
state: web::Data<Arc<State>>,
|
|
||||||
data: web::Path<(String, String)>,
|
|
||||||
branch: &str,
|
|
||||||
mapper: F,
|
|
||||||
) -> Result<HttpResponse>
|
|
||||||
where
|
|
||||||
T: Service,
|
|
||||||
F: Fn(HocResult) -> Result<HttpResponse>,
|
|
||||||
{
|
|
||||||
let data = data.into_inner();
|
|
||||||
let span = info_span!(
|
|
||||||
"handling hoc calculation",
|
|
||||||
service = T::domain(),
|
|
||||||
user = data.0.as_str(),
|
|
||||||
repo = data.1.as_str(),
|
|
||||||
branch
|
|
||||||
);
|
|
||||||
let future = async {
|
|
||||||
let repo = format!("{}/{}", data.0.to_lowercase(), data.1.to_lowercase());
|
|
||||||
let service_path = format!("{}/{}", T::url_path(), repo);
|
|
||||||
let service_url = format!("{}/{}", T::domain(), repo);
|
|
||||||
let path = format!("{}/{}", state.repos, service_url);
|
|
||||||
let url = format!("https://{}", service_url);
|
|
||||||
let remote_exists = remote_exists(&url).await?;
|
|
||||||
let file = Path::new(&path);
|
|
||||||
if !file.exists() {
|
|
||||||
if !remote_exists {
|
|
||||||
warn!("Repository does not exist");
|
|
||||||
return mapper(HocResult::NotFound);
|
|
||||||
}
|
|
||||||
info!("Cloning for the first time");
|
|
||||||
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, commits) = hoc(&service_url, &state.repos, &state.cache, branch)?;
|
|
||||||
let hoc_pretty = match NumberPrefix::decimal(hoc as f64) {
|
|
||||||
NumberPrefix::Standalone(hoc) => hoc.to_string(),
|
|
||||||
NumberPrefix::Prefixed(prefix, hoc) => format!("{:.1}{}", hoc, prefix),
|
|
||||||
};
|
|
||||||
let res = HocResult::Hoc {
|
|
||||||
hoc,
|
|
||||||
commits,
|
|
||||||
hoc_pretty,
|
|
||||||
head,
|
|
||||||
url,
|
|
||||||
repo,
|
|
||||||
service_path,
|
|
||||||
};
|
|
||||||
mapper(res)
|
|
||||||
};
|
|
||||||
future.instrument(span).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) async fn json_hoc<T: Service>(
|
|
||||||
state: web::Data<Arc<State>>,
|
|
||||||
data: web::Path<(String, String)>,
|
|
||||||
branch: web::Query<BranchQuery>,
|
|
||||||
) -> Result<HttpResponse> {
|
|
||||||
let branch = branch.branch.as_deref().unwrap_or("master");
|
|
||||||
let mapper = |r| match r {
|
|
||||||
HocResult::NotFound => p404(),
|
|
||||||
HocResult::Hoc {
|
|
||||||
hoc, head, commits, ..
|
|
||||||
} => Ok(HttpResponse::Ok().json(JsonResponse {
|
|
||||||
branch,
|
|
||||||
head: &head,
|
|
||||||
count: hoc,
|
|
||||||
commits,
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
handle_hoc_request::<T, _>(state, data, branch, mapper).await
|
|
||||||
}
|
|
||||||
|
|
||||||
fn no_cache_response(body: Vec<u8>) -> HttpResponse {
|
|
||||||
let expiration = SystemTime::now() + Duration::from_secs(30);
|
|
||||||
HttpResponse::Ok()
|
|
||||||
.content_type("image/svg+xml")
|
|
||||||
.set(Expires(expiration.into()))
|
|
||||||
.set(CacheControl(vec![
|
|
||||||
CacheDirective::MaxAge(0u32),
|
|
||||||
CacheDirective::MustRevalidate,
|
|
||||||
CacheDirective::NoCache,
|
|
||||||
CacheDirective::NoStore,
|
|
||||||
]))
|
|
||||||
.body(body)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) async fn calculate_hoc<T: Service>(
|
|
||||||
state: web::Data<Arc<State>>,
|
|
||||||
data: web::Path<(String, String)>,
|
|
||||||
branch: web::Query<BranchQuery>,
|
|
||||||
) -> HttpResponse {
|
|
||||||
let mapper = move |r| match r {
|
|
||||||
HocResult::NotFound => p404(),
|
|
||||||
HocResult::Hoc { hoc_pretty, .. } => {
|
|
||||||
let badge_opt = BadgeOptions {
|
|
||||||
subject: "Hits-of-Code".to_string(),
|
|
||||||
color: "#007ec6".to_string(),
|
|
||||||
status: hoc_pretty,
|
|
||||||
};
|
|
||||||
let badge = Badge::new(badge_opt)?;
|
|
||||||
// TODO: remove clone
|
|
||||||
let body = badge.to_svg().as_bytes().to_vec();
|
|
||||||
|
|
||||||
Ok(no_cache_response(body))
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let branch = branch.branch.as_deref().unwrap_or("master");
|
|
||||||
let error_badge = |_| {
|
|
||||||
let error_badge = Badge::new(BadgeOptions {
|
|
||||||
subject: "Hits-of-Code".to_string(),
|
|
||||||
color: "#ff0000".to_string(),
|
|
||||||
status: "error".to_string(),
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
let body = error_badge.to_svg().as_bytes().to_vec();
|
|
||||||
no_cache_response(body)
|
|
||||||
};
|
|
||||||
handle_hoc_request::<T, _>(state, data, branch, mapper)
|
|
||||||
.await
|
|
||||||
.unwrap_or_else(error_badge)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn overview<T: Service>(
|
|
||||||
state: web::Data<Arc<State>>,
|
|
||||||
data: web::Path<(String, String)>,
|
|
||||||
branch: web::Query<BranchQuery>,
|
|
||||||
) -> Result<HttpResponse> {
|
|
||||||
let branch = branch.branch.as_deref().unwrap_or("master");
|
|
||||||
let mapper = |r| match r {
|
|
||||||
HocResult::NotFound => p404(),
|
|
||||||
HocResult::Hoc {
|
|
||||||
hoc,
|
|
||||||
commits,
|
|
||||||
hoc_pretty,
|
|
||||||
url,
|
|
||||||
head,
|
|
||||||
repo,
|
|
||||||
service_path,
|
|
||||||
} => {
|
|
||||||
let mut buf = Vec::new();
|
|
||||||
let repo_info = RepoInfo {
|
|
||||||
commit_url: &T::commit_url(&repo, &head),
|
|
||||||
commits,
|
|
||||||
base_url: &OPT.base_url,
|
|
||||||
head: &head,
|
|
||||||
hoc,
|
|
||||||
hoc_pretty: &hoc_pretty,
|
|
||||||
path: &service_path,
|
|
||||||
url: &url,
|
|
||||||
branch,
|
|
||||||
};
|
|
||||||
templates::overview(
|
|
||||||
&mut buf,
|
|
||||||
VERSION_INFO,
|
|
||||||
REPO_COUNT.load(Ordering::Relaxed),
|
|
||||||
repo_info,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().content_type("text/html").body(buf))
|
|
||||||
}
|
|
||||||
};
|
|
||||||
handle_hoc_request::<T, _>(state, data, branch, mapper).await
|
|
||||||
}
|
|
||||||
|
|
||||||
#[get("/")]
|
|
||||||
async fn index() -> Result<HttpResponse> {
|
|
||||||
let mut buf = Vec::new();
|
|
||||||
templates::index(
|
|
||||||
&mut buf,
|
|
||||||
VERSION_INFO,
|
|
||||||
REPO_COUNT.load(Ordering::Relaxed),
|
|
||||||
&OPT.base_url,
|
|
||||||
)?;
|
|
||||||
Ok(HttpResponse::Ok().content_type("text/html").body(buf))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[post("/generate")]
|
|
||||||
async fn generate(params: web::Form<GeneratorForm<'_>>) -> Result<HttpResponse> {
|
|
||||||
let repo = format!("{}/{}", params.user, params.repo);
|
|
||||||
let mut buf = Vec::new();
|
|
||||||
templates::generate(
|
|
||||||
&mut buf,
|
|
||||||
VERSION_INFO,
|
|
||||||
REPO_COUNT.load(Ordering::Relaxed),
|
|
||||||
&OPT.base_url,
|
|
||||||
params.service.url(),
|
|
||||||
params.service.service(),
|
|
||||||
&repo,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().content_type("text/html").body(buf))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn p404() -> Result<HttpResponse> {
|
|
||||||
let mut buf = Vec::new();
|
|
||||||
templates::p404(&mut buf, VERSION_INFO, REPO_COUNT.load(Ordering::Relaxed))?;
|
|
||||||
Ok(HttpResponse::NotFound().content_type("text/html").body(buf))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn async_p404() -> Result<HttpResponse> {
|
|
||||||
p404()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn css() -> HttpResponse {
|
|
||||||
HttpResponse::Ok().content_type("text/css").body(CSS)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn favicon32() -> HttpResponse {
|
|
||||||
HttpResponse::Ok().content_type("image/png").body(FAVICON)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn start_server() -> std::io::Result<()> {
|
|
||||||
let interface = format!("{}:{}", OPT.host, OPT.port);
|
|
||||||
let state = Arc::new(State {
|
|
||||||
repos: OPT.repodir.display().to_string(),
|
|
||||||
cache: OPT.cachedir.display().to_string(),
|
|
||||||
});
|
|
||||||
HttpServer::new(move || {
|
|
||||||
App::new()
|
|
||||||
.data(state.clone())
|
|
||||||
.wrap(tracing_actix_web::TracingLogger)
|
|
||||||
.wrap(middleware::NormalizePath::new(TrailingSlash::Trim))
|
|
||||||
.service(index)
|
|
||||||
.service(web::resource("/tacit-css.min.css").route(web::get().to(css)))
|
|
||||||
.service(web::resource("/favicon.ico").route(web::get().to(favicon32)))
|
|
||||||
.service(generate)
|
|
||||||
.service(web::resource("/github/{user}/{repo}").to(calculate_hoc::<GitHub>))
|
|
||||||
.service(web::resource("/gitlab/{user}/{repo}").to(calculate_hoc::<Gitlab>))
|
|
||||||
.service(web::resource("/bitbucket/{user}/{repo}").to(calculate_hoc::<Bitbucket>))
|
|
||||||
.service(
|
|
||||||
web::resource("/github/{user}/{repo}/delete")
|
|
||||||
.route(web::post().to(delete_repo_and_cache::<GitHub>)),
|
|
||||||
)
|
|
||||||
.service(
|
|
||||||
web::resource("/gitlab/{user}/{repo}/delete")
|
|
||||||
.route(web::post().to(delete_repo_and_cache::<Gitlab>)),
|
|
||||||
)
|
|
||||||
.service(
|
|
||||||
web::resource("/bitbucket/{user}/{repo}/delete")
|
|
||||||
.route(web::post().to(delete_repo_and_cache::<Bitbucket>)),
|
|
||||||
)
|
|
||||||
.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("/bitbucket/{user}/{repo}/json").to(json_hoc::<Bitbucket>))
|
|
||||||
.service(web::resource("/view/github/{user}/{repo}").to(overview::<GitHub>))
|
|
||||||
.service(web::resource("/view/gitlab/{user}/{repo}").to(overview::<Gitlab>))
|
|
||||||
.service(web::resource("/view/bitbucket/{user}/{repo}").to(overview::<Bitbucket>))
|
|
||||||
.service(web::resource("/github/{user}/{repo}/view").to(overview::<GitHub>))
|
|
||||||
.service(web::resource("/gitlab/{user}/{repo}/view").to(overview::<Gitlab>))
|
|
||||||
.service(web::resource("/bitbucket/{user}/{repo}/view").to(overview::<Bitbucket>))
|
|
||||||
.default_service(web::resource("").route(web::get().to(async_p404)))
|
|
||||||
})
|
|
||||||
.workers(OPT.workers)
|
|
||||||
.bind(interface)?
|
|
||||||
.run()
|
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::main]
|
#[actix_rt::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
config::init();
|
let _uninstall = init();
|
||||||
let span = info_span!("hoc", version = env!("CARGO_PKG_VERSION"));
|
|
||||||
let _ = span.enter();
|
// TODO: error handling
|
||||||
start_server().instrument(span).await
|
let settings = Settings::load().expect("Cannot load config");
|
||||||
|
|
||||||
|
let address = format!("{}:{}", settings.host, settings.port);
|
||||||
|
// TODO: error handling
|
||||||
|
let listener = TcpListener::bind(address).expect("cannot bind addres");
|
||||||
|
|
||||||
|
hoc::run(listener, settings)
|
||||||
|
.await
|
||||||
|
.expect("Server error")
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
use crate::{config::Settings, count::count_repositories};
|
|
||||||
use std::sync::atomic::AtomicUsize;
|
|
||||||
|
|
||||||
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,7 +12,4 @@ 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: Settings = Settings::new().unwrap();
|
|
||||||
pub(crate) static ref REPO_COUNT: AtomicUsize =
|
|
||||||
AtomicUsize::new(count_repositories(&OPT.repodir).unwrap());
|
|
||||||
}
|
}
|
||||||
|
35
src/telemetry.rs
Normal file
35
src/telemetry.rs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
use opentelemetry::global;
|
||||||
|
use opentelemetry_jaeger::Uninstall;
|
||||||
|
use tracing::{subscriber::set_global_default, Subscriber};
|
||||||
|
use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer};
|
||||||
|
use tracing_log::LogTracer;
|
||||||
|
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry};
|
||||||
|
|
||||||
|
// TODO: don't pass `Uninstall` around...
|
||||||
|
pub fn get_subscriber(name: &str, env_filter: &str) -> (impl Subscriber + Send + Sync, Uninstall) {
|
||||||
|
let env_filter =
|
||||||
|
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(env_filter));
|
||||||
|
|
||||||
|
let formatting_layer = BunyanFormattingLayer::new(name.to_string(), std::io::stdout);
|
||||||
|
|
||||||
|
global::set_text_map_propagator(opentelemetry_jaeger::Propagator::new());
|
||||||
|
let (tracer, uninstall) = opentelemetry_jaeger::new_pipeline()
|
||||||
|
.with_service_name(name)
|
||||||
|
.install()
|
||||||
|
.expect("cannot install jaeger pipeline");
|
||||||
|
let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);
|
||||||
|
|
||||||
|
(
|
||||||
|
Registry::default()
|
||||||
|
.with(telemetry)
|
||||||
|
.with(env_filter)
|
||||||
|
.with(JsonStorageLayer)
|
||||||
|
.with(formatting_layer),
|
||||||
|
uninstall,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_subscriber(subscriber: impl Subscriber + Send + Sync) {
|
||||||
|
LogTracer::init().expect("Failed to set logger");
|
||||||
|
set_global_default(subscriber).expect("Failed to set tracing subscriber");
|
||||||
|
}
|
68
src/tests.rs
68
src/tests.rs
@ -1,68 +0,0 @@
|
|||||||
use crate::{
|
|
||||||
calculate_hoc, index, json_hoc,
|
|
||||||
service::{Bitbucket, GitHub, Gitlab, Service},
|
|
||||||
State,
|
|
||||||
};
|
|
||||||
|
|
||||||
use actix_web::{http, test, web, App};
|
|
||||||
use tempfile::tempdir;
|
|
||||||
|
|
||||||
macro_rules! test_app {
|
|
||||||
($path: expr) => {
|
|
||||||
test::init_service(App::new().service($path)).await
|
|
||||||
};
|
|
||||||
($state: expr, $path: expr) => {
|
|
||||||
test::init_service(App::new().data($state).service($path)).await
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! test_service {
|
|
||||||
($name: ident, $path: tt, $what: ident) => {
|
|
||||||
async fn $name<T: 'static + Service>(req_path: &str) {
|
|
||||||
let repo_dir = dbg!(tempdir().unwrap());
|
|
||||||
let cache_dir = dbg!(tempdir().unwrap());
|
|
||||||
let repos = format!("{}/", repo_dir.path().display());
|
|
||||||
let cache = format!("{}/", cache_dir.path().display());
|
|
||||||
let state = dbg!(State { repos, cache });
|
|
||||||
|
|
||||||
let mut app = test_app!(state, web::resource($path).to($what::<T>));
|
|
||||||
|
|
||||||
let req = dbg!(test::TestRequest::with_uri(req_path).to_request());
|
|
||||||
let resp = dbg!(test::call_service(&mut app, req).await);
|
|
||||||
|
|
||||||
assert_eq!(resp.status(), http::StatusCode::OK);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn test_index() {
|
|
||||||
std::env::set_var("HOC_BASE_URL", "http://0.0.0.0:8080");
|
|
||||||
|
|
||||||
let mut app = test_app!(index);
|
|
||||||
|
|
||||||
let req = dbg!(test::TestRequest::with_uri("/").to_request());
|
|
||||||
let resp = dbg!(test::call_service(&mut app, req).await);
|
|
||||||
|
|
||||||
assert_eq!(resp.status(), http::StatusCode::OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: fix this test
|
|
||||||
// #[actix_rt::test]
|
|
||||||
async fn test_json() {
|
|
||||||
test_service!(test_json_service, "/service/{user}/{repo}/json", json_hoc);
|
|
||||||
|
|
||||||
test_json_service::<Gitlab>("/service/vbrandl/hoc/json").await;
|
|
||||||
test_json_service::<GitHub>("/service/vbrandl/hoc/json").await;
|
|
||||||
test_json_service::<Bitbucket>("/service/vbrandl/hoc/json").await;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: fix this test
|
|
||||||
// #[actix_rt::test]
|
|
||||||
async fn test_badge() {
|
|
||||||
test_service!(test_badge_service, "/service/{user}/{repo}", calculate_hoc);
|
|
||||||
|
|
||||||
test_badge_service::<Gitlab>("/service/vbrandl/hoc").await;
|
|
||||||
test_badge_service::<GitHub>("/service/vbrandl/hoc").await;
|
|
||||||
test_badge_service::<Bitbucket>("/service/vbrandl/hoc").await;
|
|
||||||
}
|
|
@ -19,7 +19,7 @@ To include the badge in your readme, use the following markdown:
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
[](@repo_info.base_url/@repo_info.path?branch=@repo_info.branch/view?branch=@repo_info.branch)
|
[](@repo_info.base_url/@repo_info.path/view?branch=@repo_info.branch)
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
|
||||||
|
18
tests/badge.rs
Normal file
18
tests/badge.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
mod util;
|
||||||
|
|
||||||
|
use actix_web::client;
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn badge_succeeds() {
|
||||||
|
let test_app = util::spawn_app().await;
|
||||||
|
|
||||||
|
let client = client::Client::default();
|
||||||
|
|
||||||
|
let response = client
|
||||||
|
.get(&format!("{}/github/vbrandl/hoc", test_app.address))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.expect("Failed to execute request");
|
||||||
|
|
||||||
|
assert!(response.status().is_success());
|
||||||
|
}
|
18
tests/health_check.rs
Normal file
18
tests/health_check.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
mod util;
|
||||||
|
|
||||||
|
use actix_web::client;
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn health_check_works() {
|
||||||
|
let test_app = util::spawn_app().await;
|
||||||
|
|
||||||
|
let client = client::Client::default();
|
||||||
|
|
||||||
|
let response = client
|
||||||
|
.get(&format!("{}/health_check", test_app.address))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.expect("Failed to execute request");
|
||||||
|
|
||||||
|
assert!(response.status().is_success());
|
||||||
|
}
|
18
tests/index.rs
Normal file
18
tests/index.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
mod util;
|
||||||
|
|
||||||
|
use actix_web::client;
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn index_returns_success() {
|
||||||
|
let test_app = util::spawn_app().await;
|
||||||
|
|
||||||
|
let client = client::Client::default();
|
||||||
|
|
||||||
|
let response = client
|
||||||
|
.get(&format!("{}/", test_app.address))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.expect("Failed to execute request");
|
||||||
|
|
||||||
|
assert!(response.status().is_success());
|
||||||
|
}
|
18
tests/json.rs
Normal file
18
tests/json.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
mod util;
|
||||||
|
|
||||||
|
use actix_web::client;
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn json_returns_success() {
|
||||||
|
let test_app = util::spawn_app().await;
|
||||||
|
|
||||||
|
let client = client::Client::default();
|
||||||
|
|
||||||
|
let response = client
|
||||||
|
.get(&format!("{}/github/vbrandl/hoc/json", test_app.address))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.expect("Failed to execute request");
|
||||||
|
|
||||||
|
assert!(response.status().is_success());
|
||||||
|
}
|
50
tests/util/mod.rs
Normal file
50
tests/util/mod.rs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
use hoc::{config::Settings, telemetry};
|
||||||
|
|
||||||
|
use std::net::TcpListener;
|
||||||
|
|
||||||
|
use tempfile::{tempdir, TempDir};
|
||||||
|
|
||||||
|
lazy_static::lazy_static! {
|
||||||
|
static ref TRACING: () = {
|
||||||
|
let filter = if std::env::var("TEST_LOG").is_ok() { "debug" } else { "" };
|
||||||
|
let subscriber = telemetry::get_subscriber("test", filter).0;
|
||||||
|
telemetry::init_subscriber(subscriber);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct TestApp {
|
||||||
|
pub address: String,
|
||||||
|
repo_dir: TempDir,
|
||||||
|
cache_dir: TempDir,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn spawn_app() -> TestApp {
|
||||||
|
lazy_static::initialize(&TRACING);
|
||||||
|
|
||||||
|
let listener = TcpListener::bind("127.0.0.1:0").expect("Failed to bind random port");
|
||||||
|
|
||||||
|
let port = listener.local_addr().unwrap().port();
|
||||||
|
let address = format!("http://127.0.0.1:{}", port);
|
||||||
|
|
||||||
|
let repo_dir = tempdir().expect("Cannot create repo_dir");
|
||||||
|
let cache_dir = tempdir().expect("Cannot create cache_dir");
|
||||||
|
|
||||||
|
let mut settings = Settings::load().expect("Failed to read configuration.");
|
||||||
|
settings.repodir = repo_dir.path().to_path_buf();
|
||||||
|
settings.cachedir = cache_dir.path().to_path_buf();
|
||||||
|
// configuration.database.database_name = Uuid::new_v4().to_string();
|
||||||
|
|
||||||
|
// let connection_pool = configure_database(&configuration.database).await;
|
||||||
|
|
||||||
|
let server = hoc::run(listener, settings)
|
||||||
|
.await
|
||||||
|
.expect("Failed to bind address");
|
||||||
|
|
||||||
|
let _ = tokio::spawn(server);
|
||||||
|
|
||||||
|
TestApp {
|
||||||
|
address,
|
||||||
|
repo_dir,
|
||||||
|
cache_dir,
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user