Compare commits

...

130 Commits

Author SHA1 Message Date
9900518d62 Bump version (v0.19.0)
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2021-09-03 13:35:45 +02:00
d37f5ba32b Merge pull request #330 from vbrandl/chore/update-actix-web2
Update actix-web and tokio
2021-09-03 13:20:09 +02:00
bcb5650cc9 Update actix-web and tokio
All checks were successful
continuous-integration/drone/push Build is passing
2021-09-03 13:13:03 +02:00
dff8151938 Merge branch 'master' of github.com:vbrandl/hoc
All checks were successful
continuous-integration/drone/push Build is passing
2021-09-03 12:09:30 +02:00
9d71ef14fc Merge pull request #328 from vbrandl/dependabot/cargo/bytes-1.1.0
Bump bytes from 1.0.1 to 1.1.0
2021-09-03 12:09:24 +02:00
888e85b1f4 Mention sourcehut in readme 2021-09-03 12:04:38 +02:00
73e0bfad92 Bump bytes from 1.0.1 to 1.1.0
Bumps [bytes](https://github.com/tokio-rs/bytes) from 1.0.1 to 1.1.0.
- [Release notes](https://github.com/tokio-rs/bytes/releases)
- [Changelog](https://github.com/tokio-rs/bytes/blob/master/CHANGELOG.md)
- [Commits](https://github.com/tokio-rs/bytes/compare/v1.0.1...v1.1.0)

---
updated-dependencies:
- dependency-name: bytes
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-09-03 10:00:46 +00:00
ae4266044b Merge pull request #314 from vbrandl/dependabot/cargo/vergen-5.1.15
All checks were successful
continuous-integration/drone/push Build is passing
Bump vergen from 5.1.13 to 5.1.15
2021-09-03 12:00:45 +02:00
c5bae481da Merge pull request #317 from vbrandl/dependabot/cargo/git2-0.13.21
Bump git2 from 0.13.20 to 0.13.21
2021-09-03 12:00:34 +02:00
d71656295f Merge pull request #319 from vbrandl/dependabot/cargo/tracing-subscriber-0.2.20
Bump tracing-subscriber from 0.2.19 to 0.2.20
2021-09-03 12:00:23 +02:00
565a2e3129 Merge pull request #321 from vbrandl/dependabot/cargo/tracing-bunyan-formatter-0.2.5
Bump tracing-bunyan-formatter from 0.2.4 to 0.2.5
2021-09-03 12:00:12 +02:00
e2da36d2e9 Merge pull request #324 from vbrandl/dependabot/cargo/serde_json-1.0.67
Bump serde_json from 1.0.64 to 1.0.67
2021-09-03 12:00:03 +02:00
ad770f71ec Merge pull request #325 from vbrandl/dependabot/cargo/serde-1.0.130
Bump serde from 1.0.126 to 1.0.130
2021-09-03 11:59:46 +02:00
f6d47baefd Bump version (v0.18.0) 2021-09-03 11:45:10 +02:00
44d47b1d5f Implement badges for sourcehut 2021-09-03 11:44:22 +02:00
f87b6ee8f4 Bump serde from 1.0.126 to 1.0.130
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.126 to 1.0.130.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.126...v1.0.130)

---
updated-dependencies:
- dependency-name: serde
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-30 04:21:03 +00:00
6322e6e7e3 Bump serde_json from 1.0.64 to 1.0.67
Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.64 to 1.0.67.
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](https://github.com/serde-rs/json/compare/v1.0.64...v1.0.67)

---
updated-dependencies:
- dependency-name: serde_json
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-30 04:20:56 +00:00
39592effd2 Bump tracing-bunyan-formatter from 0.2.4 to 0.2.5
Bumps [tracing-bunyan-formatter](https://github.com/LukeMathWalker/tracing-bunyan-formatter) from 0.2.4 to 0.2.5.
- [Release notes](https://github.com/LukeMathWalker/tracing-bunyan-formatter/releases)
- [Commits](https://github.com/LukeMathWalker/tracing-bunyan-formatter/compare/v0.2.4...v0.2.5)

---
updated-dependencies:
- dependency-name: tracing-bunyan-formatter
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-23 04:23:35 +00:00
632638ddd8 Bump tracing-subscriber from 0.2.19 to 0.2.20
Bumps [tracing-subscriber](https://github.com/tokio-rs/tracing) from 0.2.19 to 0.2.20.
- [Release notes](https://github.com/tokio-rs/tracing/releases)
- [Commits](https://github.com/tokio-rs/tracing/compare/tracing-subscriber-0.2.19...tracing-subscriber-0.2.20)

---
updated-dependencies:
- dependency-name: tracing-subscriber
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-18 04:20:08 +00:00
c4e31f2f67 Bump git2 from 0.13.20 to 0.13.21
Bumps [git2](https://github.com/rust-lang/git2-rs) from 0.13.20 to 0.13.21.
- [Release notes](https://github.com/rust-lang/git2-rs/releases)
- [Commits](https://github.com/rust-lang/git2-rs/compare/0.13.20...0.13.21)

---
updated-dependencies:
- dependency-name: git2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-13 04:22:12 +00:00
46d7ae030e Bump vergen from 5.1.13 to 5.1.15
Bumps [vergen](https://github.com/rustyhorde/vergen) from 5.1.13 to 5.1.15.
- [Release notes](https://github.com/rustyhorde/vergen/releases)
- [Commits](https://github.com/rustyhorde/vergen/compare/5.1.13...5.1.15)

---
updated-dependencies:
- dependency-name: vergen
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-06 04:21:48 +00:00
3a57fcca9d Merge pull request #305 from vbrandl/dependabot/cargo/vergen-5.1.13
Bump vergen from 5.1.2 to 5.1.13
2021-07-16 09:03:52 +02:00
3051bdc0c7 Bump vergen from 5.1.2 to 5.1.13
Bumps [vergen](https://github.com/rustyhorde/vergen) from 5.1.2 to 5.1.13.
- [Release notes](https://github.com/rustyhorde/vergen/releases)
- [Commits](https://github.com/rustyhorde/vergen/compare/5.1.2...5.1.13)

---
updated-dependencies:
- dependency-name: vergen
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-07-13 04:20:01 +00:00
e267a4fc8a chore: Bump version (v0.17.4)
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/tag Build is failing
2021-06-29 19:47:08 +02:00
441ab76ca6 Merge pull request #300 from vbrandl/revert-299-dependabot/cargo/vergen-5.1.10
Revert "Bump vergen from 5.1.2 to 5.1.10"
2021-06-29 19:46:36 +02:00
155d79a019 Revert "Bump vergen from 5.1.2 to 5.1.10" 2021-06-29 19:46:21 +02:00
1fe39fbd3c fix(docker): Start with lib project for caching
Some checks failed
continuous-integration/drone/tag Build is passing
continuous-integration/drone/push Build is failing
2021-06-29 19:23:34 +02:00
1fae322993 fix(docker): Start with lib project for caching
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/tag Build is failing
2021-06-29 19:14:51 +02:00
13c193d04a chore: Bump version (v0.17.3)
Some checks failed
continuous-integration/drone/push Build is failing
2021-06-29 19:06:35 +02:00
701299ab5b Merge pull request #299 from vbrandl/dependabot/cargo/vergen-5.1.10
Bump vergen from 5.1.2 to 5.1.10
2021-06-29 19:01:27 +02:00
2277931d3c Merge pull request #291 from vbrandl/dependabot/cargo/git2-0.13.20
Bump git2 from 0.13.18 to 0.13.20
2021-06-29 18:57:39 +02:00
6c59acc0ab Bump vergen from 5.1.2 to 5.1.10
Bumps [vergen](https://github.com/rustyhorde/vergen) from 5.1.2 to 5.1.10.
- [Release notes](https://github.com/rustyhorde/vergen/releases)
- [Commits](https://github.com/rustyhorde/vergen/compare/5.1.2...5.1.10)

---
updated-dependencies:
- dependency-name: vergen
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-29 16:56:16 +00:00
79d947fb36 Merge pull request #297 from vbrandl/dependabot/cargo/tracing-subscriber-0.2.19
Bump tracing-subscriber from 0.2.18 to 0.2.19
2021-06-29 18:55:39 +02:00
a1133259c2 Merge pull request #298 from vbrandl/dependabot/cargo/ructe-0.13.4
Bump ructe from 0.13.2 to 0.13.4
2021-06-29 18:55:05 +02:00
9eb47bd94b Bump ructe from 0.13.2 to 0.13.4
Bumps [ructe](https://github.com/kaj/ructe) from 0.13.2 to 0.13.4.
- [Release notes](https://github.com/kaj/ructe/releases)
- [Changelog](https://github.com/kaj/ructe/blob/master/CHANGELOG.md)
- [Commits](https://github.com/kaj/ructe/compare/v0.13.2...v0.13.4)

---
updated-dependencies:
- dependency-name: ructe
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-28 04:24:35 +00:00
8f6c52a6f5 Bump tracing-subscriber from 0.2.18 to 0.2.19
Bumps [tracing-subscriber](https://github.com/tokio-rs/tracing) from 0.2.18 to 0.2.19.
- [Release notes](https://github.com/tokio-rs/tracing/releases)
- [Commits](https://github.com/tokio-rs/tracing/compare/tracing-subscriber-0.2.18...tracing-subscriber-0.2.19)

---
updated-dependencies:
- dependency-name: tracing-subscriber
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-28 04:24:28 +00:00
b50112c7c0 Bump git2 from 0.13.18 to 0.13.20
Bumps [git2](https://github.com/rust-lang/git2-rs) from 0.13.18 to 0.13.20.
- [Release notes](https://github.com/rust-lang/git2-rs/releases)
- [Commits](https://github.com/rust-lang/git2-rs/compare/0.13.18...0.13.20)

---
updated-dependencies:
- dependency-name: git2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-11 04:12:07 +00:00
62c80a81de Change link to gpg key 2021-06-10 12:10:00 +02:00
04f1437d0c chores(cargo): Bump version (0.17.2) 2021-05-27 13:18:31 +02:00
e706176d84 Merge pull request #282 from vbrandl/dependabot/cargo/serde-1.0.126
Bump serde from 1.0.125 to 1.0.126
2021-05-27 12:55:05 +02:00
a2a0047e03 Merge pull request #283 from vbrandl/dependabot/cargo/futures-0.3.15
Bump futures from 0.3.14 to 0.3.15
2021-05-27 12:54:37 +02:00
be7320e24e Merge pull request #281 from vbrandl/dependabot/cargo/tracing-bunyan-formatter-0.2.4
Bump tracing-bunyan-formatter from 0.2.0 to 0.2.4
2021-05-27 12:54:27 +02:00
55f937aac2 Bump tracing-bunyan-formatter from 0.2.0 to 0.2.4
Bumps [tracing-bunyan-formatter](https://github.com/LukeMathWalker/tracing-bunyan-formatter) from 0.2.0 to 0.2.4.
- [Release notes](https://github.com/LukeMathWalker/tracing-bunyan-formatter/releases)
- [Commits](https://github.com/LukeMathWalker/tracing-bunyan-formatter/compare/v0.2.0...v0.2.4)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-27 10:48:45 +00:00
d929a559b6 Bump futures from 0.3.14 to 0.3.15
Bumps [futures](https://github.com/rust-lang/futures-rs) from 0.3.14 to 0.3.15.
- [Release notes](https://github.com/rust-lang/futures-rs/releases)
- [Changelog](https://github.com/rust-lang/futures-rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/futures-rs/compare/0.3.14...0.3.15)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-27 10:48:26 +00:00
5e7374deea Bump serde from 1.0.125 to 1.0.126
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.125 to 1.0.126.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.125...v1.0.126)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-27 10:48:22 +00:00
0821559471 Remove reviewer and ignored dependencies for dependabot 2021-05-27 12:47:10 +02:00
a9ede0b2c7 Merge pull request #273 from vbrandl/dependabot/cargo/openssl-probe-0.1.4
Bump openssl-probe from 0.1.2 to 0.1.4
2021-05-27 12:45:28 +02:00
be48ebd2d9 Fix clippy lint 2021-05-27 12:39:45 +02:00
c80bef7cbd Merge pull request #271 from vbrandl/dependabot/cargo/tracing-subscriber-0.2.18
Bump tracing-subscriber from 0.2.17 to 0.2.18
2021-05-27 12:20:35 +02:00
c9b67eb6e6 Merge pull request #270 from vbrandl/dependabot/cargo/tracing-0.1.26
Bump tracing from 0.1.25 to 0.1.26
2021-05-27 12:19:55 +02:00
1ab4cb6c71 Merge pull request #268 from vbrandl/dependabot/add-v2-config-file
Upgrade to GitHub-native Dependabot
2021-05-27 12:18:35 +02:00
9785b38ce0 Bump openssl-probe from 0.1.2 to 0.1.4
Bumps [openssl-probe](https://github.com/alexcrichton/openssl-probe) from 0.1.2 to 0.1.4.
- [Release notes](https://github.com/alexcrichton/openssl-probe/releases)
- [Commits](https://github.com/alexcrichton/openssl-probe/compare/0.1.2...0.1.4)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-05-12 04:20:25 +00:00
492e17b997 Bump tracing-subscriber from 0.2.17 to 0.2.18
Bumps [tracing-subscriber](https://github.com/tokio-rs/tracing) from 0.2.17 to 0.2.18.
- [Release notes](https://github.com/tokio-rs/tracing/releases)
- [Commits](https://github.com/tokio-rs/tracing/compare/tracing-subscriber-0.2.17...tracing-subscriber-0.2.18)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-05-03 04:19:29 +00:00
43586e534b Bump tracing from 0.1.25 to 0.1.26
Bumps [tracing](https://github.com/tokio-rs/tracing) from 0.1.25 to 0.1.26.
- [Release notes](https://github.com/tokio-rs/tracing/releases)
- [Commits](https://github.com/tokio-rs/tracing/compare/tracing-0.1.25...tracing-0.1.26)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-05-03 04:19:05 +00:00
70bca967f3 Upgrade to GitHub-native Dependabot 2021-04-29 15:09:17 +00:00
61013e43ab Merge pull request #264 from vbrandl/dependabot/cargo/git2-0.13.18
Some checks failed
continuous-integration/drone/push Build is failing
Bump git2 from 0.13.17 to 0.13.18
2021-04-23 12:52:03 +02:00
0c100e76ad Merge pull request #263 from vbrandl/dependabot/cargo/vergen-5.1.2
Bump vergen from 5.1.1 to 5.1.2
2021-04-23 12:51:30 +02:00
000c7457f5 Bump git2 from 0.13.17 to 0.13.18
Bumps [git2](https://github.com/rust-lang/git2-rs) from 0.13.17 to 0.13.18.
- [Release notes](https://github.com/rust-lang/git2-rs/releases)
- [Commits](https://github.com/rust-lang/git2-rs/compare/0.13.17...0.13.18)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-04-20 04:19:33 +00:00
70361e8b70 Bump vergen from 5.1.1 to 5.1.2
Bumps [vergen](https://github.com/rustyhorde/vergen) from 5.1.1 to 5.1.2.
- [Release notes](https://github.com/rustyhorde/vergen/releases)
- [Commits](https://github.com/rustyhorde/vergen/compare/5.1.1...5.1.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-04-20 04:19:12 +00:00
4237f6cc06 Merge pull request #262 from vbrandl/disable-gitlab-ci
Some checks failed
continuous-integration/drone/push Build is failing
Remove `.gitlab-ci.yml`
2021-04-19 09:02:03 +02:00
04a90469fe Remove .gitlab-ci.yml
All checks were successful
continuous-integration/drone/push Build is passing
2021-04-19 09:01:06 +02:00
117a052aa5 Merge pull request #259 from vbrandl/dependabot/cargo/futures-0.3.14
Bump futures from 0.3.13 to 0.3.14
2021-04-19 08:59:59 +02:00
b2bc7fc217 Bump futures from 0.3.13 to 0.3.14
Bumps [futures](https://github.com/rust-lang/futures-rs) from 0.3.13 to 0.3.14.
- [Release notes](https://github.com/rust-lang/futures-rs/releases)
- [Changelog](https://github.com/rust-lang/futures-rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/futures-rs/compare/0.3.13...0.3.14)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-04-13 17:58:36 +00:00
cd2624ae11 Merge pull request #256 from vbrandl/dependabot/cargo/tracing-bunyan-formatter-0.2.0
Bump tracing-bunyan-formatter from 0.1.7 to 0.2.0
2021-04-13 19:56:58 +02:00
fa9601bb9a Merge pull request #258 from vbrandl/dependabot/cargo/vergen-5.1.1
Bump vergen from 5.1.0 to 5.1.1
2021-04-13 19:55:14 +02:00
ae9d31b82c Bump vergen from 5.1.0 to 5.1.1
Bumps [vergen](https://github.com/rustyhorde/vergen) from 5.1.0 to 5.1.1.
- [Release notes](https://github.com/rustyhorde/vergen/releases)
- [Commits](https://github.com/rustyhorde/vergen/compare/5.1.0...5.1.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-04-08 04:18:02 +00:00
2afe5fc172 Bump tracing-bunyan-formatter from 0.1.7 to 0.2.0
Bumps [tracing-bunyan-formatter](https://github.com/LukeMathWalker/tracing-bunyan-formatter) from 0.1.7 to 0.2.0.
- [Release notes](https://github.com/LukeMathWalker/tracing-bunyan-formatter/releases)
- [Commits](https://github.com/LukeMathWalker/tracing-bunyan-formatter/commits/v0.2.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-03-30 04:19:49 +00:00
ea7f074661 Merge pull request #244 from vbrandl/dependabot/cargo/ructe-0.13.2
Bump ructe from 0.13.0 to 0.13.2
2021-03-29 14:45:53 +02:00
d5e3cad299 Bump ructe from 0.13.0 to 0.13.2
Bumps [ructe](https://github.com/kaj/ructe) from 0.13.0 to 0.13.2.
- [Release notes](https://github.com/kaj/ructe/releases)
- [Changelog](https://github.com/kaj/ructe/blob/master/CHANGELOG.md)
- [Commits](https://github.com/kaj/ructe/compare/v0.13.0...v0.13.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-03-29 10:56:11 +00:00
6570daef02 Remove macos from test matrix
Some checks failed
continuous-integration/drone/push Build is failing
2021-03-29 12:55:49 +02:00
6ac389e3ee Merge pull request #239 from vbrandl/dependabot/cargo/serde_json-1.0.64
Bump serde_json from 1.0.63 to 1.0.64
2021-03-29 12:55:14 +02:00
36196975ac Merge pull request #251 from vbrandl/dependabot/cargo/vergen-5.1.0
Bump vergen from 4.1.0 to 5.1.0
2021-03-29 12:54:28 +02:00
1dd83829b2 Bump serde_json from 1.0.63 to 1.0.64
Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.63 to 1.0.64.
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](https://github.com/serde-rs/json/compare/v1.0.63...v1.0.64)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-03-29 10:48:28 +00:00
1b0817bc25 Bump vergen from 4.1.0 to 5.1.0
All checks were successful
continuous-integration/drone/push Build is passing
Bumps [vergen](https://github.com/rustyhorde/vergen) from 4.1.0 to 5.1.0.
- [Release notes](https://github.com/rustyhorde/vergen/releases)
- [Commits](https://github.com/rustyhorde/vergen/compare/4.1.0...5.1.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-03-29 12:45:49 +02:00
f57dc8e890 Fix vergen 2021-03-29 12:45:49 +02:00
bdda6292d2 Bump vergen from 4.1.0 to 5.1.0
Bumps [vergen](https://github.com/rustyhorde/vergen) from 4.1.0 to 5.1.0.
- [Release notes](https://github.com/rustyhorde/vergen/releases)
- [Commits](https://github.com/rustyhorde/vergen/compare/4.1.0...5.1.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-03-29 12:45:49 +02:00
a2826c9922 Remove windows from test matrix
Some checks failed
continuous-integration/drone/push Build is failing
2021-03-29 12:44:55 +02:00
3b2a368df0 Merge pull request #247 from vbrandl/dependabot/cargo/config-0.11.0
Bump config from 0.10.1 to 0.11.0
2021-03-29 12:23:55 +02:00
8b7444bd7c Merge pull request #253 from vbrandl/feature/refactor2
Feature/refactor2
2021-03-29 12:12:58 +02:00
9d719e7d85 Merge pull request #252 from vbrandl/master
Refactor for testability
2021-03-29 12:12:09 +02:00
584379e047 Merge pull request #250 from vbrandl/dependabot/cargo/serde-1.0.125
Bump serde from 1.0.123 to 1.0.125
2021-03-29 12:10:50 +02:00
951124e038 Bump serde from 1.0.123 to 1.0.125
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.123 to 1.0.125.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.123...v1.0.125)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-03-23 04:24:16 +00:00
e574f4bdd0 Run tests also on windows
All checks were successful
continuous-integration/drone/push Build is passing
2021-03-22 13:41:50 +01:00
5c8e3fa35d Add badge test
All checks were successful
continuous-integration/drone/push Build is passing
2021-03-22 13:34:26 +01:00
4c0df1fa19 Add config so tests will work 2021-03-22 13:34:18 +01:00
f6b46a1e90 Add config so tests will work
All checks were successful
continuous-integration/drone/push Build is passing
2021-03-22 13:33:56 +01:00
5eb16ac38e Remove unused code
All checks were successful
continuous-integration/drone/push Build is passing
2021-03-22 12:52:24 +01:00
3486d44bc5 Restructure for testability and implement first tests 2021-03-22 12:46:10 +01:00
1311e724ce Bump version (v0.17.1)
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2021-03-22 08:38:45 +01:00
5da9e74992 Merge pull request #248 from strdr4605/patch-1
fix: remove redundant param in md url
2021-03-22 08:37:53 +01:00
8dadc0ddea fix: remove redundant param in md url 2021-03-22 00:16:31 +02:00
cba235eadf Bump config from 0.10.1 to 0.11.0
Bumps [config](https://github.com/mehcode/config-rs) from 0.10.1 to 0.11.0.
- [Release notes](https://github.com/mehcode/config-rs/releases)
- [Changelog](https://github.com/mehcode/config-rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mehcode/config-rs/commits/0.11.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-03-18 04:18:27 +00:00
5284249acf Bump version (v0.17.0)
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2021-02-26 16:38:26 +01:00
d28f56dac0 Updgrade serde_derive and futures
All checks were successful
continuous-integration/drone/push Build is passing
2021-02-26 16:35:14 +01:00
ab02a45bf6 Update dependencies
All checks were successful
continuous-integration/drone/push Build is passing
2021-02-26 16:28:04 +01:00
837c1c160b Merge pull request #234 from vbrandl/dependabot/cargo/vergen-4.1.0
Bump vergen from 3.2.0 to 4.1.0
2021-02-26 16:17:56 +01:00
3d26823425 Fix breaking changes in vergen
All checks were successful
continuous-integration/drone/push Build is passing
2021-02-26 16:12:58 +01:00
d9553871fa Deactivate unused features of vergen 2021-02-26 16:12:47 +01:00
d2bc9c2149 Bump vergen from 3.2.0 to 4.1.0
Bumps [vergen](https://github.com/rustyhorde/vergen) from 3.2.0 to 4.1.0.
- [Release notes](https://github.com/rustyhorde/vergen/releases)
- [Commits](https://github.com/rustyhorde/vergen/compare/v3.2.0...4.1.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-02-26 15:06:33 +00:00
b0b97653a9 Rollback reqwest to 0.10.10
All checks were successful
continuous-integration/drone/push Build is passing
2021-02-26 16:04:58 +01:00
0b1bc60790 Merge pull request #238 from vbrandl/revert-236-dependabot/cargo/actix-rt-2.1.0
Revert "Bump actix-rt from 1.1.1 to 2.1.0"
2021-02-26 15:51:46 +01:00
e93588a6d9 Revert "Bump actix-rt from 1.1.1 to 2.1.0" 2021-02-26 15:51:35 +01:00
cd5046a276 Merge pull request #236 from vbrandl/dependabot/cargo/actix-rt-2.1.0
Bump actix-rt from 1.1.1 to 2.1.0
2021-02-26 15:41:54 +01:00
919348d49d Merge pull request #229 from vbrandl/dependabot/cargo/tracing-futures-0.2.5
Bump tracing-futures from 0.2.4 to 0.2.5
2021-02-26 15:31:26 +01:00
8378b0b51b Bump tracing-futures from 0.2.4 to 0.2.5
Bumps [tracing-futures](https://github.com/tokio-rs/tracing) from 0.2.4 to 0.2.5.
- [Release notes](https://github.com/tokio-rs/tracing/releases)
- [Commits](https://github.com/tokio-rs/tracing/compare/tracing-futures-0.2.4...tracing-futures-0.2.5)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-02-26 14:31:17 +00:00
0394ae52e9 Merge pull request #235 from vbrandl/dependabot/cargo/tracing-0.1.25
Bump tracing from 0.1.23 to 0.1.25
2021-02-26 15:29:55 +01:00
fb34f6bf2f Bump tracing from 0.1.23 to 0.1.25
Bumps [tracing](https://github.com/tokio-rs/tracing) from 0.1.23 to 0.1.25.
- [Release notes](https://github.com/tokio-rs/tracing/releases)
- [Commits](https://github.com/tokio-rs/tracing/compare/tracing-0.1.23...tracing-0.1.25)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-02-26 14:29:17 +00:00
36622ad322 Merge pull request #232 from vbrandl/dependabot/cargo/tracing-subscriber-0.2.16
Bump tracing-subscriber from 0.2.15 to 0.2.16
2021-02-26 15:28:11 +01:00
89bb27e137 Merge pull request #237 from vbrandl/dependabot/cargo/serde_json-1.0.63
Bump serde_json from 1.0.62 to 1.0.63
2021-02-26 15:27:53 +01:00
7d4385764c Bump serde_json from 1.0.62 to 1.0.63
Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.62 to 1.0.63.
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](https://github.com/serde-rs/json/compare/v1.0.62...v1.0.63)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-02-26 04:19:16 +00:00
5df97f0e64 Bump actix-rt from 1.1.1 to 2.1.0
Bumps [actix-rt](https://github.com/actix/actix-net) from 1.1.1 to 2.1.0.
- [Release notes](https://github.com/actix/actix-net/releases)
- [Commits](https://github.com/actix/actix-net/compare/rt-1.1.1...rt-v2.1.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-02-26 04:18:49 +00:00
a3d98a326e Bump tracing-subscriber from 0.2.15 to 0.2.16
Bumps [tracing-subscriber](https://github.com/tokio-rs/tracing) from 0.2.15 to 0.2.16.
- [Release notes](https://github.com/tokio-rs/tracing/releases)
- [Commits](https://github.com/tokio-rs/tracing/compare/tracing-subscriber-0.2.15...tracing-subscriber-0.2.16)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-02-22 04:14:56 +00:00
76bf5f2f98 Merge pull request #221 from vbrandl/dependabot/cargo/serde-1.0.123
Bump serde from 1.0.118 to 1.0.123
2021-02-11 11:17:34 +01:00
e827d2ef39 Bump serde from 1.0.118 to 1.0.123
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.118 to 1.0.123.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.118...v1.0.123)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-02-11 10:12:45 +00:00
65576140ce Merge pull request #212 from vbrandl/dependabot/cargo/reqwest-0.11.0
Bump reqwest from 0.10.10 to 0.11.0
2021-02-11 11:11:14 +01:00
cea54cf2f3 Bump reqwest from 0.10.10 to 0.11.0
Bumps [reqwest](https://github.com/seanmonstar/reqwest) from 0.10.10 to 0.11.0.
- [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.10.10...v0.11.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-02-11 10:10:09 +00:00
8c28c68c17 Merge pull request #215 from vbrandl/dependabot/cargo/bytes-1.0.1
Bump bytes from 1.0.0 to 1.0.1
2021-02-11 11:09:27 +01:00
b86a080ead Merge pull request #223 from vbrandl/dependabot/cargo/tracing-0.1.23
Bump tracing from 0.1.22 to 0.1.23
2021-02-11 11:08:42 +01:00
1b0c959a8d Bump bytes from 1.0.0 to 1.0.1
Bumps [bytes](https://github.com/tokio-rs/bytes) from 1.0.0 to 1.0.1.
- [Release notes](https://github.com/tokio-rs/bytes/releases)
- [Changelog](https://github.com/tokio-rs/bytes/blob/master/CHANGELOG.md)
- [Commits](https://github.com/tokio-rs/bytes/compare/v1.0.0...v1.0.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-02-10 17:07:29 +00:00
806baf7460 Bump tracing from 0.1.22 to 0.1.23
Bumps [tracing](https://github.com/tokio-rs/tracing) from 0.1.22 to 0.1.23.
- [Release notes](https://github.com/tokio-rs/tracing/releases)
- [Commits](https://github.com/tokio-rs/tracing/compare/tracing-0.1.22...tracing-0.1.23)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-02-10 17:06:26 +00:00
080f7379ea Merge pull request #216 from vbrandl/dependabot/cargo/tempfile-3.2.0
Bump tempfile from 3.1.0 to 3.2.0
2021-02-10 18:06:14 +01:00
7409de5dba Merge pull request #219 from vbrandl/dependabot/cargo/git2-0.13.17
Bump git2 from 0.13.14 to 0.13.17
2021-02-10 18:05:52 +01:00
07f4ef518a Merge pull request #225 from vbrandl/dependabot/cargo/serde_json-1.0.62
Bump serde_json from 1.0.61 to 1.0.62
2021-02-10 18:04:58 +01:00
820ebdd899 Bump tempfile from 3.1.0 to 3.2.0
Bumps [tempfile](https://github.com/Stebalien/tempfile) from 3.1.0 to 3.2.0.
- [Release notes](https://github.com/Stebalien/tempfile/releases)
- [Changelog](https://github.com/Stebalien/tempfile/blob/master/NEWS)
- [Commits](https://github.com/Stebalien/tempfile/commits)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-02-10 17:04:57 +00:00
527d793914 Merge pull request #226 from vbrandl/dependabot/cargo/vergen-3.2.0
Bump vergen from 3.1.0 to 3.2.0
2021-02-10 18:03:26 +01:00
7df6c3fc75 Bump vergen from 3.1.0 to 3.2.0
Bumps [vergen](https://github.com/rustyhorde/vergen) from 3.1.0 to 3.2.0.
- [Release notes](https://github.com/rustyhorde/vergen/releases)
- [Commits](https://github.com/rustyhorde/vergen/compare/v3.1.0...v3.2.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-02-10 04:16:04 +00:00
17e1af1dd7 Bump serde_json from 1.0.61 to 1.0.62
Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.61 to 1.0.62.
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](https://github.com/serde-rs/json/compare/v1.0.61...v1.0.62)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-02-08 04:17:19 +00:00
baade8fbc2 Bump git2 from 0.13.14 to 0.13.17
Bumps [git2](https://github.com/rust-lang/git2-rs) from 0.13.14 to 0.13.17.
- [Release notes](https://github.com/rust-lang/git2-rs/releases)
- [Commits](https://github.com/rust-lang/git2-rs/compare/0.13.14...0.13.17)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-01-25 04:16:33 +00:00
cfc07664fc Merge pull request #211 from vbrandl/dependabot/cargo/serde_json-1.0.61
Bump serde_json from 1.0.60 to 1.0.61
2021-01-06 18:11:44 +01:00
52938c9106 Bump serde_json from 1.0.60 to 1.0.61
Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.60 to 1.0.61.
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](https://github.com/serde-rs/json/compare/v1.0.60...v1.0.61)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-12-29 04:18:23 +00:00
26 changed files with 1487 additions and 1658 deletions

10
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: cargo
directory: "/"
schedule:
interval: daily
time: "04:00"
open-pull-requests-limit: 10
assignees:
- vbrandl

View File

@ -69,7 +69,8 @@ jobs:
strategy:
matrix:
# 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:
- name: Checkout sources

1
.gitignore vendored
View File

@ -4,5 +4,4 @@ repos
cache
hoc.log
result
hoc.toml
.env

View File

@ -1,53 +0,0 @@
image: docker:19.03
services:
- docker:19.03-dind
stages:
- build
- release
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
before_script:
- export CONTAINER_TAG_IMAGE="$CI_REGISTRY_IMAGE:${CI_COMMIT_TAG:1}"
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
build:
stage: build
script:
- docker pull $CONTAINER_TEST_IMAGE || true
- docker pull $CONTAINER_RELEASE_IMAGE || true
- docker pull $CONTAINER_TAG_IMAGE || true
- docker pull $CONTAINER_BUILDER_IMAGE || true
- docker build --pull -t $CONTAINER_BUILDER_IMAGE --target builder .
- docker build --pull -t $CONTAINER_TEST_IMAGE .
- docker push $CONTAINER_BUILDER_IMAGE
- docker push $CONTAINER_TEST_IMAGE
release-image:
stage: release
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker tag $CONTAINER_TEST_IMAGE $CONTAINER_RELEASE_IMAGE
- docker push $CONTAINER_RELEASE_IMAGE
only:
- master
release-tag:
stage: release
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker tag $CONTAINER_TEST_IMAGE $CONTAINER_TAG_IMAGE
- docker push $CONTAINER_TAG_IMAGE
only:
- /^v\d+\.\d+\.\d+/
except:
- branch

1681
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,34 +1,46 @@
[package]
name = "hoc"
version = "0.16.0"
version = "0.19.0"
authors = ["Valentin Brandl <vbrandl@riseup.net>"]
edition = "2018"
build = "build.rs"
[lib]
path = "src/lib.rs"
[[bin]]
path = "src/main.rs"
name = "hoc"
[dependencies]
actix-rt = "1.1.1"
actix-web = "3.3.2"
actix-rt = "2.2.0"
actix-web = "4.0.0-beta.8"
badge = "0.3.0"
bytes = "1.0.0"
config = { version = "0.10.1", features = ["toml"] }
bytes = "1.1.0"
config = { version = "0.11.0", features = ["toml"] }
dotenv = "0.15.0"
futures = "0.3.8"
git2 = "0.13.14"
futures = "0.3.17"
git2 = "0.13.21"
lazy_static = "1.4.0"
number_prefix = "0.4.0"
openssl-probe = "0.1.2"
reqwest = "0.10.10"
serde = "1.0.118"
serde_derive = "1.0.103"
serde_json = "1.0.60"
tracing = "0.1.22"
tracing-actix-web = "0.2.1"
tracing-futures = "0.2.4"
tracing-subscriber = "0.2.15"
openssl-probe = "0.1.4"
reqwest = "0.11.4"
serde = "1.0.130"
serde_derive = "1.0.123"
serde_json = "1.0.67"
tracing = "0.1.26"
tracing-actix-web = "0.4.0-beta.11"
tracing-bunyan-formatter = "0.2.5"
tracing-futures = "0.2.5"
tracing-log = "0.1.2"
tracing-subscriber = { version = "0.2.20", features = ["registry", "env-filter"] }
[build-dependencies]
ructe = "0.13.0"
vergen = "3.1.0"
ructe = "0.13.4"
vergen = { version = "5.1.15", default-features = false, features = ["git"] }
[dev-dependencies]
tempfile = "3.1.0"
awc = "3.0.0-beta.7"
ructe = "0.13.4"
tempfile = "3.2.0"
tokio = "1.11.0"

View File

@ -1,7 +1,8 @@
FROM ekidd/rust-musl-builder:stable as builder
# create new cargo project
RUN USER=rust cargo init --bin
RUN USER=rust cargo init --lib
RUN echo 'fn main() { println!("Hello, world!"); }' >> src/main.rs
# copy build config
COPY --chown=rust ./Cargo.lock ./Cargo.lock
COPY ./Cargo.toml ./Cargo.toml

View File

@ -19,8 +19,8 @@ The API is as simple as
https://<host>/<service>/<user>/<repo>
```
where `<service>` is one of `gitub`, `gitlab` or `bitbucket`. The HoC data can also be received as JSON by appending
`/json` to the reuqest path:
where `<service>` is one of `gitub`, `gitlab`, `bitbucket` or `sourcehut`. The HoC data can also be received as JSON by
appending `/json` to the reuqest path:
```
https://<host>/<service>/<user>/<repo>/json

View File

@ -2,11 +2,12 @@ extern crate ructe;
extern crate vergen;
use ructe::Ructe;
use vergen::{generate_cargo_keys, ConstantsFlags};
use vergen::{vergen, Config, ShaKind};
fn main() {
let flags = ConstantsFlags::SHA_SHORT;
generate_cargo_keys(flags).expect("Unable to generate the cargo keys!");
let mut config = Config::default();
*config.git_mut().sha_kind_mut() = ShaKind::Short;
vergen(config).expect("Unable to generate static repo info");
Ructe::from_env()
.expect("ructe")
.compile_templates("templates")

15
hoc.toml Normal file
View 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"

View File

@ -101,9 +101,9 @@ impl<'a> CacheState<'a> {
entries.insert(
branch.into(),
CacheEntry {
commits,
head,
count,
commits,
},
);
Cache { entries }

View File

@ -17,16 +17,13 @@ pub struct Settings {
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 {
#[deprecated]
pub fn new() -> Result<Self, ConfigError> {
Self::load()
}
pub fn load() -> Result<Self, ConfigError> {
let mut config = Config::new();
config
.merge(File::with_name("hoc.toml").required(false))?

View File

@ -1,9 +1,6 @@
use crate::{
statics::{REPO_COUNT, VERSION_INFO},
templates,
};
use actix_web::{HttpResponse, ResponseError};
use std::{fmt, sync::atomic::Ordering};
use crate::{statics::VERSION_INFO, templates};
use actix_web::{http::StatusCode, HttpResponse, ResponseError};
use std::fmt;
pub(crate) type Result<T> = std::result::Result<T, Error>;
@ -35,21 +32,22 @@ impl fmt::Display 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 {
let mut buf = Vec::new();
match self {
Error::BranchNotFound => {
templates::p404_no_master(
&mut buf,
VERSION_INFO,
REPO_COUNT.load(Ordering::Relaxed),
)
.unwrap();
templates::p404_no_master(&mut buf, VERSION_INFO, 0).unwrap();
HttpResponse::NotFound().content_type("text/html").body(buf)
}
_ => {
templates::p500(&mut buf, VERSION_INFO, REPO_COUNT.load(Ordering::Relaxed))
.unwrap();
templates::p500(&mut buf, VERSION_INFO, 0).unwrap();
HttpResponse::InternalServerError()
.content_type("text/html")
.body(buf)

532
src/lib.rs Normal file
View File

@ -0,0 +1,532 @@
#![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, Sourcehut},
statics::{CLIENT, CSS, FAVICON, VERSION_INFO},
template::RepoInfo,
};
use actix_web::{
dev::Server,
http::header::{CacheControl, CacheDirective, Expires, LOCATION},
middleware::{self, 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,
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()
.insert_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")
.insert_header(Expires(expiration.into()))
.insert_header(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(tracing_actix_web::TracingLogger::default())
.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("/sourcehut/{user}/{repo}").to(calculate_hoc::<Sourcehut>))
.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("/sourcehut/{user}/{repo}/delete")
.route(web::post().to(delete_repo_and_cache::<Sourcehut>)),
)
.service(web::resource("/github/{user}/{repo}/json").to(json_hoc::<GitHub>))
.service(web::resource("/gitlab/{user}/{repo}/json").to(json_hoc::<Gitlab>))
.service(web::resource("/bitbucket/{user}/{repo}/json").to(json_hoc::<Bitbucket>))
.service(web::resource("/sourcehut/{user}/{repo}/json").to(json_hoc::<Sourcehut>))
.service(web::resource("/view/github/{user}/{repo}").to(overview::<GitHub>))
.service(web::resource("/view/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>))
.service(web::resource("/sourcehut/{user}/{repo}/view").to(overview::<Sourcehut>))
.default_service(web::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
}

View File

@ -1,495 +1,26 @@
#![type_length_limit = "2257138"]
use hoc::{config::Settings, telemetry};
#[macro_use]
extern crate actix_web;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate tracing;
use std::net::TcpListener;
mod cache;
mod config;
mod count;
mod error;
mod service;
mod statics;
mod template;
fn init() {
dotenv::dotenv().ok();
openssl_probe::init_ssl_cert_env_vars();
#[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
telemetry::init_subscriber(telemetry::get_subscriber("hoc", "info"))
}
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
config::init();
let span = info_span!("hoc", version = env!("CARGO_PKG_VERSION"));
let _ = span.enter();
start_server().instrument(span).await
init();
// TODO: error handling
let settings = Settings::load().expect("Cannot load config");
let address = format!("{}:{}", settings.host, settings.port);
// TODO: error handling
let listener = TcpListener::bind(address)?;
hoc::run(listener, settings)
.await
.expect("Server error")
.await
}

View File

@ -12,6 +12,8 @@ pub(crate) enum FormService {
Gitlab,
#[serde(rename = "bitbucket")]
Bitbucket,
#[serde(rename = "sourcehut")]
Sourcehut,
}
impl FormService {
@ -20,6 +22,7 @@ impl FormService {
FormService::GitHub => "github.com",
FormService::Gitlab => "gitlab.com",
FormService::Bitbucket => "bitbucket.org",
FormService::Sourcehut => "git.sr.ht",
}
}
@ -28,6 +31,7 @@ impl FormService {
FormService::GitHub => "github",
FormService::Gitlab => "gitlab",
FormService::Bitbucket => "bitbucket",
FormService::Sourcehut => "sourcehut",
}
}
}
@ -73,3 +77,17 @@ impl Service for Bitbucket {
format!("https://{}/{}/commits/{}", Self::domain(), repo, commit_ref)
}
}
pub(crate) struct Sourcehut;
impl Service for Sourcehut {
fn domain() -> &'static str {
"git.sr.ht"
}
fn url_path() -> &'static str {
"sourcehut"
}
fn commit_url(repo: &str, commit_ref: &str) -> String {
format!("https://{}/{}/commit/{}", Self::domain(), repo, commit_ref)
}
}

View File

@ -1,13 +1,10 @@
use crate::{config::Settings, count::count_repositories};
use std::sync::atomic::AtomicUsize;
pub struct VersionInfo<'a> {
pub commit: &'a str,
pub version: &'a str,
}
pub(crate) const VERSION_INFO: VersionInfo = VersionInfo {
commit: env!("VERGEN_SHA_SHORT"),
commit: env!("VERGEN_GIT_SHA_SHORT"),
version: env!("CARGO_PKG_VERSION"),
};
pub(crate) const CSS: &str = include_str!("../static/tacit-css.min.css");
@ -15,7 +12,4 @@ 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 OPT: Settings = Settings::new().unwrap();
pub(crate) static ref REPO_COUNT: AtomicUsize =
AtomicUsize::new(count_repositories(&OPT.repodir).unwrap());
}

21
src/telemetry.rs Normal file
View File

@ -0,0 +1,21 @@
use tracing::{subscriber::set_global_default, Subscriber};
use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer};
use tracing_log::LogTracer;
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry};
pub fn get_subscriber(name: &str, env_filter: &str) -> impl Subscriber + Send + Sync {
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);
Registry::default()
.with(env_filter)
.with(JsonStorageLayer)
.with(formatting_layer)
}
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");
}

View File

@ -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;
}

View File

@ -20,7 +20,7 @@ gives an overview about the amount of work put into a codebase.
<p>
There is a <a href="https://github.com/yegor256/hoc/">command-line tool</a> to calculate the HoC of a repository, but
some people might want a nice badge to put in their README, that's why I implemented this API. Currently the API can be
used for GitHub, GitLab and Bitbucket repositories. Just put the following code in your README:
used for GitHub, GitLab, Bitbucket and Sourcehut repositories. Just put the following code in your README:
</p>
<pre>
@ -28,8 +28,8 @@ used for GitHub, GitLab and Bitbucket repositories. Just put the following code
</pre>
<p>
where <code>&lt;service&gt;</code> is one of <code>github</code>, <code>gitlab</code> or <code>bitbucket</code>. So the
following Markdown
where <code>&lt;service&gt;</code> is one of <code>github</code>, <code>gitlab</code>, <code>bitbucket</code> or
<code>sourcehut</code>. So the following Markdown
</p>
<pre>
@ -74,6 +74,7 @@ the lines of
<option value="github">GitHub</option>
<option value="gitlab">Gitlab</option>
<option value="bitbucket">Bitbucket</option>
<option value="sourcehut">Sourcehut</option>
</select>
<label>/</label>
<input name="user" id="user" type="text" placeholder="user" />
@ -94,7 +95,7 @@ welcome.
<p>
You can reach me via mail: <a href="mailto:mail+hoc@@vbrandl.net">mail+hoc@@vbrandl.net</a> preferably using
my <a href="https://mirror.oldsql.cc/key.asc">GPG key</a>
my <a href="https://www.vbrandl.net/static/keys/0x1FFE431282F4B8CC0A7579167FB009175885FC76.asc">GPG key</a>
(<a href="http://pool.sks-keyservers.net/pks/lookup?op=get&amp;search=0x1FFE431282F4B8CC0A7579167FB009175885FC76">from a
keyserver</a>), or by using any other UID from my key.
</p>

View File

@ -19,7 +19,7 @@ To include the badge in your readme, use the following markdown:
</p>
<pre>
[![Hits-of-Code](@repo_info.base_url/@repo_info.path?branch=@repo_info.branch)](@repo_info.base_url/@repo_info.path?branch=@repo_info.branch/view?branch=@repo_info.branch)
[![Hits-of-Code](@repo_info.base_url/@repo_info.path?branch=@repo_info.branch)](@repo_info.base_url/@repo_info.path/view?branch=@repo_info.branch)
</pre>

16
tests/badge.rs Normal file
View File

@ -0,0 +1,16 @@
mod util;
#[actix_rt::test]
async fn badge_succeeds() {
let test_app = util::spawn_app().await;
let client = awc::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());
}

16
tests/health_check.rs Normal file
View File

@ -0,0 +1,16 @@
mod util;
#[actix_rt::test]
async fn health_check_works() {
let test_app = util::spawn_app().await;
let client = awc::Client::default();
let response = client
.get(&format!("{}/health_check", test_app.address))
.send()
.await
.expect("Failed to execute request");
assert!(response.status().is_success());
}

16
tests/index.rs Normal file
View File

@ -0,0 +1,16 @@
mod util;
#[actix_rt::test]
async fn index_returns_success() {
let test_app = util::spawn_app().await;
let client = awc::Client::default();
let response = client
.get(&format!("{}/", test_app.address))
.send()
.await
.expect("Failed to execute request");
assert!(response.status().is_success());
}

16
tests/json.rs Normal file
View File

@ -0,0 +1,16 @@
mod util;
#[actix_rt::test]
async fn json_returns_success() {
let test_app = util::spawn_app().await;
let client = awc::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
View 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);
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,
}
}