Compare commits

...

69 Commits

Author SHA1 Message Date
bdae157caf Bump serde from 1.0.100 to 1.0.101
Some checks reported errors
continuous-integration/drone/push Build was killed
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.100 to 1.0.101.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.100...v1.0.101)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-14 15:26:08 +02:00
d6618a0e61 Bump serde_derive from 1.0.100 to 1.0.101
Bumps [serde_derive](https://github.com/serde-rs/serde) from 1.0.100 to 1.0.101.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.100...v1.0.101)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-14 15:26:08 +02:00
1223d429db Merge pull request #60 from vbrandl/vbrandl-patch-1
All checks were successful
continuous-integration/drone/push Build is passing
Add Github actions
2019-09-09 21:39:32 +02:00
9613aa7848 Add Github actions 2019-09-09 21:39:16 +02:00
334fa8ced5 Bump version number
All checks were successful
continuous-integration/drone/push Build is passing
2019-09-09 18:19:53 +02:00
062343dd32 Merge pull request #57 from vbrandl/dependabot/cargo/serde-1.0.100
Bump serde from 1.0.99 to 1.0.100
2019-09-09 18:18:15 +02:00
bdb2a151fa Merge pull request #56 from vbrandl/dependabot/cargo/futures-0.1.29
Bump futures from 0.1.28 to 0.1.29
2019-09-09 18:17:04 +02:00
7e66393966 Bump serde from 1.0.99 to 1.0.100
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.99 to 1.0.100.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.99...v1.0.100)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-09-09 16:16:33 +00:00
32ac5ca0d8 Merge pull request #58 from vbrandl/dependabot/cargo/structopt-0.3.1
Bump structopt from 0.2.18 to 0.3.1
2019-09-09 18:15:19 +02:00
b3b4cd0e42 Merge pull request #59 from vbrandl/dependabot/cargo/serde_derive-1.0.100
Bump serde_derive from 1.0.99 to 1.0.100
2019-09-09 18:15:07 +02:00
be08b87bbb Bump serde_derive from 1.0.99 to 1.0.100
Bumps [serde_derive](https://github.com/serde-rs/serde) from 1.0.99 to 1.0.100.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.99...v1.0.100)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-09-09 04:25:47 +00:00
cf4d427b96 Bump structopt from 0.2.18 to 0.3.1
Bumps [structopt](https://github.com/TeXitoi/structopt) from 0.2.18 to 0.3.1.
- [Release notes](https://github.com/TeXitoi/structopt/releases)
- [Changelog](https://github.com/TeXitoi/structopt/blob/master/CHANGELOG.md)
- [Commits](https://github.com/TeXitoi/structopt/compare/v0.2.18...v0.3.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-09-09 04:25:23 +00:00
b5ebc54372 Bump futures from 0.1.28 to 0.1.29
Bumps [futures](https://github.com/rust-lang-nursery/futures-rs) from 0.1.28 to 0.1.29.
- [Release notes](https://github.com/rust-lang-nursery/futures-rs/releases)
- [Changelog](https://github.com/rust-lang-nursery/futures-rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang-nursery/futures-rs/compare/0.1.28...0.1.29)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-09-06 04:23:07 +00:00
231741629e Merge pull request #53 from vbrandl/dependabot/cargo/actix-web-1.0.7
All checks were successful
continuous-integration/drone/push Build is passing
Bump actix-web from 1.0.5 to 1.0.7
2019-08-30 11:22:26 +02:00
135c5756b1 Merge pull request #54 from vbrandl/dependabot/cargo/ructe-0.7.2
Bump ructe from 0.7.0 to 0.7.2
2019-08-30 11:21:07 +02:00
79cfee5fa5 Bump ructe from 0.7.0 to 0.7.2
Bumps [ructe](https://github.com/kaj/ructe) from 0.7.0 to 0.7.2.
- [Release notes](https://github.com/kaj/ructe/releases)
- [Commits](https://github.com/kaj/ructe/compare/v0.7.0...v0.7.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-08-29 04:27:17 +00:00
1c9b5db4e1 Bump actix-web from 1.0.5 to 1.0.7
Bumps [actix-web](https://github.com/actix/actix-web) from 1.0.5 to 1.0.7.
- [Release notes](https://github.com/actix/actix-web/releases)
- [Changelog](https://github.com/actix/actix-web/blob/master/CHANGES.md)
- [Commits](https://github.com/actix/actix-web/compare/web-v1.0.5...web-v1.0.7)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-08-29 04:26:47 +00:00
6e0e452395 Bump version number
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-08-28 20:21:56 +02:00
9e44731650 Merge pull request #50 from vbrandl/dependabot/cargo/reqwest-0.9.20
Bump reqwest from 0.9.19 to 0.9.20
2019-08-28 20:20:37 +02:00
f673d71387 Bump reqwest from 0.9.19 to 0.9.20
Bumps [reqwest](https://github.com/seanmonstar/reqwest) from 0.9.19 to 0.9.20.
- [Release notes](https://github.com/seanmonstar/reqwest/releases)
- [Changelog](https://github.com/seanmonstar/reqwest/blob/v0.9.20/CHANGELOG.md)
- [Commits](https://github.com/seanmonstar/reqwest/compare/v0.9.19...v0.9.20)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-08-28 18:20:05 +00:00
eda1822dce Merge pull request #51 from vbrandl/dependabot/cargo/lazy_static-1.4.0
Bump lazy_static from 1.3.0 to 1.4.0
2019-08-28 20:18:56 +02:00
fb64af3456 Bump lazy_static from 1.3.0 to 1.4.0
Bumps [lazy_static](https://github.com/rust-lang-nursery/lazy-static.rs) from 1.3.0 to 1.4.0.
- [Release notes](https://github.com/rust-lang-nursery/lazy-static.rs/releases)
- [Commits](https://github.com/rust-lang-nursery/lazy-static.rs/compare/1.3.0...1.4.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-08-28 18:18:32 +00:00
0837284798 Merge pull request #48 from vbrandl/dependabot/cargo/serde-1.0.99
Bump serde from 1.0.98 to 1.0.99
2019-08-28 20:18:24 +02:00
a7039f15b5 Merge pull request #52 from vbrandl/dependabot/cargo/spin-0.5.2
[Security] Bump spin from 0.5.0 to 0.5.2
2019-08-28 20:16:54 +02:00
b1be281982 [Security] Bump spin from 0.5.0 to 0.5.2
Bumps [spin](https://github.com/mvdnes/spin-rs) from 0.5.0 to 0.5.2. **This update includes a security fix.**
- [Release notes](https://github.com/mvdnes/spin-rs/releases)
- [Commits](https://github.com/mvdnes/spin-rs/commits)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-08-28 17:22:32 +00:00
2795995f58 Bump serde from 1.0.98 to 1.0.99
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.98 to 1.0.99.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.98...v1.0.99)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-08-28 07:43:01 +00:00
913cc9dc75 Merge pull request #47 from vbrandl/dependabot/cargo/serde_derive-1.0.99
Bump serde_derive from 1.0.98 to 1.0.99
2019-08-28 09:27:35 +02:00
645d6e4a2b Bump serde_derive from 1.0.98 to 1.0.99
Bumps [serde_derive](https://github.com/serde-rs/serde) from 1.0.98 to 1.0.99.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.98...v1.0.99)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-08-28 07:23:42 +00:00
e455a89de4 Fix Docker TLS certdir
All checks were successful
continuous-integration/drone/push Build is passing
2019-08-28 09:14:17 +02:00
f2cae46624 Update CI script for new docker version
All checks were successful
continuous-integration/drone/push Build is passing
2019-08-02 15:14:31 +02:00
f47cbbe81a Merge pull request #44 from vbrandl/dependabot/cargo/serde_derive-1.0.98
All checks were successful
continuous-integration/drone/push Build is passing
Bump serde_derive from 1.0.97 to 1.0.98
2019-08-02 15:01:12 +02:00
85f90c0bdb Bump serde_derive from 1.0.97 to 1.0.98
Bumps [serde_derive](https://github.com/serde-rs/serde) from 1.0.97 to 1.0.98.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.97...v1.0.98)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-08-02 13:00:35 +00:00
9143e5dbf8 Merge pull request #45 from vbrandl/dependabot/cargo/serde-1.0.98
Bump serde from 1.0.97 to 1.0.98
2019-08-02 14:59:02 +02:00
865e3c7bbd Merge pull request #46 from vbrandl/dependabot/cargo/log-0.4.8
Bump log from 0.4.7 to 0.4.8
2019-08-02 14:58:53 +02:00
5ebdd4067c Bump version number
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-07-29 21:50:21 +02:00
55a1405e71 Enable NormalizePath middleware
This allows double slashes in paths
2019-07-29 21:49:25 +02:00
1436336b6a Bump log from 0.4.7 to 0.4.8
Bumps [log](https://github.com/rust-lang/log) from 0.4.7 to 0.4.8.
- [Release notes](https://github.com/rust-lang/log/releases)
- [Changelog](https://github.com/rust-lang-nursery/log/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/log/commits)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-07-29 04:34:22 +00:00
5a74306e49 Bump serde from 1.0.97 to 1.0.98
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.97 to 1.0.98.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.97...v1.0.98)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-07-29 04:33:55 +00:00
614e5a6da5 Bump version number
All checks were successful
continuous-integration/drone/tag Build is passing
continuous-integration/drone/push Build is passing
2019-07-22 22:27:19 +02:00
0128e267cc Use async client to check if a repo exists 2019-07-22 22:26:37 +02:00
c3dffac5da Use async client 2019-07-22 22:25:55 +02:00
aaaff22907 Merge pull request #42 from vbrandl/dependabot/cargo/reqwest-0.9.19
Bump reqwest from 0.9.17 to 0.9.19
2019-07-22 21:39:45 +02:00
ddfcbf11f1 Bump reqwest from 0.9.17 to 0.9.19
Bumps [reqwest](https://github.com/seanmonstar/reqwest) from 0.9.17 to 0.9.19.
- [Release notes](https://github.com/seanmonstar/reqwest/releases)
- [Changelog](https://github.com/seanmonstar/reqwest/blob/master/CHANGELOG.md)
- [Commits](https://github.com/seanmonstar/reqwest/compare/v0.9.17...v0.9.19)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-07-22 04:28:01 +00:00
3bee454548 Bump version number
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-07-19 17:03:24 +02:00
9cff6f1f13 Merge pull request #40 from vbrandl/dependabot/cargo/serde-1.0.97
Bump serde from 1.0.93 to 1.0.97
2019-07-19 16:43:35 +02:00
c946c5d0b4 Bump serde from 1.0.93 to 1.0.97
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.93 to 1.0.97.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.93...v1.0.97)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-07-19 14:41:50 +00:00
88ae90af95 Merge pull request #39 from vbrandl/dependabot/cargo/actix-web-1.0.5
Bump actix-web from 1.0.3 to 1.0.5
2019-07-19 16:40:36 +02:00
9f783dffa8 Merge pull request #41 from vbrandl/dependabot/cargo/ructe-0.7.0
Bump ructe from 0.6.4 to 0.7.0
2019-07-19 16:40:23 +02:00
2cdf64ed80 Bump ructe from 0.6.4 to 0.7.0
Bumps [ructe](https://github.com/kaj/ructe) from 0.6.4 to 0.7.0.
- [Release notes](https://github.com/kaj/ructe/releases)
- [Commits](https://github.com/kaj/ructe/compare/v0.6.4...v0.7.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-07-19 14:40:13 +00:00
9e024b530e Merge pull request #38 from vbrandl/dependabot/cargo/serde_derive-1.0.97
Bump serde_derive from 1.0.94 to 1.0.97
2019-07-19 16:38:43 +02:00
0db7b26541 Bump actix-web from 1.0.3 to 1.0.5
Bumps [actix-web](https://github.com/actix/actix-web) from 1.0.3 to 1.0.5.
- [Release notes](https://github.com/actix/actix-web/releases)
- [Changelog](https://github.com/actix/actix-web/blob/master/CHANGES.md)
- [Commits](https://github.com/actix/actix-web/compare/web-v1.0.3...web-v1.0.5)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-07-18 15:13:53 +00:00
009d2c4813 Bump serde_derive from 1.0.94 to 1.0.97
Bumps [serde_derive](https://github.com/serde-rs/serde) from 1.0.94 to 1.0.97.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.94...v1.0.97)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-07-18 15:13:40 +00:00
f0ed6c2e23 Merge pull request #35 from vbrandl/dependabot/cargo/log-0.4.7
All checks were successful
continuous-integration/drone/push Build is passing
Bump log from 0.4.6 to 0.4.7
2019-07-14 14:25:47 +02:00
d16a21e74e Bump log from 0.4.6 to 0.4.7
Bumps [log](https://github.com/rust-lang/log) from 0.4.6 to 0.4.7.
- [Release notes](https://github.com/rust-lang/log/releases)
- [Changelog](https://github.com/rust-lang-nursery/log/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/log/compare/0.4.6...0.4.7)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-07-11 06:35:54 +00:00
7e721ac212 Fork in for loop
[ci skip]
2019-07-07 21:01:57 +02:00
4eb5d06cd1 Fork in loop
[ci skip]
2019-07-07 20:33:08 +02:00
b71207ca51 Add helper scripts for finding and loading active repos (on github)
[ci skip]
2019-07-07 20:22:32 +02:00
f3902f800f Remove migration subcommand
All checks were successful
continuous-integration/drone/push Build is passing
2019-07-07 18:27:50 +02:00
b8e454762e Bump version number
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-07-07 14:53:51 +02:00
268734efdd Merge branch 'feature/commit-count'
Closes #33
2019-07-07 14:53:10 +02:00
c71925f61e Add migration subcommand 2019-07-07 14:52:42 +02:00
c5bbd14a05 Update documentation for the JSON endpoint 2019-07-07 13:36:14 +02:00
a239a3f80b Calculate number of commits
The number of commits is shown in the overview page and returned in the
JSON response.

Closes #33
2019-07-07 13:30:17 +02:00
00b4e60341 Add parse error 2019-07-07 13:29:26 +02:00
ed1cafafd0 Show commit count in overview page 2019-07-07 13:29:03 +02:00
bdb10fd54a Add commit count to the cache struct 2019-07-07 13:28:43 +02:00
1f01c3b964 Bump version number
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-07-05 12:50:55 +02:00
3f94789b8b Merge pull request #32 from vbrandl/dependabot/cargo/actix-web-1.0.3
Bump actix-web from 1.0.2 to 1.0.3
2019-07-05 12:49:40 +02:00
e4f8604861 Bump actix-web from 1.0.2 to 1.0.3
All checks were successful
continuous-integration/drone/push Build is passing
Bumps [actix-web](https://github.com/actix/actix-web) from 1.0.2 to 1.0.3.
- [Release notes](https://github.com/actix/actix-web/releases)
- [Changelog](https://github.com/actix/actix-web/blob/master/CHANGES.md)
- [Commits](https://github.com/actix/actix-web/compare/web-v1.0.2...web-v1.0.3)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-07-03 04:24:43 +00:00
12 changed files with 550 additions and 344 deletions

15
.github/workflows/rust.yml vendored Normal file
View File

@ -0,0 +1,15 @@
name: Rust
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose

View File

@ -1,6 +1,6 @@
image: docker:stable
image: docker:19.03
services:
- docker:dind
- docker:19.03-dind
stages:
- build
@ -9,6 +9,8 @@ stages:
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
# DOCKER_TLS_CERTDIR: "/certs"
DOCKER_TLS_CERTDIR: ""
CONTAINER_BUILDER_IMAGE: $CI_REGISTRY_IMAGE:builder-latest
CONTAINER_TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest

698
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,27 +1,27 @@
[package]
name = "hoc"
version = "0.9.6"
version = "0.11.3"
authors = ["Valentin Brandl <vbrandl@riseup.net>"]
edition = "2018"
build = "build.rs"
[dependencies]
actix-web = "1.0.2"
actix-web = "1.0.7"
badge = "0.2.0"
bytes = "0.4.12"
futures = "0.1.28"
futures = "0.1.29"
git2 = "0.9.1"
lazy_static = "1.3.0"
log = "0.4.6"
lazy_static = "1.4.0"
log = "0.4.8"
log4rs = "0.8.3"
number_prefix = "0.3.0"
openssl-probe = "0.1.2"
reqwest = "0.9.17"
serde = "1.0.93"
serde_derive = "1.0.94"
reqwest = "0.9.20"
serde = "1.0.101"
serde_derive = "1.0.101"
serde_json = "1.0.40"
structopt = "0.2.18"
structopt = "0.3.1"
[build-dependencies]
ructe = "0.6.4"
ructe = "0.7.2"
vergen = "3.0.4"

10
scripts/find-active.sh Executable file
View File

@ -0,0 +1,10 @@
#!/usr/bin/env sh
set -e
DIR=${1:-repos}
for url in $(./scripts/list.sh "${DIR}")
do
(curl "${url}" --silent | grep -q hitsofcode) && echo "${url}" &
done

21
scripts/load-active.sh Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env sh
set -e
ACTIVE=${1}
if [ -z "${ACTIVE}" ]
then
echo "Usage: $0 <list of active repos>"
exit 1
fi
while IFS= read -r url
do
imgs=$(curl "${url}" --silent | grep hitsofcode | grep -o -P 'https://camo.githubusercontent.com/[a-z0-9]+/[a-z0-9]+')
[ -z "${imgs}" ] || echo "${url}"
for img in ${imgs}
do
curl "$img" --silent > /dev/null &
done
done < "${ACTIVE}"

View File

@ -9,7 +9,7 @@ use std::{
/// Enum to indicate the state of the cache
pub(crate) enum CacheState<'a> {
/// Current head and cached head are the same
Current(u64),
Current { count: u64, commits: u64 },
/// Cached head is older than current head
Old(Cache<'a>),
/// No cache was found
@ -21,7 +21,10 @@ impl<'a> CacheState<'a> {
if path.as_ref().exists() {
let cache: Cache = serde_json::from_reader(BufReader::new(File::open(path)?))?;
if cache.head == head {
Ok(CacheState::Current(cache.count))
Ok(CacheState::Current {
count: cache.count,
commits: cache.commits,
})
} else {
Ok(CacheState::Old(cache))
}
@ -30,22 +33,31 @@ impl<'a> CacheState<'a> {
}
}
pub(crate) fn calculate_new_cache(self, count: u64, head: Cow<'a, str>) -> Cache {
pub(crate) fn calculate_new_cache(self, count: u64, commits: u64, head: Cow<'a, str>) -> Cache {
match self {
CacheState::Old(mut cache) => {
cache.head = head;
cache.count += count;
cache.commits += commits;
cache
}
CacheState::No | CacheState::Current(_) => Cache { head, count },
CacheState::No | CacheState::Current { .. } => Cache {
head,
count,
commits,
},
}
}
}
#[derive(Serialize, Deserialize)]
pub(crate) struct Cache<'a> {
/// HEAD commit ref
pub head: Cow<'a, str>,
/// HoC value
pub count: u64,
/// Number of commits
pub commits: u64,
}
impl<'a> Cache<'a> {

View File

@ -16,6 +16,7 @@ pub(crate) enum Error {
Io(std::io::Error),
Log(log::SetLoggerError),
LogBuilder(log4rs::config::Errors),
Parse(std::num::ParseIntError),
Serial(serde_json::Error),
}
@ -29,6 +30,7 @@ impl fmt::Display for Error {
Error::Io(e) => write!(fmt, "Io({})", e),
Error::Log(e) => write!(fmt, "Log({})", e),
Error::LogBuilder(e) => write!(fmt, "LogBuilder({})", e),
Error::Parse(e) => write!(fmt, "Parse({})", e),
Error::Serial(e) => write!(fmt, "Serial({})", e),
}
}
@ -91,3 +93,9 @@ impl From<log4rs::config::Errors> for Error {
Error::LogBuilder(err)
}
}
impl From<std::num::ParseIntError> for Error {
fn from(err: std::num::ParseIntError) -> Self {
Error::Parse(err)
}
}

View File

@ -60,6 +60,7 @@ struct State {
struct JsonResponse<'a> {
head: &'a str,
count: u64,
commits: u64,
}
fn pull(path: impl AsRef<Path>) -> Result<()> {
@ -69,17 +70,13 @@ fn pull(path: impl AsRef<Path>) -> Result<()> {
Ok(())
}
fn hoc(repo: &str, repo_dir: &str, cache_dir: &str) -> Result<(u64, String)> {
fn hoc(repo: &str, repo_dir: &str, cache_dir: &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 head = format!(
"{}",
Repository::open_bare(&repo_dir)?
.head()?
.target()
.ok_or(Error::Internal)?
);
let repo = Repository::open_bare(&repo_dir)?;
let head = format!("{}", repo.head()?.target().ok_or(Error::Internal)?);
let mut arg_commit_count = vec!["rev-list".to_string(), "--count".to_string()];
let mut arg = vec![
"log".to_string(),
"--pretty=tformat:".to_string(),
@ -94,16 +91,18 @@ fn hoc(repo: &str, repo_dir: &str, cache_dir: &str) -> Result<(u64, String)> {
];
let cache = CacheState::read_from_file(&cache_dir, &head)?;
match &cache {
CacheState::Current(res) => {
CacheState::Current { count, commits } => {
info!("Using cache for {}", repo_dir);
return Ok((*res, head));
return Ok((*count, head, *commits));
}
CacheState::Old(cache) => {
info!("Updating cache for {}", repo_dir);
arg.push(format!("{}..HEAD", cache.head));
arg_commit_count.push(format!("{}..HEAD", cache.head));
}
CacheState::No => {
info!("Creating cache for {}", repo_dir);
arg_commit_count.push("HEAD".to_string());
}
};
arg.push("--".to_string());
@ -114,6 +113,13 @@ fn hoc(repo: &str, repo_dir: &str, cache_dir: &str) -> Result<(u64, String)> {
.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| {
@ -125,19 +131,24 @@ fn hoc(repo: &str, repo_dir: &str, cache_dir: &str) -> Result<(u64, String)> {
})
.sum();
let cache = cache.calculate_new_cache(count, (&head).into());
let cache = cache.calculate_new_cache(count, commits, (&head).into());
cache.write_to_file(cache_dir)?;
Ok((cache.count, head))
Ok((cache.count, head, commits))
}
fn remote_exists(url: &str) -> Result<bool> {
Ok(CLIENT.head(url).send()?.status() == reqwest::StatusCode::OK)
fn remote_exists(url: &str) -> impl Future<Item = bool, Error = Error> {
CLIENT
.head(url)
.send()
.map(|resp| resp.status() == reqwest::StatusCode::OK)
.from_err()
}
enum HocResult {
Hoc {
hoc: u64,
commits: u64,
hoc_pretty: String,
head: String,
url: String,
@ -156,15 +167,15 @@ where
T: Service,
F: Fn(HocResult) -> Result<HttpResponse>,
{
futures::future::result(Ok(()))
.and_then(move |_| {
let repo = format!("{}/{}", data.0.to_lowercase(), data.1.to_lowercase());
let service_path = format!("{}/{}", T::domain(), repo);
let path = format!("{}/{}", state.repos, service_path);
let repo = format!("{}/{}", data.0.to_lowercase(), data.1.to_lowercase());
let service_path = format!("{}/{}", T::domain(), repo);
let path = format!("{}/{}", state.repos, service_path);
let url = format!("https://{}", service_path);
remote_exists(&url)
.and_then(move |remote_exists| {
let file = Path::new(&path);
let url = format!("https://{}", service_path);
if !file.exists() {
if !remote_exists(&url)? {
if !remote_exists {
warn!("Repository does not exist: {}", url);
return Ok(HocResult::NotFound);
}
@ -176,15 +187,16 @@ where
REPO_COUNT.fetch_add(1, Ordering::Relaxed);
}
pull(&path)?;
let (hoc, head) = hoc(&service_path, &state.repos, &state.cache)?;
let (hoc, head, commits) = hoc(&service_path, &state.repos, &state.cache)?;
let hoc_pretty = match NumberPrefix::decimal(hoc as f64) {
Standalone(hoc) => hoc.to_string(),
Prefixed(prefix, hoc) => format!("{:.1}{}", hoc, prefix),
};
Ok(HocResult::Hoc {
hoc,
commits,
hoc_pretty,
head,
head: head.to_string(),
url,
repo,
service_path,
@ -199,9 +211,12 @@ fn json_hoc<T: Service>(
) -> impl Future<Item = HttpResponse, Error = Error> {
let mapper = |r| match r {
HocResult::NotFound => p404(),
HocResult::Hoc { hoc, head, .. } => Ok(HttpResponse::Ok().json(JsonResponse {
HocResult::Hoc {
hoc, head, commits, ..
} => Ok(HttpResponse::Ok().json(JsonResponse {
head: &head,
count: hoc,
commits,
})),
};
handle_hoc_request::<T, _>(state, data, mapper)
@ -248,6 +263,7 @@ fn overview<T: Service>(
HocResult::NotFound => p404(),
HocResult::Hoc {
hoc,
commits,
hoc_pretty,
url,
head,
@ -266,6 +282,7 @@ fn overview<T: Service>(
&hoc_pretty,
&head,
&T::commit_url(&repo, &head),
commits,
)?;
let (tx, rx_body) = mpsc::unbounded();
@ -328,8 +345,7 @@ fn favicon32() -> HttpResponse {
HttpResponse::Ok().content_type("image/png").body(FAVICON)
}
fn main() -> Result<()> {
config::init()?;
fn start_server() -> Result<()> {
let interface = format!("{}:{}", OPT.host, OPT.port);
let state = Arc::new(State {
repos: OPT.outdir.display().to_string(),
@ -339,6 +355,7 @@ fn main() -> Result<()> {
App::new()
.data(state.clone())
.wrap(middleware::Logger::default())
.wrap(middleware::NormalizePath)
.service(index)
.service(css)
.service(favicon32)
@ -358,3 +375,8 @@ fn main() -> Result<()> {
.bind(interface)?
.run()?)
}
fn main() -> Result<()> {
config::init()?;
start_server()
}

View File

@ -15,7 +15,7 @@ pub(crate) const CSS: &str = include_str!("../static/tacit-css.min.css");
pub(crate) const FAVICON: &[u8] = include_bytes!("../static/favicon32.png");
lazy_static! {
pub(crate) static ref CLIENT: reqwest::Client = reqwest::Client::new();
pub(crate) static ref CLIENT: reqwest::r#async::Client = reqwest::r#async::Client::new();
pub(crate) static ref OPT: Opt = Opt::from_args();
pub(crate) static ref REPO_COUNT: AtomicUsize =
AtomicUsize::new(count_repositories(&OPT.outdir).unwrap());

View File

@ -46,17 +46,18 @@ alt="example badge" /></a>
</pre>
<p>
You can also request the HoC as JSON by appending <code>/json</code> to the request path. This will return a JSON
object with two fields: <code>count</code> and <code>head</code> with count being the HoC value and head being the
commit ref of <code>HEAD</code>. Requesting
<a href="https://@domain/github/vbrandl/hoc/json">https://@domain/github/vbrandl/hoc/json</a> might return something
along the lines of
You can also request the HoC as JSON by appending <code>/json</code> to the request path. This will return a JSON object
with three fields: <code>count</code> (the HoC value), <code>commits</code> (the number of commits) and
<code>head</code> (the commit ref of HEAD). Requesting <a
href="https://@domain/github/vbrandl/hoc/json">https://@domain/github/vbrandl/hoc/json</a> might return something along
the lines of
</p>
<pre>
&#123;
"head" : "05736ee3ba256ec9a7227c436aef2bf43db109ab",
"count": 7582
"head": "1f01c3b964b018fb0c0c2c5b572bf4ace2968546",
"count": 8324,
"commits": 223
&#125;
</pre>

View File

@ -1,12 +1,13 @@
@use super::base;
@use crate::statics::VersionInfo;
@(version_info: VersionInfo, repo_count: usize, domain: &str, path: &str, url: &str, hoc: u64, hoc_pretty: &str, head: &str, commit_url: &str)
@(version_info: VersionInfo, repo_count: usize, domain: &str, path: &str, url: &str, hoc: u64, hoc_pretty: &str, head: &str, commit_url: &str, commits: u64)
@:base("Hits-of-Code Badges", "Overview", {
<p>
The project <a href="@url">@url</a> has <strong>@hoc_pretty</strong> (exactly @hoc) hits of code at <a href="@commit_url">@head</a>.
The project <a href="@url">@url</a> has <strong>@hoc_pretty</strong> (exactly @hoc) hits of code at
<a href="@commit_url">@head</a>. The repository contains <strong>@commits</strong> commits.
</p>
<p>