Compare commits
5 Commits
v0.26.0
...
feature/te
Author | SHA1 | Date | |
---|---|---|---|
5493af0c0c | |||
56b973607c | |||
cbdda8a561 | |||
6ac399a41b | |||
35c13fa486 |
@ -1 +0,0 @@
|
|||||||
[advisories]
|
|
12
.github/dependabot.yml
vendored
12
.github/dependabot.yml
vendored
@ -1,12 +0,0 @@
|
|||||||
version: 2
|
|
||||||
updates:
|
|
||||||
- package-ecosystem: cargo
|
|
||||||
directory: "/"
|
|
||||||
schedule:
|
|
||||||
interval: daily
|
|
||||||
time: "04:00"
|
|
||||||
open-pull-requests-limit: 10
|
|
||||||
assignees:
|
|
||||||
- vbrandl
|
|
||||||
labels:
|
|
||||||
- dependencies
|
|
17
.github/workflows/audit.yml
vendored
17
.github/workflows/audit.yml
vendored
@ -3,19 +3,26 @@ on:
|
|||||||
schedule:
|
schedule:
|
||||||
- cron: '0 1 * * *'
|
- cron: '0 1 * * *'
|
||||||
push:
|
push:
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
pull_request:
|
|
||||||
paths:
|
paths:
|
||||||
- '**/Cargo.toml'
|
- '**/Cargo.toml'
|
||||||
- '**/Cargo.lock'
|
- '**/Cargo.lock'
|
||||||
- ".cargo/audit.toml"
|
pull_request:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
security_audit:
|
security_audit:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Cache cargo registry, index and build directory
|
||||||
|
uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.cargo/registry
|
||||||
|
~/.cargo/git
|
||||||
|
./target
|
||||||
|
key: audit-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
|
||||||
- uses: actions-rs/audit-check@v1
|
- uses: actions-rs/audit-check@v1
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
19
.github/workflows/release.yml
vendored
19
.github/workflows/release.yml
vendored
@ -6,12 +6,8 @@ on:
|
|||||||
- 'v[0-9]+.[0-9]+.[0-9]+'
|
- 'v[0-9]+.[0-9]+.[0-9]+'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
tests:
|
|
||||||
uses: vbrandl/hoc/.github/workflows/rust.yml@master
|
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
name: Publishing for ${{ matrix.os }}
|
name: Publishing for ${{ matrix.os }}
|
||||||
needs: [tests]
|
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
@ -33,7 +29,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout sources
|
- name: Checkout sources
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Install stable toolchain
|
- name: Install stable toolchain
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
@ -48,7 +44,7 @@ jobs:
|
|||||||
~/.cargo/registry
|
~/.cargo/registry
|
||||||
~/.cargo/git
|
~/.cargo/git
|
||||||
./target
|
./target
|
||||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
key: release-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
|
||||||
- name: Cargo build
|
- name: Cargo build
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
@ -78,14 +74,3 @@ jobs:
|
|||||||
target/${{ matrix.target }}/release/hoc-${{ matrix.artifact_prefix }}.sha256
|
target/${{ matrix.target }}/release/hoc-${{ matrix.artifact_prefix }}.sha256
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
changelog:
|
|
||||||
name: Update Changelog
|
|
||||||
needs: [tests]
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- uses: taiki-e/create-gh-release-action@v1
|
|
||||||
with:
|
|
||||||
changelog: CHANGELOG.md
|
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
33
.github/workflows/rust.yml
vendored
33
.github/workflows/rust.yml
vendored
@ -1,19 +1,13 @@
|
|||||||
on:
|
on: [push, pull_request]
|
||||||
workflow_call:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
pull_request:
|
|
||||||
schedule:
|
|
||||||
- cron: "0 0 * * *"
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
rustfmt:
|
rustfmt:
|
||||||
name: Rustfmt
|
name: Rustfmt
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout sources
|
- name: Checkout sources
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Install stable toolchain
|
- name: Install stable toolchain
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
@ -23,6 +17,15 @@ jobs:
|
|||||||
override: true
|
override: true
|
||||||
components: rustfmt
|
components: rustfmt
|
||||||
|
|
||||||
|
- name: Cache cargo registry, index and build directory
|
||||||
|
uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.cargo/registry
|
||||||
|
~/.cargo/git
|
||||||
|
./target
|
||||||
|
key: rustfmt-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
|
||||||
- name: Check Formatting
|
- name: Check Formatting
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
@ -34,7 +37,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout sources
|
- name: Checkout sources
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Install stable toolchain
|
- name: Install stable toolchain
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
@ -45,13 +48,13 @@ jobs:
|
|||||||
components: rustfmt
|
components: rustfmt
|
||||||
|
|
||||||
- name: Cache cargo registry, index and build directory
|
- name: Cache cargo registry, index and build directory
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v2
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
~/.cargo/registry
|
~/.cargo/registry
|
||||||
~/.cargo/git
|
~/.cargo/git
|
||||||
./target
|
./target
|
||||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
key: clippy-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
|
||||||
- name: Clippy Linting
|
- name: Clippy Linting
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
@ -71,7 +74,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout sources
|
- name: Checkout sources
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Install stable toolchain
|
- name: Install stable toolchain
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
@ -81,13 +84,13 @@ jobs:
|
|||||||
override: true
|
override: true
|
||||||
|
|
||||||
- name: Cache cargo registry, index and build directory
|
- name: Cache cargo registry, index and build directory
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v2
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
~/.cargo/registry
|
~/.cargo/registry
|
||||||
~/.cargo/git
|
~/.cargo/git
|
||||||
./target
|
./target
|
||||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
key: test-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
|
||||||
- name: Run Tests
|
- name: Run Tests
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
|
53
.gitlab-ci.yml
Normal file
53
.gitlab-ci.yml
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
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
|
||||||
|
|
22
CHANGELOG.md
22
CHANGELOG.md
@ -1,22 +0,0 @@
|
|||||||
# Changelog
|
|
||||||
|
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
||||||
|
|
||||||
## [Unreleased]
|
|
||||||
|
|
||||||
## [0.26.0] 2022-10-03
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
* Updated [`tracing-subscriber`](https://github.com/tokio-rs/tracing) from 0.3.15 to 0.3.16 ([#501])
|
|
||||||
* Updated [`tracing`](https://github.com/tokio-rs/tracing) from 0.1.36 to 0.1.37 ([#502])
|
|
||||||
* Updated [`serde_json`](https://github.com/serde-rs/json) from 1.0.85 to 1.0.86 ([#503])
|
|
||||||
* Updated [`tracing-bunyan-formatter`](https://github.com/LukeMathWalker/tracing-bunyan-formatter) from 0.3.3 to 0.3.4 ([#504])
|
|
||||||
* Updated [`dotenvy`](https://github.com/allan2/dotenvy) from 0.15.5 to 0.15.6 ([#508])
|
|
||||||
|
|
||||||
[#501]: https://github.com/vbrandl/hoc/pull/501
|
|
||||||
[#502]: https://github.com/vbrandl/hoc/pull/502
|
|
||||||
[#503]: https://github.com/vbrandl/hoc/pull/503
|
|
||||||
[#504]: https://github.com/vbrandl/hoc/pull/504
|
|
||||||
[#508]: https://github.com/vbrandl/hoc/pull/508
|
|
2138
Cargo.lock
generated
2138
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
56
Cargo.toml
56
Cargo.toml
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "hoc"
|
name = "hoc"
|
||||||
version = "0.26.0"
|
version = "0.17.1"
|
||||||
authors = ["Valentin Brandl <vbrandl@riseup.net>"]
|
authors = ["Valentin Brandl <vbrandl@riseup.net>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
@ -13,35 +13,39 @@ path = "src/main.rs"
|
|||||||
name = "hoc"
|
name = "hoc"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-rt = "2.7.0"
|
actix-rt = "1.1.1"
|
||||||
actix-web = "4.2.1"
|
actix-web = "3.3.2"
|
||||||
badgers = "1.0.0"
|
actix-web-opentelemetry = "0.10.0"
|
||||||
bytes = "1.2.1"
|
badge = "0.3.0"
|
||||||
config = { version = "0.13.2", features = ["toml"] }
|
bytes = "1.0.1"
|
||||||
dotenvy = "0.15.6"
|
config = { version = "0.11.0", features = ["toml"] }
|
||||||
futures = "0.3.24"
|
dotenv = "0.15.0"
|
||||||
git2 = "0.15.0"
|
futures = "0.3.13"
|
||||||
|
git2 = "0.13.17"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
mime = "0.3"
|
|
||||||
number_prefix = "0.4.0"
|
number_prefix = "0.4.0"
|
||||||
openssl-probe = "0.1.5"
|
openssl-probe = "0.1.2"
|
||||||
reqwest = "0.11.12"
|
# TODO: upgrade
|
||||||
serde = "1.0.145"
|
opentelemetry = { version = "0.12.0", default-features = false, features = ["trace"] }
|
||||||
serde_derive = "1.0.137"
|
# TODO: upgrade
|
||||||
serde_json = "1.0.86"
|
opentelemetry-jaeger = "0.11.0"
|
||||||
tracing = "0.1.37"
|
reqwest = "0.10.10"
|
||||||
tracing-actix-web = "0.6.1"
|
serde = "1.0.125"
|
||||||
tracing-bunyan-formatter = "0.3.4"
|
serde_derive = "1.0.123"
|
||||||
|
serde_json = "1.0.64"
|
||||||
|
tracing = "0.1.25"
|
||||||
|
tracing-actix-web = "0.2.1"
|
||||||
|
tracing-bunyan-formatter = "0.1.7"
|
||||||
tracing-futures = "0.2.5"
|
tracing-futures = "0.2.5"
|
||||||
tracing-log = "0.1.3"
|
tracing-log = "0.1.2"
|
||||||
tracing-subscriber = { version = "0.3.16", features = ["registry", "env-filter"] }
|
tracing-opentelemetry = "0.11.0"
|
||||||
|
tracing-subscriber = { version = "0.2.17", features = ["registry", "env-filter"] }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
ructe = { version = "0.15.0", features = ["mime03"] }
|
ructe = "0.13.0"
|
||||||
vergen = { version = "7.3.1", default-features = false, features = ["git"] }
|
vergen = { version = "5.1.0", default-features = false, features = ["git"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
awc = "3.0.1"
|
ructe = "0.13.0"
|
||||||
ructe = "0.15.0"
|
tempfile = "3.2.0"
|
||||||
tempfile = "3.3.0"
|
tokio = "0.2.25"
|
||||||
tokio = "1.21.2"
|
|
||||||
|
13
Dockerfile
13
Dockerfile
@ -1,13 +1,9 @@
|
|||||||
# FROM ekidd/rust-musl-builder:stable as builder
|
FROM ekidd/rust-musl-builder:stable as builder
|
||||||
FROM clux/muslrust:stable as builder
|
|
||||||
|
|
||||||
# create new cargo project
|
# create new cargo project
|
||||||
RUN cargo init --lib
|
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 build config
|
||||||
# COPY --chown=rust ./Cargo.lock ./Cargo.lock
|
COPY --chown=rust ./Cargo.lock ./Cargo.lock
|
||||||
COPY ./Cargo.lock ./Cargo.lock
|
|
||||||
COPY ./Cargo.toml ./Cargo.toml
|
COPY ./Cargo.toml ./Cargo.toml
|
||||||
# HACK: remove build-dependencies so we have at least some caching
|
# HACK: remove build-dependencies so we have at least some caching
|
||||||
RUN head -n $(($(grep -n "\[build-dependencies\]" Cargo.toml | cut -f1 -d:) - 1)) Cargo.toml | sed '/build.rs/d' > \
|
RUN head -n $(($(grep -n "\[build-dependencies\]" Cargo.toml | cut -f1 -d:) - 1)) Cargo.toml | sed '/build.rs/d' > \
|
||||||
@ -41,7 +37,6 @@ USER hoc
|
|||||||
# FROM scratch
|
# FROM scratch
|
||||||
# COPY --from=linuxkit/ca-certificates:v0.7 / /
|
# COPY --from=linuxkit/ca-certificates:v0.7 / /
|
||||||
|
|
||||||
# COPY --from=builder /home/rust/src/target/x86_64-unknown-linux-musl/release/hoc .
|
COPY --from=builder /home/rust/src/target/x86_64-unknown-linux-musl/release/hoc .
|
||||||
COPY --from=builder /volume/target/x86_64-unknown-linux-musl/release/hoc .
|
|
||||||
|
|
||||||
ENTRYPOINT ["/home/hoc/hoc"]
|
ENTRYPOINT ["/home/hoc/hoc"]
|
||||||
|
@ -19,8 +19,8 @@ The API is as simple as
|
|||||||
https://<host>/<service>/<user>/<repo>
|
https://<host>/<service>/<user>/<repo>
|
||||||
```
|
```
|
||||||
|
|
||||||
where `<service>` is one of `gitub`, `gitlab`, `bitbucket` or `sourcehut`. The HoC data can also be received as JSON by
|
where `<service>` is one of `gitub`, `gitlab` or `bitbucket`. The HoC data can also be received as JSON by appending
|
||||||
appending `/json` to the reuqest path:
|
`/json` to the reuqest path:
|
||||||
|
|
||||||
```
|
```
|
||||||
https://<host>/<service>/<user>/<repo>/json
|
https://<host>/<service>/<user>/<repo>/json
|
||||||
|
12
build.rs
12
build.rs
@ -1,15 +1,15 @@
|
|||||||
extern crate ructe;
|
extern crate ructe;
|
||||||
extern crate vergen;
|
extern crate vergen;
|
||||||
|
|
||||||
use ructe::{Ructe, RucteError};
|
use ructe::Ructe;
|
||||||
use vergen::{vergen, Config, ShaKind};
|
use vergen::{vergen, Config, ShaKind};
|
||||||
|
|
||||||
fn main() -> Result<(), RucteError> {
|
fn main() {
|
||||||
let mut config = Config::default();
|
let mut config = Config::default();
|
||||||
*config.git_mut().sha_kind_mut() = ShaKind::Short;
|
*config.git_mut().sha_kind_mut() = ShaKind::Short;
|
||||||
vergen(config).expect("Unable to generate static repo info");
|
vergen(config).expect("Unable to generate static repo info");
|
||||||
let mut ructe = Ructe::from_env()?;
|
Ructe::from_env()
|
||||||
let mut statics = ructe.statics()?;
|
.expect("ructe")
|
||||||
statics.add_files("static")?;
|
.compile_templates("templates")
|
||||||
ructe.compile_templates("templates")
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
1
crate-hashes.json
Normal file
1
crate-hashes.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{}
|
56
default.nix
Normal file
56
default.nix
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
{ sources ? import ./nix/sources.nix
|
||||||
|
, system ? builtins.currentSystem
|
||||||
|
}:
|
||||||
|
|
||||||
|
let
|
||||||
|
rustOverlay = import "${sources.nixpkgs-mozilla}/rust-overlay.nix";
|
||||||
|
cargo2nixOverlay = import "${sources.cargo2nix}/overlay";
|
||||||
|
|
||||||
|
pkgs = import sources.nixpkgs {
|
||||||
|
# pkgs = import <nixpkgs> {
|
||||||
|
inherit system;
|
||||||
|
overlays = [ cargo2nixOverlay rustOverlay ];
|
||||||
|
};
|
||||||
|
|
||||||
|
rustPkgs = pkgs.rustBuilder.makePackageSet' {
|
||||||
|
rustChannel = "stable";
|
||||||
|
packageFun = import ./Cargo.nix;
|
||||||
|
localPatterns =
|
||||||
|
[
|
||||||
|
''^(src|tests)(/.*)?''
|
||||||
|
''[^/]*\.(rs|toml)$''
|
||||||
|
# include other directory from the project repository
|
||||||
|
''^templates(/.*)?''
|
||||||
|
''^static(/.*)?''
|
||||||
|
''^.git.*(/.*)?''
|
||||||
|
];
|
||||||
|
# packageOverrides
|
||||||
|
};
|
||||||
|
in
|
||||||
|
rec {
|
||||||
|
inherit rustPkgs;
|
||||||
|
shell = pkgs.mkShell {
|
||||||
|
inputsFrom = pkgs.lib.mapAttrsToList (_: pkg: pkg { }) rustPkgs.noBuild.workspace;
|
||||||
|
nativeBuildInputs = with rustPkgs; [ cargo rustc ];
|
||||||
|
};
|
||||||
|
package = (rustPkgs.workspace.hoc {}).overrideAttrs (drv: {
|
||||||
|
buildInputs = drv.buildInputs or [ ] ++ [ pkgs.git ];
|
||||||
|
});
|
||||||
|
dockerImage =
|
||||||
|
pkgs.dockerTools.buildImage {
|
||||||
|
name = "vbrandl/hits-of-code";
|
||||||
|
tag = package.version;
|
||||||
|
|
||||||
|
contents =
|
||||||
|
[
|
||||||
|
package
|
||||||
|
pkgs.cacert
|
||||||
|
pkgs.gitMinimal
|
||||||
|
];
|
||||||
|
|
||||||
|
config = {
|
||||||
|
Cmd = [ "/bin/hoc" ];
|
||||||
|
WorkingDir = "/home/hoc";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
50
nix/sources.json
Normal file
50
nix/sources.json
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
{
|
||||||
|
"cargo2nix": {
|
||||||
|
"branch": "master",
|
||||||
|
"description": "Convert a Cargo.lock to mkRustCrate statements for import in Nix",
|
||||||
|
"homepage": "",
|
||||||
|
"owner": "tenx-tech",
|
||||||
|
"repo": "cargo2nix",
|
||||||
|
"rev": "7bc062ccffc41dc7d3759b8b797e8b4f8dd23a15",
|
||||||
|
"sha256": "1z7xwk1hbp26aydsk3y07riy0ivwqss06n1470mvdl7allfcd1w5",
|
||||||
|
"type": "tarball",
|
||||||
|
"url": "https://github.com/tenx-tech/cargo2nix/archive/7bc062ccffc41dc7d3759b8b797e8b4f8dd23a15.tar.gz",
|
||||||
|
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
||||||
|
},
|
||||||
|
"niv": {
|
||||||
|
"branch": "master",
|
||||||
|
"description": "Easy dependency management for Nix projects",
|
||||||
|
"homepage": "https://github.com/nmattia/niv",
|
||||||
|
"owner": "nmattia",
|
||||||
|
"repo": "niv",
|
||||||
|
"rev": "98c74a80934123cb4c3bf3314567f67311eb711a",
|
||||||
|
"sha256": "1w8n54hapd4x9f1am33icvngkqns7m3hl9yair38yqq08ffwg0kn",
|
||||||
|
"type": "tarball",
|
||||||
|
"url": "https://github.com/nmattia/niv/archive/98c74a80934123cb4c3bf3314567f67311eb711a.tar.gz",
|
||||||
|
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"branch": "nixpkgs-unstable",
|
||||||
|
"description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to",
|
||||||
|
"homepage": "https://github.com/NixOS/nixpkgs",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs-channels",
|
||||||
|
"rev": "f6bfb371cba2b5a02f200c2747c1fe2c72bd782f",
|
||||||
|
"sha256": "0y3hlbyvznrpr1d2vxj2511hkjg733wdnxfaib3fgy9i9jr8ivzn",
|
||||||
|
"type": "tarball",
|
||||||
|
"url": "https://github.com/NixOS/nixpkgs-channels/archive/f6bfb371cba2b5a02f200c2747c1fe2c72bd782f.tar.gz",
|
||||||
|
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
||||||
|
},
|
||||||
|
"nixpkgs-mozilla": {
|
||||||
|
"branch": "master",
|
||||||
|
"description": "mozilla related nixpkgs (extends nixos/nixpkgs repo)",
|
||||||
|
"homepage": null,
|
||||||
|
"owner": "mozilla",
|
||||||
|
"repo": "nixpkgs-mozilla",
|
||||||
|
"rev": "e912ed483e980dfb4666ae0ed17845c4220e5e7c",
|
||||||
|
"sha256": "08fvzb8w80bkkabc1iyhzd15f4sm7ra10jn32kfch5klgl0gj3j3",
|
||||||
|
"type": "tarball",
|
||||||
|
"url": "https://github.com/mozilla/nixpkgs-mozilla/archive/e912ed483e980dfb4666ae0ed17845c4220e5e7c.tar.gz",
|
||||||
|
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
||||||
|
}
|
||||||
|
}
|
134
nix/sources.nix
Normal file
134
nix/sources.nix
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
# This file has been generated by Niv.
|
||||||
|
|
||||||
|
let
|
||||||
|
|
||||||
|
#
|
||||||
|
# The fetchers. fetch_<type> fetches specs of type <type>.
|
||||||
|
#
|
||||||
|
|
||||||
|
fetch_file = pkgs: spec:
|
||||||
|
if spec.builtin or true then
|
||||||
|
builtins_fetchurl { inherit (spec) url sha256; }
|
||||||
|
else
|
||||||
|
pkgs.fetchurl { inherit (spec) url sha256; };
|
||||||
|
|
||||||
|
fetch_tarball = pkgs: spec:
|
||||||
|
if spec.builtin or true then
|
||||||
|
builtins_fetchTarball { inherit (spec) url sha256; }
|
||||||
|
else
|
||||||
|
pkgs.fetchzip { inherit (spec) url sha256; };
|
||||||
|
|
||||||
|
fetch_git = spec:
|
||||||
|
builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; };
|
||||||
|
|
||||||
|
fetch_builtin-tarball = spec:
|
||||||
|
builtins.trace
|
||||||
|
''
|
||||||
|
WARNING:
|
||||||
|
The niv type "builtin-tarball" will soon be deprecated. You should
|
||||||
|
instead use `builtin = true`.
|
||||||
|
|
||||||
|
$ niv modify <package> -a type=tarball -a builtin=true
|
||||||
|
''
|
||||||
|
builtins_fetchTarball { inherit (spec) url sha256; };
|
||||||
|
|
||||||
|
fetch_builtin-url = spec:
|
||||||
|
builtins.trace
|
||||||
|
''
|
||||||
|
WARNING:
|
||||||
|
The niv type "builtin-url" will soon be deprecated. You should
|
||||||
|
instead use `builtin = true`.
|
||||||
|
|
||||||
|
$ niv modify <package> -a type=file -a builtin=true
|
||||||
|
''
|
||||||
|
(builtins_fetchurl { inherit (spec) url sha256; });
|
||||||
|
|
||||||
|
#
|
||||||
|
# Various helpers
|
||||||
|
#
|
||||||
|
|
||||||
|
# The set of packages used when specs are fetched using non-builtins.
|
||||||
|
mkPkgs = sources:
|
||||||
|
let
|
||||||
|
sourcesNixpkgs =
|
||||||
|
import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) {};
|
||||||
|
hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
|
||||||
|
hasThisAsNixpkgsPath = <nixpkgs> == ./.;
|
||||||
|
in
|
||||||
|
if builtins.hasAttr "nixpkgs" sources
|
||||||
|
then sourcesNixpkgs
|
||||||
|
else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
|
||||||
|
import <nixpkgs> {}
|
||||||
|
else
|
||||||
|
abort
|
||||||
|
''
|
||||||
|
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
|
||||||
|
add a package called "nixpkgs" to your sources.json.
|
||||||
|
'';
|
||||||
|
|
||||||
|
# The actual fetching function.
|
||||||
|
fetch = pkgs: name: spec:
|
||||||
|
|
||||||
|
if ! builtins.hasAttr "type" spec then
|
||||||
|
abort "ERROR: niv spec ${name} does not have a 'type' attribute"
|
||||||
|
else if spec.type == "file" then fetch_file pkgs spec
|
||||||
|
else if spec.type == "tarball" then fetch_tarball pkgs spec
|
||||||
|
else if spec.type == "git" then fetch_git spec
|
||||||
|
else if spec.type == "builtin-tarball" then fetch_builtin-tarball spec
|
||||||
|
else if spec.type == "builtin-url" then fetch_builtin-url spec
|
||||||
|
else
|
||||||
|
abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}";
|
||||||
|
|
||||||
|
# Ports of functions for older nix versions
|
||||||
|
|
||||||
|
# a Nix version of mapAttrs if the built-in doesn't exist
|
||||||
|
mapAttrs = builtins.mapAttrs or (
|
||||||
|
f: set: with builtins;
|
||||||
|
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))
|
||||||
|
);
|
||||||
|
|
||||||
|
# fetchTarball version that is compatible between all the versions of Nix
|
||||||
|
builtins_fetchTarball = { url, sha256 }@attrs:
|
||||||
|
let
|
||||||
|
inherit (builtins) lessThan nixVersion fetchTarball;
|
||||||
|
in
|
||||||
|
if lessThan nixVersion "1.12" then
|
||||||
|
fetchTarball { inherit url; }
|
||||||
|
else
|
||||||
|
fetchTarball attrs;
|
||||||
|
|
||||||
|
# fetchurl version that is compatible between all the versions of Nix
|
||||||
|
builtins_fetchurl = { url, sha256 }@attrs:
|
||||||
|
let
|
||||||
|
inherit (builtins) lessThan nixVersion fetchurl;
|
||||||
|
in
|
||||||
|
if lessThan nixVersion "1.12" then
|
||||||
|
fetchurl { inherit url; }
|
||||||
|
else
|
||||||
|
fetchurl attrs;
|
||||||
|
|
||||||
|
# Create the final "sources" from the config
|
||||||
|
mkSources = config:
|
||||||
|
mapAttrs (
|
||||||
|
name: spec:
|
||||||
|
if builtins.hasAttr "outPath" spec
|
||||||
|
then abort
|
||||||
|
"The values in sources.json should not have an 'outPath' attribute"
|
||||||
|
else
|
||||||
|
spec // { outPath = fetch config.pkgs name spec; }
|
||||||
|
) config.sources;
|
||||||
|
|
||||||
|
# The "config" used by the fetchers
|
||||||
|
mkConfig =
|
||||||
|
{ sourcesFile ? ./sources.json
|
||||||
|
, sources ? builtins.fromJSON (builtins.readFile sourcesFile)
|
||||||
|
, pkgs ? mkPkgs sources
|
||||||
|
}: rec {
|
||||||
|
# The sources, i.e. the attribute set of spec name to spec
|
||||||
|
inherit sources;
|
||||||
|
|
||||||
|
# The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers
|
||||||
|
inherit pkgs;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }
|
@ -1,8 +1 @@
|
|||||||
{ pkgs ? import <nixpkgs> {} }:
|
with import ./. { }; shell
|
||||||
|
|
||||||
pkgs.mkShell {
|
|
||||||
buildInputs = with pkgs; [
|
|
||||||
openssl
|
|
||||||
pkg-config
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
@ -101,9 +101,9 @@ impl<'a> CacheState<'a> {
|
|||||||
entries.insert(
|
entries.insert(
|
||||||
branch.into(),
|
branch.into(),
|
||||||
CacheEntry {
|
CacheEntry {
|
||||||
|
commits,
|
||||||
head,
|
head,
|
||||||
count,
|
count,
|
||||||
commits,
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
Cache { entries }
|
Cache { entries }
|
||||||
|
@ -18,16 +18,21 @@ pub struct Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Settings {
|
impl Settings {
|
||||||
|
#[deprecated]
|
||||||
|
pub fn new() -> Result<Self, ConfigError> {
|
||||||
|
Self::load()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn load() -> Result<Self, ConfigError> {
|
pub fn load() -> Result<Self, ConfigError> {
|
||||||
Config::builder()
|
let mut config = Config::new();
|
||||||
.add_source(File::with_name("hoc.toml").required(false))
|
config
|
||||||
.add_source(Environment::with_prefix("hoc"))
|
.merge(File::with_name("hoc.toml").required(false))?
|
||||||
|
.merge(Environment::with_prefix("hoc"))?
|
||||||
.set_default("repodir", "./repos")?
|
.set_default("repodir", "./repos")?
|
||||||
.set_default("cachedir", "./cache")?
|
.set_default("cachedir", "./cache")?
|
||||||
.set_default("workers", 4)?
|
.set_default("workers", 4)?
|
||||||
.set_default("port", 8080)?
|
.set_default("port", 8080)?
|
||||||
.set_default("host", "0.0.0.0")?
|
.set_default("host", "0.0.0.0")?;
|
||||||
.build()?
|
config.try_into()
|
||||||
.try_deserialize()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
37
src/count.rs
37
src/count.rs
@ -1,30 +1,27 @@
|
|||||||
use crate::error::Result;
|
use crate::error::Result;
|
||||||
use std::{
|
use std::{fs::read_dir, path::Path, result::Result as StdResult};
|
||||||
fs::{read_dir, ReadDir},
|
|
||||||
iter::once,
|
|
||||||
path::Path,
|
|
||||||
result::Result as StdResult,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The on disk layout for served repos is `<service>/<user>/<repo>`
|
|
||||||
/// so to get the amount of repos, we just have to count everything
|
|
||||||
/// in `*/*/*` to get the count.
|
|
||||||
#[instrument]
|
#[instrument]
|
||||||
pub fn count_repositories<P>(repo_path: P) -> Result<usize>
|
pub(crate) fn count_repositories<P>(repo_path: P) -> Result<usize>
|
||||||
where
|
where
|
||||||
P: AsRef<Path> + std::fmt::Debug,
|
P: AsRef<Path> + std::fmt::Debug,
|
||||||
{
|
{
|
||||||
trace!("Counting repositories");
|
trace!("Counting repositories");
|
||||||
std::fs::create_dir_all(&repo_path)?;
|
std::fs::create_dir_all(&repo_path)?;
|
||||||
Ok(once(read_dir(repo_path)?)
|
Ok(read_dir(repo_path)?
|
||||||
.flat_map(sub_directories)
|
.filter_map(StdResult::ok)
|
||||||
.flat_map(sub_directories)
|
.filter(|entry| entry.file_type().map(|ft| ft.is_dir()).unwrap_or(false))
|
||||||
.flat_map(sub_directories)
|
.map(|entry| read_dir(entry.path()))
|
||||||
|
.filter_map(StdResult::ok)
|
||||||
|
.flat_map(|dir| {
|
||||||
|
dir.filter_map(StdResult::ok)
|
||||||
|
.filter(|entry| entry.file_type().map(|ft| ft.is_dir()).unwrap_or(false))
|
||||||
|
})
|
||||||
|
.map(|entry| read_dir(entry.path()))
|
||||||
|
.filter_map(StdResult::ok)
|
||||||
|
.flat_map(|dir| {
|
||||||
|
dir.filter_map(StdResult::ok)
|
||||||
|
.filter(|entry| entry.file_type().map(|ft| ft.is_dir()).unwrap_or(false))
|
||||||
|
})
|
||||||
.count())
|
.count())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sub_directories(dir: ReadDir) -> impl Iterator<Item = ReadDir> {
|
|
||||||
dir.filter_map(StdResult::ok)
|
|
||||||
.filter(|entry| entry.file_type().map(|ft| ft.is_dir()).unwrap_or(false))
|
|
||||||
.filter_map(|entry| read_dir(entry.path()).ok())
|
|
||||||
}
|
|
||||||
|
@ -5,7 +5,7 @@ use std::fmt;
|
|||||||
pub(crate) type Result<T> = std::result::Result<T, Error>;
|
pub(crate) type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub(crate) enum Error {
|
||||||
Badge(String),
|
Badge(String),
|
||||||
Client(reqwest::Error),
|
Client(reqwest::Error),
|
||||||
Git(git2::Error),
|
Git(git2::Error),
|
||||||
|
105
src/lib.rs
105
src/lib.rs
@ -11,7 +11,7 @@ extern crate tracing;
|
|||||||
|
|
||||||
mod cache;
|
mod cache;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod count;
|
mod count;
|
||||||
mod error;
|
mod error;
|
||||||
mod service;
|
mod service;
|
||||||
mod statics;
|
mod statics;
|
||||||
@ -22,17 +22,18 @@ use crate::{
|
|||||||
cache::CacheState,
|
cache::CacheState,
|
||||||
config::Settings,
|
config::Settings,
|
||||||
error::{Error, Result},
|
error::{Error, Result},
|
||||||
service::{Bitbucket, FormService, GitHub, Gitlab, Service, Sourcehut},
|
service::{Bitbucket, FormService, GitHub, Gitlab, Service},
|
||||||
statics::{CLIENT, VERSION_INFO},
|
statics::{CLIENT, CSS, FAVICON, VERSION_INFO},
|
||||||
template::{RepoGeneratorInfo, RepoInfo},
|
template::RepoInfo,
|
||||||
};
|
};
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
dev::Server,
|
dev::Server,
|
||||||
http::header::{CacheControl, CacheDirective, Expires, LOCATION},
|
http::header::{CacheControl, CacheDirective, Expires, LOCATION},
|
||||||
middleware::{self, TrailingSlash},
|
middleware::{self, normalize::TrailingSlash},
|
||||||
web, App, HttpResponse, HttpServer, Responder,
|
web, App, HttpResponse, HttpServer, Responder,
|
||||||
};
|
};
|
||||||
use badgers::{Badge, BadgeOptions};
|
use actix_web_opentelemetry::RequestTracing;
|
||||||
|
use badge::{Badge, BadgeOptions};
|
||||||
use git2::{BranchType, Repository};
|
use git2::{BranchType, Repository};
|
||||||
use number_prefix::NumberPrefix;
|
use number_prefix::NumberPrefix;
|
||||||
use std::{
|
use std::{
|
||||||
@ -46,7 +47,6 @@ use std::{
|
|||||||
sync::atomic::Ordering,
|
sync::atomic::Ordering,
|
||||||
time::{Duration, SystemTime},
|
time::{Duration, SystemTime},
|
||||||
};
|
};
|
||||||
use templates::statics::{self as template_statics, StaticFile};
|
|
||||||
use tracing::Instrument;
|
use tracing::Instrument;
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/templates.rs"));
|
include!(concat!(env!("OUT_DIR"), "/templates.rs"));
|
||||||
@ -56,7 +56,6 @@ struct GeneratorForm<'a> {
|
|||||||
service: FormService,
|
service: FormService,
|
||||||
user: Cow<'a, str>,
|
user: Cow<'a, str>,
|
||||||
repo: Cow<'a, str>,
|
repo: Cow<'a, str>,
|
||||||
branch: Option<Cow<'a, str>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -226,10 +225,10 @@ where
|
|||||||
})?;
|
})?;
|
||||||
repo_count.fetch_sub(1, Ordering::Relaxed);
|
repo_count.fetch_sub(1, Ordering::Relaxed);
|
||||||
Ok(HttpResponse::TemporaryRedirect()
|
Ok(HttpResponse::TemporaryRedirect()
|
||||||
.insert_header((
|
.header(
|
||||||
LOCATION,
|
LOCATION,
|
||||||
format!("/{}/{}/{}/view", T::url_path(), data.0, data.1),
|
format!("/{}/{}/{}/view", T::url_path(), data.0, data.1),
|
||||||
))
|
)
|
||||||
.finish())
|
.finish())
|
||||||
};
|
};
|
||||||
future.instrument(span).await
|
future.instrument(span).await
|
||||||
@ -320,8 +319,8 @@ fn no_cache_response(body: Vec<u8>) -> HttpResponse {
|
|||||||
let expiration = SystemTime::now() + Duration::from_secs(30);
|
let expiration = SystemTime::now() + Duration::from_secs(30);
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.content_type("image/svg+xml")
|
.content_type("image/svg+xml")
|
||||||
.insert_header(Expires(expiration.into()))
|
.set(Expires(expiration.into()))
|
||||||
.insert_header(CacheControl(vec![
|
.set(CacheControl(vec![
|
||||||
CacheDirective::MaxAge(0u32),
|
CacheDirective::MaxAge(0u32),
|
||||||
CacheDirective::MustRevalidate,
|
CacheDirective::MustRevalidate,
|
||||||
CacheDirective::NoCache,
|
CacheDirective::NoCache,
|
||||||
@ -439,23 +438,16 @@ async fn generate(
|
|||||||
state: web::Data<State>,
|
state: web::Data<State>,
|
||||||
repo_count: web::Data<AtomicUsize>,
|
repo_count: web::Data<AtomicUsize>,
|
||||||
) -> Result<HttpResponse> {
|
) -> Result<HttpResponse> {
|
||||||
|
let repo = format!("{}/{}", params.user, params.repo);
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
let repo_info = RepoGeneratorInfo {
|
|
||||||
service: params.service,
|
|
||||||
user: ¶ms.user,
|
|
||||||
repo: ¶ms.repo,
|
|
||||||
branch: params
|
|
||||||
.branch
|
|
||||||
.as_deref()
|
|
||||||
.filter(|s| !s.is_empty())
|
|
||||||
.unwrap_or("master"),
|
|
||||||
};
|
|
||||||
templates::generate(
|
templates::generate(
|
||||||
&mut buf,
|
&mut buf,
|
||||||
VERSION_INFO,
|
VERSION_INFO,
|
||||||
repo_count.load(Ordering::Relaxed),
|
repo_count.load(Ordering::Relaxed),
|
||||||
&state.settings.base_url,
|
&state.settings.base_url,
|
||||||
&repo_info,
|
params.service.url(),
|
||||||
|
params.service.service(),
|
||||||
|
&repo,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().content_type("text/html").body(buf))
|
Ok(HttpResponse::Ok().content_type("text/html").body(buf))
|
||||||
@ -471,32 +463,12 @@ async fn async_p404(repo_count: web::Data<AtomicUsize>) -> Result<HttpResponse>
|
|||||||
p404(repo_count)
|
p404(repo_count)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A duration to add to current time for a far expires header.
|
fn css() -> HttpResponse {
|
||||||
static FAR: Duration = Duration::from_secs(180 * 24 * 60 * 60);
|
HttpResponse::Ok().content_type("text/css").body(CSS)
|
||||||
|
|
||||||
#[get("/static/{filename}")]
|
|
||||||
async fn static_file(
|
|
||||||
path: web::Path<String>,
|
|
||||||
repo_count: web::Data<AtomicUsize>,
|
|
||||||
) -> Result<HttpResponse> {
|
|
||||||
StaticFile::get(&path)
|
|
||||||
.map(|data| {
|
|
||||||
let far_expires = SystemTime::now() + FAR;
|
|
||||||
HttpResponse::Ok()
|
|
||||||
.insert_header(Expires(far_expires.into()))
|
|
||||||
.content_type(data.mime.clone())
|
|
||||||
.body(data.content)
|
|
||||||
})
|
|
||||||
.map(Result::Ok)
|
|
||||||
.unwrap_or_else(|| p404(repo_count))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/favicon.ico")]
|
fn favicon32() -> HttpResponse {
|
||||||
async fn favicon32() -> HttpResponse {
|
HttpResponse::Ok().content_type("image/png").body(FAVICON)
|
||||||
let data = &template_statics::favicon32_png;
|
|
||||||
HttpResponse::Ok()
|
|
||||||
.content_type(data.mime.clone())
|
|
||||||
.body(data.content)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn start_server(listener: TcpListener, settings: Settings) -> std::io::Result<Server> {
|
async fn start_server(listener: TcpListener, settings: Settings) -> std::io::Result<Server> {
|
||||||
@ -506,21 +478,42 @@ async fn start_server(listener: TcpListener, settings: Settings) -> std::io::Res
|
|||||||
web::Data::new(AtomicUsize::new(count::count_repositories(&settings.repodir).unwrap()));
|
web::Data::new(AtomicUsize::new(count::count_repositories(&settings.repodir).unwrap()));
|
||||||
let state = web::Data::new(State { settings });
|
let state = web::Data::new(State { settings });
|
||||||
Ok(HttpServer::new(move || {
|
Ok(HttpServer::new(move || {
|
||||||
let app = App::new()
|
App::new()
|
||||||
.app_data(state.clone())
|
.app_data(state.clone())
|
||||||
.app_data(repo_count.clone())
|
.app_data(repo_count.clone())
|
||||||
.wrap(tracing_actix_web::TracingLogger::default())
|
.wrap(RequestTracing::new())
|
||||||
|
.wrap(tracing_actix_web::TracingLogger)
|
||||||
.wrap(middleware::NormalizePath::new(TrailingSlash::Trim))
|
.wrap(middleware::NormalizePath::new(TrailingSlash::Trim))
|
||||||
.service(index)
|
.service(index)
|
||||||
.service(health_check)
|
.service(health_check)
|
||||||
.service(static_file)
|
.service(web::resource("/tacit-css.min.css").route(web::get().to(css)))
|
||||||
.service(favicon32)
|
.service(web::resource("/favicon.ico").route(web::get().to(favicon32)))
|
||||||
.service(generate)
|
.service(generate)
|
||||||
.default_service(web::to(async_p404));
|
.service(web::resource("/github/{user}/{repo}").to(calculate_hoc::<GitHub>))
|
||||||
let app = GitHub::register_service(app);
|
.service(web::resource("/gitlab/{user}/{repo}").to(calculate_hoc::<Gitlab>))
|
||||||
let app = Gitlab::register_service(app);
|
.service(web::resource("/bitbucket/{user}/{repo}").to(calculate_hoc::<Bitbucket>))
|
||||||
let app = Bitbucket::register_service(app);
|
.service(
|
||||||
Sourcehut::register_service(app)
|
web::resource("/github/{user}/{repo}/delete")
|
||||||
|
.route(web::post().to(delete_repo_and_cache::<GitHub>)),
|
||||||
|
)
|
||||||
|
.service(
|
||||||
|
web::resource("/gitlab/{user}/{repo}/delete")
|
||||||
|
.route(web::post().to(delete_repo_and_cache::<Gitlab>)),
|
||||||
|
)
|
||||||
|
.service(
|
||||||
|
web::resource("/bitbucket/{user}/{repo}/delete")
|
||||||
|
.route(web::post().to(delete_repo_and_cache::<Bitbucket>)),
|
||||||
|
)
|
||||||
|
.service(web::resource("/github/{user}/{repo}/json").to(json_hoc::<GitHub>))
|
||||||
|
.service(web::resource("/gitlab/{user}/{repo}/json").to(json_hoc::<Gitlab>))
|
||||||
|
.service(web::resource("/bitbucket/{user}/{repo}/json").to(json_hoc::<Bitbucket>))
|
||||||
|
.service(web::resource("/view/github/{user}/{repo}").to(overview::<GitHub>))
|
||||||
|
.service(web::resource("/view/gitlab/{user}/{repo}").to(overview::<Gitlab>))
|
||||||
|
.service(web::resource("/view/bitbucket/{user}/{repo}").to(overview::<Bitbucket>))
|
||||||
|
.service(web::resource("/github/{user}/{repo}/view").to(overview::<GitHub>))
|
||||||
|
.service(web::resource("/gitlab/{user}/{repo}/view").to(overview::<Gitlab>))
|
||||||
|
.service(web::resource("/bitbucket/{user}/{repo}/view").to(overview::<Bitbucket>))
|
||||||
|
.default_service(web::resource("").route(web::get().to(async_p404)))
|
||||||
})
|
})
|
||||||
.workers(workers)
|
.workers(workers)
|
||||||
.listen(listener)?
|
.listen(listener)?
|
||||||
|
14
src/main.rs
14
src/main.rs
@ -1,24 +1,26 @@
|
|||||||
use hoc::{config::Settings, telemetry};
|
use hoc::{config::Settings, telemetry};
|
||||||
|
|
||||||
use std::net::TcpListener;
|
use std::net::TcpListener;
|
||||||
|
|
||||||
fn init() {
|
fn init() -> opentelemetry_jaeger::Uninstall {
|
||||||
dotenvy::dotenv().ok();
|
dotenv::dotenv().ok();
|
||||||
openssl_probe::init_ssl_cert_env_vars();
|
openssl_probe::init_ssl_cert_env_vars();
|
||||||
|
|
||||||
telemetry::init_subscriber(telemetry::get_subscriber("hoc", "info"))
|
let (subscriber, uninstall) = telemetry::get_subscriber("hoc", "info");
|
||||||
|
telemetry::init_subscriber(subscriber);
|
||||||
|
uninstall
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::main]
|
#[actix_rt::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
init();
|
let _uninstall = init();
|
||||||
|
|
||||||
// TODO: error handling
|
// TODO: error handling
|
||||||
let settings = Settings::load().expect("Cannot load config");
|
let settings = Settings::load().expect("Cannot load config");
|
||||||
|
|
||||||
let address = format!("{}:{}", settings.host, settings.port);
|
let address = format!("{}:{}", settings.host, settings.port);
|
||||||
// TODO: error handling
|
// TODO: error handling
|
||||||
let listener = TcpListener::bind(address)?;
|
let listener = TcpListener::bind(address).expect("cannot bind addres");
|
||||||
|
|
||||||
hoc::run(listener, settings)
|
hoc::run(listener, settings)
|
||||||
.await
|
.await
|
||||||
.expect("Server error")
|
.expect("Server error")
|
||||||
|
@ -1,43 +1,17 @@
|
|||||||
use crate::{calculate_hoc, delete_repo_and_cache, json_hoc, overview};
|
pub(crate) trait Service {
|
||||||
|
|
||||||
use actix_web::{
|
|
||||||
dev::{ServiceFactory, ServiceRequest},
|
|
||||||
web, App,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub(crate) trait Service: Sized + 'static {
|
|
||||||
fn domain() -> &'static str;
|
fn domain() -> &'static str;
|
||||||
fn url_path() -> &'static str;
|
fn url_path() -> &'static str;
|
||||||
fn commit_url(repo: &str, commit_ref: &str) -> String;
|
fn commit_url(repo: &str, commit_ref: &str) -> String;
|
||||||
|
|
||||||
fn register_service<T>(app: App<T>) -> App<T>
|
|
||||||
where
|
|
||||||
T: ServiceFactory<ServiceRequest, Config = (), Error = actix_web::Error, InitError = ()>,
|
|
||||||
{
|
|
||||||
let url_path = Self::url_path();
|
|
||||||
app.service(
|
|
||||||
web::resource(format!("/{url_path}/{{user}}/{{repo}}")).to(calculate_hoc::<Self>),
|
|
||||||
)
|
|
||||||
.service(
|
|
||||||
web::resource(format!("/{url_path}/{{user}}/{{repo}}/delete"))
|
|
||||||
.route(web::post().to(delete_repo_and_cache::<Self>)),
|
|
||||||
)
|
|
||||||
.service(web::resource(format!("/{url_path}/{{user}}/{{repo}}/json")).to(json_hoc::<Self>))
|
|
||||||
.service(web::resource(format!("/view/{url_path}/{{user}}/{{repo}}")).to(overview::<Self>))
|
|
||||||
.service(web::resource(format!("/{url_path}/{{user}}/{{repo}}/view")).to(overview::<Self>))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Clone, Copy)]
|
#[derive(Deserialize, Serialize)]
|
||||||
pub enum FormService {
|
pub(crate) enum FormService {
|
||||||
#[serde(rename = "github")]
|
#[serde(rename = "github")]
|
||||||
GitHub,
|
GitHub,
|
||||||
#[serde(rename = "gitlab")]
|
#[serde(rename = "gitlab")]
|
||||||
Gitlab,
|
Gitlab,
|
||||||
#[serde(rename = "bitbucket")]
|
#[serde(rename = "bitbucket")]
|
||||||
Bitbucket,
|
Bitbucket,
|
||||||
#[serde(rename = "sourcehut")]
|
|
||||||
Sourcehut,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FormService {
|
impl FormService {
|
||||||
@ -46,7 +20,6 @@ impl FormService {
|
|||||||
FormService::GitHub => "github.com",
|
FormService::GitHub => "github.com",
|
||||||
FormService::Gitlab => "gitlab.com",
|
FormService::Gitlab => "gitlab.com",
|
||||||
FormService::Bitbucket => "bitbucket.org",
|
FormService::Bitbucket => "bitbucket.org",
|
||||||
FormService::Sourcehut => "git.sr.ht",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +28,6 @@ impl FormService {
|
|||||||
FormService::GitHub => "github",
|
FormService::GitHub => "github",
|
||||||
FormService::Gitlab => "gitlab",
|
FormService::Gitlab => "gitlab",
|
||||||
FormService::Bitbucket => "bitbucket",
|
FormService::Bitbucket => "bitbucket",
|
||||||
FormService::Sourcehut => "sourcehut",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,17 +73,3 @@ impl Service for Bitbucket {
|
|||||||
format!("https://{}/{}/commits/{}", Self::domain(), repo, commit_ref)
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -7,6 +7,8 @@ pub(crate) const VERSION_INFO: VersionInfo = VersionInfo {
|
|||||||
commit: env!("VERGEN_GIT_SHA_SHORT"),
|
commit: env!("VERGEN_GIT_SHA_SHORT"),
|
||||||
version: env!("CARGO_PKG_VERSION"),
|
version: env!("CARGO_PKG_VERSION"),
|
||||||
};
|
};
|
||||||
|
pub(crate) const CSS: &str = include_str!("../static/tacit-css.min.css");
|
||||||
|
pub(crate) const FAVICON: &[u8] = include_bytes!("../static/favicon32.png");
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub(crate) static ref CLIENT: reqwest::Client = reqwest::Client::new();
|
pub(crate) static ref CLIENT: reqwest::Client = reqwest::Client::new();
|
||||||
|
@ -1,18 +1,32 @@
|
|||||||
|
use opentelemetry::global;
|
||||||
|
use opentelemetry_jaeger::Uninstall;
|
||||||
use tracing::{subscriber::set_global_default, Subscriber};
|
use tracing::{subscriber::set_global_default, Subscriber};
|
||||||
use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer};
|
use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer};
|
||||||
use tracing_log::LogTracer;
|
use tracing_log::LogTracer;
|
||||||
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry};
|
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry};
|
||||||
|
|
||||||
pub fn get_subscriber(name: &str, env_filter: &str) -> impl Subscriber + Send + Sync {
|
// TODO: don't pass `Uninstall` around...
|
||||||
|
pub fn get_subscriber(name: &str, env_filter: &str) -> (impl Subscriber + Send + Sync, Uninstall) {
|
||||||
let env_filter =
|
let env_filter =
|
||||||
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(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);
|
let formatting_layer = BunyanFormattingLayer::new(name.to_string(), std::io::stdout);
|
||||||
|
|
||||||
Registry::default()
|
global::set_text_map_propagator(opentelemetry_jaeger::Propagator::new());
|
||||||
.with(env_filter)
|
let (tracer, uninstall) = opentelemetry_jaeger::new_pipeline()
|
||||||
.with(JsonStorageLayer)
|
.with_service_name(name)
|
||||||
.with(formatting_layer)
|
.install()
|
||||||
|
.expect("cannot install jaeger pipeline");
|
||||||
|
let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);
|
||||||
|
|
||||||
|
(
|
||||||
|
Registry::default()
|
||||||
|
.with(telemetry)
|
||||||
|
.with(env_filter)
|
||||||
|
.with(JsonStorageLayer)
|
||||||
|
.with(formatting_layer),
|
||||||
|
uninstall,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_subscriber(subscriber: impl Subscriber + Send + Sync) {
|
pub fn init_subscriber(subscriber: impl Subscriber + Send + Sync) {
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
use crate::service::FormService;
|
|
||||||
|
|
||||||
pub struct RepoInfo<'a> {
|
pub struct RepoInfo<'a> {
|
||||||
pub commit_url: &'a str,
|
pub commit_url: &'a str,
|
||||||
pub commits: u64,
|
pub commits: u64,
|
||||||
@ -11,10 +9,3 @@ pub struct RepoInfo<'a> {
|
|||||||
pub url: &'a str,
|
pub url: &'a str,
|
||||||
pub branch: &'a str,
|
pub branch: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct RepoGeneratorInfo<'a> {
|
|
||||||
pub service: FormService,
|
|
||||||
pub user: &'a str,
|
|
||||||
pub repo: &'a str,
|
|
||||||
pub branch: &'a str,
|
|
||||||
}
|
|
||||||
|
4
static/tacit-css.min.css
vendored
4
static/tacit-css.min.css
vendored
File diff suppressed because one or more lines are too long
@ -1,4 +1,3 @@
|
|||||||
@use super::statics::*;
|
|
||||||
@use crate::statics::VersionInfo;
|
@use crate::statics::VersionInfo;
|
||||||
|
|
||||||
@(title: &str, header: &str, content: Content, version_info: VersionInfo, repo_count: usize)
|
@(title: &str, header: &str, content: Content, version_info: VersionInfo, repo_count: usize)
|
||||||
@ -10,7 +9,7 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta name="keywords" content="Hits-of-Code, GitHub, Badge" />
|
<meta name="keywords" content="Hits-of-Code, GitHub, Badge" />
|
||||||
<meta name="description" content="Hits-of-Code Badges for Git repositories" />
|
<meta name="description" content="Hits-of-Code Badges for Git repositories" />
|
||||||
<link rel="stylesheet" href="/static/@tacit_css_min_css.name" />
|
<link rel="stylesheet" href="/tacit-css.min.css" />
|
||||||
<title>@title</title>
|
<title>@title</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
@use super::base;
|
@use super::base;
|
||||||
@use crate::{statics::VersionInfo, template::RepoGeneratorInfo};
|
@use crate::statics::VersionInfo;
|
||||||
|
|
||||||
@(version_info: VersionInfo, repo_count: usize, base_url: &str, repo_info: &RepoGeneratorInfo)
|
@(version_info: VersionInfo, repo_count: usize, base_url: &str, url: &str, service: &str, path: &str)
|
||||||
|
|
||||||
@:base("Hits-of-Code Badges", "Badge Generator", {
|
@:base("Hits-of-Code Badges", "Badge Generator", {
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Here is the markdown for the badge for <a href="https://@repo_info.service.url()/@repo_info.user/@repo_info.repo">@repo_info.user/@repo_info.repo</a>
|
Here is the markdown for the badge for <a href="https://@url/@path">@url/@path</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
[/@repo_info.user/@repo_info.repo?branch=@repo_info.branch)](@base_url/@repo_info.service.service()/@repo_info.user/@repo_info.repo/view?branch=@repo_info.branch)
|
[](@base_url/@service/@path/view)
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
@ -18,6 +18,6 @@ It will be rendered like this
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
<a href="@base_url/@repo_info.service.service()/@repo_info.user/@repo_info.repo/view?branch=@repo_info.branch"><img src="@base_url/@repo_info.service.service()/@repo_info.user/@repo_info.repo?branch=@repo_info.branch" alt="example badge" /></a>
|
<a href="@base_url/@service/@path/view"><img src="@base_url/@service/@path" alt="example badge" /></a>
|
||||||
</pre>
|
</pre>
|
||||||
}, version_info, repo_count)
|
}, version_info, repo_count)
|
||||||
|
@ -20,7 +20,7 @@ gives an overview about the amount of work put into a codebase.
|
|||||||
<p>
|
<p>
|
||||||
There is a <a href="https://github.com/yegor256/hoc/">command-line tool</a> to calculate the HoC of a repository, but
|
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
|
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, Bitbucket and Sourcehut repositories. Just put the following code in your README:
|
used for GitHub, GitLab and Bitbucket repositories. Just put the following code in your README:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
@ -28,8 +28,8 @@ used for GitHub, GitLab, Bitbucket and Sourcehut repositories. Just put the foll
|
|||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
where <code><service></code> is one of <code>github</code>, <code>gitlab</code>, <code>bitbucket</code> or
|
where <code><service></code> is one of <code>github</code>, <code>gitlab</code> or <code>bitbucket</code>. So the
|
||||||
<code>sourcehut</code>. So the following Markdown
|
following Markdown
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
@ -74,14 +74,11 @@ the lines of
|
|||||||
<option value="github">GitHub</option>
|
<option value="github">GitHub</option>
|
||||||
<option value="gitlab">Gitlab</option>
|
<option value="gitlab">Gitlab</option>
|
||||||
<option value="bitbucket">Bitbucket</option>
|
<option value="bitbucket">Bitbucket</option>
|
||||||
<option value="sourcehut">Sourcehut</option>
|
|
||||||
</select>
|
</select>
|
||||||
<label>/</label>
|
<label>/</label>
|
||||||
<input name="user" id="user" type="text" placeholder="user" />
|
<input name="user" id="user" type="text" placeholder="user" />
|
||||||
<label>/</label>
|
<label>/</label>
|
||||||
<input name="repo" id="repo" type="text" placeholder="repository" />
|
<input name="repo" id="repo" type="text" placeholder="repository" />
|
||||||
<label>:</label>
|
|
||||||
<input name="branch" id="branch" type="text" placeholder="branch (defaults to `master`)" />
|
|
||||||
<button type="submit">Generate</button>
|
<button type="submit">Generate</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
@ -97,7 +94,7 @@ welcome.
|
|||||||
|
|
||||||
<p>
|
<p>
|
||||||
You can reach me via mail: <a href="mailto:mail+hoc@@vbrandl.net">mail+hoc@@vbrandl.net</a> preferably using
|
You can reach me via mail: <a href="mailto:mail+hoc@@vbrandl.net">mail+hoc@@vbrandl.net</a> preferably using
|
||||||
my <a href="https://www.vbrandl.net/static/keys/0x1FFE431282F4B8CC0A7579167FB009175885FC76.asc">GPG key</a>
|
my <a href="https://mirror.oldsql.cc/key.asc">GPG key</a>
|
||||||
(<a href="http://pool.sks-keyservers.net/pks/lookup?op=get&search=0x1FFE431282F4B8CC0A7579167FB009175885FC76">from a
|
(<a href="http://pool.sks-keyservers.net/pks/lookup?op=get&search=0x1FFE431282F4B8CC0A7579167FB009175885FC76">from a
|
||||||
keyserver</a>), or by using any other UID from my key.
|
keyserver</a>), or by using any other UID from my key.
|
||||||
</p>
|
</p>
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
|
use actix_web::client;
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn badge_succeeds() {
|
async fn badge_succeeds() {
|
||||||
let test_app = util::spawn_app().await;
|
let test_app = util::spawn_app().await;
|
||||||
|
|
||||||
let client = awc::Client::default();
|
let client = client::Client::default();
|
||||||
|
|
||||||
let response = client
|
let response = client
|
||||||
.get(&format!("{}/github/vbrandl/hoc", test_app.address))
|
.get(&format!("{}/github/vbrandl/hoc", test_app.address))
|
||||||
|
@ -1,66 +0,0 @@
|
|||||||
use hoc::count::count_repositories;
|
|
||||||
|
|
||||||
use tempfile::TempDir;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn no_repos() {
|
|
||||||
let repos = TempDir::new().unwrap();
|
|
||||||
assert_eq!(0, count_repositories(&repos).unwrap())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn no_repos_for_provider() {
|
|
||||||
let repos = TempDir::new().unwrap();
|
|
||||||
let _provider = TempDir::new_in(&repos).unwrap();
|
|
||||||
assert_eq!(0, count_repositories(&repos).unwrap())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn no_repos_for_owner() {
|
|
||||||
let repos = TempDir::new().unwrap();
|
|
||||||
let provider = TempDir::new_in(&repos).unwrap();
|
|
||||||
let _owner = TempDir::new_in(&provider).unwrap();
|
|
||||||
assert_eq!(0, count_repositories(&repos).unwrap())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn one_repo_for_owner() {
|
|
||||||
let repos = TempDir::new().unwrap();
|
|
||||||
let provider = TempDir::new_in(&repos).unwrap();
|
|
||||||
let owner = TempDir::new_in(&provider).unwrap();
|
|
||||||
let _repo = TempDir::new_in(&owner).unwrap();
|
|
||||||
assert_eq!(1, count_repositories(&repos).unwrap())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn two_repos_for_owner() {
|
|
||||||
let repos = TempDir::new().unwrap();
|
|
||||||
let provider = TempDir::new_in(&repos).unwrap();
|
|
||||||
let owner = TempDir::new_in(&provider).unwrap();
|
|
||||||
let _repo1 = TempDir::new_in(&owner).unwrap();
|
|
||||||
let _repo2 = TempDir::new_in(&owner).unwrap();
|
|
||||||
assert_eq!(2, count_repositories(&repos).unwrap())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn two_repos_for_two_providers() {
|
|
||||||
let repos = TempDir::new().unwrap();
|
|
||||||
let provider1 = TempDir::new_in(&repos).unwrap();
|
|
||||||
let owner1 = TempDir::new_in(&provider1).unwrap();
|
|
||||||
let _repo1 = TempDir::new_in(&owner1).unwrap();
|
|
||||||
let provider2 = TempDir::new_in(&repos).unwrap();
|
|
||||||
let owner2 = TempDir::new_in(&provider2).unwrap();
|
|
||||||
let _repo2 = TempDir::new_in(&owner2).unwrap();
|
|
||||||
assert_eq!(2, count_repositories(&repos).unwrap())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn two_subdirs_in_one_repo() {
|
|
||||||
let repos = TempDir::new().unwrap();
|
|
||||||
let provider = TempDir::new_in(&repos).unwrap();
|
|
||||||
let owner = TempDir::new_in(&provider).unwrap();
|
|
||||||
let repo = TempDir::new_in(&owner).unwrap();
|
|
||||||
let _subdir1 = TempDir::new_in(&repo).unwrap();
|
|
||||||
let _subdir2 = TempDir::new_in(&repo).unwrap();
|
|
||||||
assert_eq!(1, count_repositories(&repos).unwrap())
|
|
||||||
}
|
|
@ -1,10 +1,12 @@
|
|||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
|
use actix_web::client;
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn health_check_works() {
|
async fn health_check_works() {
|
||||||
let test_app = util::spawn_app().await;
|
let test_app = util::spawn_app().await;
|
||||||
|
|
||||||
let client = awc::Client::default();
|
let client = client::Client::default();
|
||||||
|
|
||||||
let response = client
|
let response = client
|
||||||
.get(&format!("{}/health_check", test_app.address))
|
.get(&format!("{}/health_check", test_app.address))
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
|
use actix_web::client;
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn index_returns_success() {
|
async fn index_returns_success() {
|
||||||
let test_app = util::spawn_app().await;
|
let test_app = util::spawn_app().await;
|
||||||
|
|
||||||
let client = awc::Client::default();
|
let client = client::Client::default();
|
||||||
|
|
||||||
let response = client
|
let response = client
|
||||||
.get(&format!("{}/", test_app.address))
|
.get(&format!("{}/", test_app.address))
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
|
use actix_web::client;
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn json_returns_success() {
|
async fn json_returns_success() {
|
||||||
let test_app = util::spawn_app().await;
|
let test_app = util::spawn_app().await;
|
||||||
|
|
||||||
let client = awc::Client::default();
|
let client = client::Client::default();
|
||||||
|
|
||||||
let response = client
|
let response = client
|
||||||
.get(&format!("{}/github/vbrandl/hoc/json", test_app.address))
|
.get(&format!("{}/github/vbrandl/hoc/json", test_app.address))
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
mod util;
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn favicon() {
|
|
||||||
let test_app = util::spawn_app().await;
|
|
||||||
|
|
||||||
let client = awc::Client::default();
|
|
||||||
|
|
||||||
let response = client
|
|
||||||
.get(&format!("{}/favicon.ico", test_app.address))
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
.expect("Failed to execute request");
|
|
||||||
|
|
||||||
assert!(response.status().is_success());
|
|
||||||
}
|
|
@ -7,16 +7,15 @@ use tempfile::{tempdir, TempDir};
|
|||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
static ref TRACING: () = {
|
static ref TRACING: () = {
|
||||||
let filter = if std::env::var("TEST_LOG").is_ok() { "debug" } else { "" };
|
let filter = if std::env::var("TEST_LOG").is_ok() { "debug" } else { "" };
|
||||||
let subscriber = telemetry::get_subscriber("test", filter);
|
let subscriber = telemetry::get_subscriber("test", filter).0;
|
||||||
telemetry::init_subscriber(subscriber);
|
telemetry::init_subscriber(subscriber);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TestApp {
|
pub struct TestApp {
|
||||||
pub address: String,
|
pub address: String,
|
||||||
// Those are unused but are hold to be dropped and deleted after the TestApp goes out of scope
|
repo_dir: TempDir,
|
||||||
_repo_dir: TempDir,
|
cache_dir: TempDir,
|
||||||
_cache_dir: TempDir,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn spawn_app() -> TestApp {
|
pub async fn spawn_app() -> TestApp {
|
||||||
@ -27,12 +26,15 @@ pub async fn spawn_app() -> TestApp {
|
|||||||
let port = listener.local_addr().unwrap().port();
|
let port = listener.local_addr().unwrap().port();
|
||||||
let address = format!("http://127.0.0.1:{}", port);
|
let address = format!("http://127.0.0.1:{}", port);
|
||||||
|
|
||||||
let _repo_dir = tempdir().expect("Cannot create repo_dir");
|
let repo_dir = tempdir().expect("Cannot create repo_dir");
|
||||||
let _cache_dir = tempdir().expect("Cannot create cache_dir");
|
let cache_dir = tempdir().expect("Cannot create cache_dir");
|
||||||
|
|
||||||
let mut settings = Settings::load().expect("Failed to read configuration.");
|
let mut settings = Settings::load().expect("Failed to read configuration.");
|
||||||
settings.repodir = _repo_dir.path().to_path_buf();
|
settings.repodir = repo_dir.path().to_path_buf();
|
||||||
settings.cachedir = _cache_dir.path().to_path_buf();
|
settings.cachedir = cache_dir.path().to_path_buf();
|
||||||
|
// configuration.database.database_name = Uuid::new_v4().to_string();
|
||||||
|
|
||||||
|
// let connection_pool = configure_database(&configuration.database).await;
|
||||||
|
|
||||||
let server = hoc::run(listener, settings)
|
let server = hoc::run(listener, settings)
|
||||||
.await
|
.await
|
||||||
@ -42,7 +44,7 @@ pub async fn spawn_app() -> TestApp {
|
|||||||
|
|
||||||
TestApp {
|
TestApp {
|
||||||
address,
|
address,
|
||||||
_repo_dir,
|
repo_dir,
|
||||||
_cache_dir,
|
cache_dir,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
80
vm.nix
Normal file
80
vm.nix
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
# Nix configuration for a VM to run a custom configured Vim
|
||||||
|
#
|
||||||
|
# It is intended as an example of building a VM that builds Vim for testing
|
||||||
|
# and evaluation purposes. It does not represent a production or secure
|
||||||
|
# deployment.
|
||||||
|
|
||||||
|
{ sources ? import ./nix/sources.nix
|
||||||
|
, pkgs ? import sources.nixpkgs { }
|
||||||
|
, callPackage ? pkgs.callPackage
|
||||||
|
, config
|
||||||
|
, lib
|
||||||
|
, ...
|
||||||
|
}:
|
||||||
|
# config, pkgs, lib, ... }:
|
||||||
|
|
||||||
|
let
|
||||||
|
hoc = pkgs.callPackage ./default.nix { };
|
||||||
|
|
||||||
|
# hoc = cargoNix.rootCrate.build;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
environment = {
|
||||||
|
systemPackages = with pkgs; [
|
||||||
|
(
|
||||||
|
hoc
|
||||||
|
# import ./default.nix
|
||||||
|
)
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
networking.hostName = "hoc"; # Define your hostname.
|
||||||
|
|
||||||
|
system.stateVersion = "19.09"; # The version of NixOS originally installed
|
||||||
|
|
||||||
|
# Set security options:
|
||||||
|
security = {
|
||||||
|
sudo = {
|
||||||
|
enable = true; # Enable sudo
|
||||||
|
wheelNeedsPassword = false; # Allow wheel members to run sudo without a passowrd
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
networking.firewall.allowedTCPPorts = [ 80 ];
|
||||||
|
|
||||||
|
# List services that you want to enable:
|
||||||
|
services.openssh = {
|
||||||
|
enable = true; # Enable the OpenSSH daemon.
|
||||||
|
#permitRootLogin = "yes"; # Probably want to change this in production
|
||||||
|
#challengeResponseAuthentication = true; # Probably want to change this in production
|
||||||
|
#passwordAuthentication = true; # Probably want to change this in production
|
||||||
|
openFirewall = true;
|
||||||
|
hostKeys = [
|
||||||
|
{
|
||||||
|
path = "/etc/ssh/ssh_host_ed25519_key"; # Generate a key for the vm
|
||||||
|
type = "ed25519"; # Use the current best key type
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
# Users of the Vim VM:
|
||||||
|
users.mutableUsers = false; # Remove any users not defined in here
|
||||||
|
|
||||||
|
users.users.root = {
|
||||||
|
password = "123456"; # Probably want to change this in production
|
||||||
|
};
|
||||||
|
|
||||||
|
# Misc groups:
|
||||||
|
users.groups.nixos.gid = 1000;
|
||||||
|
|
||||||
|
# NixOS users
|
||||||
|
users.users.nixos = {
|
||||||
|
isNormalUser = true;
|
||||||
|
uid = 1000;
|
||||||
|
group = "nixos";
|
||||||
|
extraGroups = [ "wheel" ];
|
||||||
|
password = "123456"; # Probably want to change this in production
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user