Compare commits
2 Commits
master
...
dependabot
Author | SHA1 | Date | |
---|---|---|---|
|
bdae157caf | ||
|
d6618a0e61 |
@ -1 +0,0 @@
|
||||
[advisories]
|
@ -1,7 +0,0 @@
|
||||
HOC_REPODIR='./repos'
|
||||
HOC_CACHEDIR='./cache'
|
||||
HOC_PORT=8080
|
||||
HOC_HOST='0.0.0.0'
|
||||
HOC_WORKERS=4
|
||||
|
||||
HOC_BASE_URL='http://0.0.0.0:8080'
|
36
.github/dependabot.yml
vendored
36
.github/dependabot.yml
vendored
@ -1,36 +0,0 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: cargo
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: daily
|
||||
time: "04:00"
|
||||
open-pull-requests-limit: 10
|
||||
assignees:
|
||||
- vbrandl
|
||||
labels:
|
||||
- dependencies
|
||||
- dependabot
|
||||
|
||||
- package-ecosystem: 'github-actions'
|
||||
directory: '/'
|
||||
schedule:
|
||||
interval: 'daily'
|
||||
open-pull-requests-limit: 10
|
||||
assignees:
|
||||
- vbrandl
|
||||
labels:
|
||||
- dependabot
|
||||
- dependencies
|
||||
|
||||
- package-ecosystem: docker
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: daily
|
||||
time: "04:00"
|
||||
open-pull-requests-limit: 10
|
||||
assignees:
|
||||
- vbrandl
|
||||
labels:
|
||||
- dependencies
|
||||
- dependabot
|
21
.github/workflows/audit.yml
vendored
21
.github/workflows/audit.yml
vendored
@ -1,21 +0,0 @@
|
||||
name: Security audit
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 1 * * *'
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
paths:
|
||||
- '**/Cargo.toml'
|
||||
- '**/Cargo.lock'
|
||||
- ".cargo/audit.toml"
|
||||
|
||||
jobs:
|
||||
security_audit:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: rustsec/audit-check@v1
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
26
.github/workflows/dependabot-changelog.yml
vendored
26
.github/workflows/dependabot-changelog.yml
vendored
@ -1,26 +0,0 @@
|
||||
name: 'Dependabot Changelog'
|
||||
on:
|
||||
pull_request:
|
||||
types:
|
||||
- opened
|
||||
- synchronize
|
||||
- reopened
|
||||
- ready_for_review
|
||||
- labeled
|
||||
- unlabeled
|
||||
|
||||
jobs:
|
||||
changelog:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
token: ${{ secrets.ACTION_TOKEN }}
|
||||
- uses: dangoslen/dependabot-changelog-helper@v3
|
||||
with:
|
||||
activationLabel: 'dependabot'
|
||||
- uses: stefanzweifel/git-auto-commit-action@v5
|
||||
with:
|
||||
commit_message: "Update Changelog"
|
91
.github/workflows/release.yml
vendored
91
.github/workflows/release.yml
vendored
@ -1,91 +0,0 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v[0-9]+.[0-9]+.[0-9]+'
|
||||
|
||||
jobs:
|
||||
tests:
|
||||
uses: vbrandl/hoc/.github/workflows/rust.yml@master
|
||||
|
||||
publish:
|
||||
name: Publishing for ${{ matrix.os }}
|
||||
needs: [tests]
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [macos-latest, ubuntu-latest, windows-latest]
|
||||
rust: [stable]
|
||||
include:
|
||||
- os: macos-latest
|
||||
artifact_prefix: macos
|
||||
target: x86_64-apple-darwin
|
||||
binary_postfix: ""
|
||||
- os: ubuntu-latest
|
||||
artifact_prefix: linux
|
||||
target: x86_64-unknown-linux-gnu
|
||||
binary_postfix: ""
|
||||
- os: windows-latest
|
||||
artifact_prefix: windows
|
||||
target: x86_64-pc-windows-msvc
|
||||
binary_postfix: ".exe"
|
||||
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install stable toolchain
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ matrix.rust }}
|
||||
override: true
|
||||
|
||||
- name: Cache cargo registry, index and build directory
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/registry
|
||||
~/.cargo/git
|
||||
./target
|
||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||
|
||||
- name: Cargo build
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: build
|
||||
toolchain: ${{ matrix.rust }}
|
||||
args: --release --target ${{ matrix.target }}
|
||||
|
||||
- name: Packaging final binary
|
||||
shell: bash
|
||||
run: |
|
||||
cd target/${{ matrix.target }}/release
|
||||
strip hoc${{ matrix.binary_postfix }}
|
||||
tar czvf hoc-${{ matrix.artifact_prefix }}.tar.gz hoc${{ matrix.binary_postfix }}
|
||||
|
||||
if [[ ${{ runner.os }} == 'Windows' ]]; then
|
||||
certutil -hashfile hoc-${{ matrix.artifact_prefix }}.tar.gz sha256 | grep -E [A-Fa-f0-9]{64} > hoc-${{ matrix.artifact_prefix }}.sha256
|
||||
else
|
||||
shasum -a 256 hoc-${{ matrix.artifact_prefix }}.tar.gz > hoc-${{ matrix.artifact_prefix }}.sha256
|
||||
fi
|
||||
|
||||
- name: Releasing assets
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: |
|
||||
target/${{ matrix.target }}/release/hoc-${{ matrix.artifact_prefix }}.tar.gz
|
||||
target/${{ matrix.target }}/release/hoc-${{ matrix.artifact_prefix }}.sha256
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
changelog:
|
||||
name: Update Changelog
|
||||
needs: [tests]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: taiki-e/create-gh-release-action@v1
|
||||
with:
|
||||
changelog: CHANGELOG.md
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
81
.github/workflows/rust.yml
vendored
81
.github/workflows/rust.yml
vendored
@ -1,76 +1,15 @@
|
||||
on:
|
||||
workflow_call:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
schedule:
|
||||
- cron: "0 0 * * *"
|
||||
name: Rust
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
rustfmt:
|
||||
name: Rustfmt
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install stable toolchain
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
|
||||
- name: Check Formatting
|
||||
run: cargo fmt --all -- --check
|
||||
|
||||
|
||||
clippy:
|
||||
name: Clippy
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install stable toolchain
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
|
||||
- name: Cache cargo registry, index and build directory
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/registry
|
||||
~/.cargo/git
|
||||
./target
|
||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||
|
||||
- name: Clippy Linting
|
||||
run: cargo clippy --all-features -- -Dclippy::all -Dclippy::pedantic
|
||||
- name: Clippy Test Linting
|
||||
run: cargo clippy --tests -- -Dclippy::all -Dclippy::pedantic
|
||||
|
||||
|
||||
test:
|
||||
name: Test Suite
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
# add windows-latest when it is clear why tests are failing
|
||||
# os: [ubuntu-latest, macos-latest]
|
||||
os: [ubuntu-latest]
|
||||
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install stable toolchain
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
|
||||
- name: Cache cargo registry, index and build directory
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/registry
|
||||
~/.cargo/git
|
||||
./target
|
||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||
|
||||
- name: Run Tests
|
||||
run: cargo test
|
||||
- uses: actions/checkout@v1
|
||||
- name: Build
|
||||
run: cargo build --verbose
|
||||
- name: Run tests
|
||||
run: cargo test --verbose
|
||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -3,5 +3,3 @@
|
||||
repos
|
||||
cache
|
||||
hoc.log
|
||||
result
|
||||
.env
|
||||
|
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
|
||||
|
17
.travis.yml
Normal file
17
.travis.yml
Normal file
@ -0,0 +1,17 @@
|
||||
language: rust
|
||||
|
||||
rust:
|
||||
- stable
|
||||
- beta
|
||||
- nightly
|
||||
|
||||
cache:
|
||||
- cargo
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- rust: nightly
|
||||
|
||||
notifications:
|
||||
email:
|
||||
on_failure: always
|
279
CHANGELOG.md
279
CHANGELOG.md
@ -1,279 +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]
|
||||
|
||||
### Dependencies
|
||||
- Bump `serde` from 1.0.192 to 1.0.204 ([#704](https://github.com/vbrandl/hoc/pull/704), [#719](https://github.com/vbrandl/hoc/pull/719), [#726](https://github.com/vbrandl/hoc/pull/726), [#736](https://github.com/vbrandl/hoc/pull/736), [#761](https://github.com/vbrandl/hoc/pull/761), [#766](https://github.com/vbrandl/hoc/pull/766), [#767](https://github.com/vbrandl/hoc/pull/767), [#771](https://github.com/vbrandl/hoc/pull/771), [#775](https://github.com/vbrandl/hoc/pull/775), [#787](https://github.com/vbrandl/hoc/pull/787))
|
||||
- Bump `config` from 0.13.3 to 0.14.0 ([#705](https://github.com/vbrandl/hoc/pull/705), [#729](https://github.com/vbrandl/hoc/pull/729))
|
||||
- Bump `openssl` from 0.10.55 to 0.10.60 ([#706](https://github.com/vbrandl/hoc/pull/706))
|
||||
- Bump `tokio` from 1.34.0 to 1.38.0 ([#707](https://github.com/vbrandl/hoc/pull/707), [#709](https://github.com/vbrandl/hoc/pull/709), [#732](https://github.com/vbrandl/hoc/pull/732), [#756](https://github.com/vbrandl/hoc/pull/756), [#776](https://github.com/vbrandl/hoc/pull/776))
|
||||
- Bump `reqwest` from 0.11.22 to 0.12.5 ([#708](https://github.com/vbrandl/hoc/pull/708), [#728](https://github.com/vbrandl/hoc/pull/728), [#741](https://github.com/vbrandl/hoc/pull/741), [#745](https://github.com/vbrandl/hoc/pull/745), [#749](https://github.com/vbrandl/hoc/pull/749), [#750](https://github.com/vbrandl/hoc/pull/750), [#754](https://github.com/vbrandl/hoc/pull/754), [#758](https://github.com/vbrandl/hoc/pull/758), [#765](https://github.com/vbrandl/hoc/pull/765), [#781](https://github.com/vbrandl/hoc/pull/781))
|
||||
- Bump `anyhow` from 1.0.75 to 1.0.86 ([#710](https://github.com/vbrandl/hoc/pull/710), [#714](https://github.com/vbrandl/hoc/pull/714), [#720](https://github.com/vbrandl/hoc/pull/720), [#737](https://github.com/vbrandl/hoc/pull/737), [#744](https://github.com/vbrandl/hoc/pull/744), [#759](https://github.com/vbrandl/hoc/pull/759), [#768](https://github.com/vbrandl/hoc/pull/768), [#772](https://github.com/vbrandl/hoc/pull/772))
|
||||
- Bump `futures` from 0.3.29 to 0.3.30 ([#711](https://github.com/vbrandl/hoc/pull/711))
|
||||
- Bump `awc` from 3.2.0 to 3.5.0 ([#712](https://github.com/vbrandl/hoc/pull/712), [#731](https://github.com/vbrandl/hoc/pull/731), [#774](https://github.com/vbrandl/hoc/pull/774))
|
||||
- Bump `actix-web` from 4.4.0 to 4.8.0 ([#713](https://github.com/vbrandl/hoc/pull/713), [#739](https://github.com/vbrandl/hoc/pull/739), [#773](https://github.com/vbrandl/hoc/pull/773), [#782](https://github.com/vbrandl/hoc/pull/782))
|
||||
- Bump `tempfile` from 3.8.1 to 3.10.1 ([#715](https://github.com/vbrandl/hoc/pull/715), [#752](https://github.com/vbrandl/hoc/pull/752))
|
||||
- Bump `serde_json` from 1.0.108 to 1.0.120 ([#717](https://github.com/vbrandl/hoc/pull/717), [#722](https://github.com/vbrandl/hoc/pull/722), [#727](https://github.com/vbrandl/hoc/pull/727), [#738](https://github.com/vbrandl/hoc/pull/738), [#760](https://github.com/vbrandl/hoc/pull/760), [#770](https://github.com/vbrandl/hoc/pull/770), [#784](https://github.com/vbrandl/hoc/pull/784), [#786](https://github.com/vbrandl/hoc/pull/786))
|
||||
- Bump `vergen` from 8.2.6 to 8.3.1 ([#721](https://github.com/vbrandl/hoc/pull/721), [#730](https://github.com/vbrandl/hoc/pull/730))
|
||||
- Bump `actions/cache` from 3 to 4 ([#724](https://github.com/vbrandl/hoc/pull/724))
|
||||
- Bump `h2` from 0.3.20 to 0.3.26 ([#725](https://github.com/vbrandl/hoc/pull/725), [#757](https://github.com/vbrandl/hoc/pull/757))
|
||||
- Bump `git2` from 0.18.1 to 0.18.3 ([#734](https://github.com/vbrandl/hoc/pull/734), [#748](https://github.com/vbrandl/hoc/pull/748))
|
||||
- Bump `tracing-actix-web` from 0.7.9 to 0.7.11 ([#742](https://github.com/vbrandl/hoc/pull/742), [#777](https://github.com/vbrandl/hoc/pull/777))
|
||||
- Bump `mio` from 0.8.9 to 0.8.11 ([#740](https://github.com/vbrandl/hoc/pull/740))
|
||||
- Bump `softprops/action-gh-release` from 1 to 2 ([#743](https://github.com/vbrandl/hoc/pull/743))
|
||||
- Bump `bytes` from 1.5.0 to 1.6.0 ([#751](https://github.com/vbrandl/hoc/pull/751))
|
||||
- Bump `actix-rt` from 2.9.0 to 2.10.0 ([#779](https://github.com/vbrandl/hoc/pull/779))
|
||||
- Bump `lazy_static` from 1.4.0 to 1.5.0 ([#783](https://github.com/vbrandl/hoc/pull/783))
|
||||
|
||||
## [0.36.0] 2023-11-17
|
||||
### Dependencies
|
||||
- Bump `serde` from 1.0.160 to 1.0.192 (#613, #617, #627, #636, #639, #640, #645, [#648](https://github.com/vbrandl/hoc/pull/648), [#650](https://github.com/vbrandl/hoc/pull/650), [#652](https://github.com/vbrandl/hoc/pull/652), [#653](https://github.com/vbrandl/hoc/pull/653), [#654](https://github.com/vbrandl/hoc/pull/654), [#655](https://github.com/vbrandl/hoc/pull/655), [#657](https://github.com/vbrandl/hoc/pull/657), [#669](https://github.com/vbrandl/hoc/pull/669), [#687](https://github.com/vbrandl/hoc/pull/687), [#692](https://github.com/vbrandl/hoc/pull/692), [#698](https://github.com/vbrandl/hoc/pull/698))
|
||||
- Bump `actions/cache` from 2 to 3 (#616)
|
||||
- Bump `tokio` from 1.28.0 to 1.34.0 (#618, #625, #633, #634, [#659](https://github.com/vbrandl/hoc/pull/659), [#660](https://github.com/vbrandl/hoc/pull/660), [#665](https://github.com/vbrandl/hoc/pull/665), [#686](https://github.com/vbrandl/hoc/pull/686), [#699](https://github.com/vbrandl/hoc/pull/699))
|
||||
- Bump `reqwest` from 0.11.17 to 0.11.22 (#619, [#672](https://github.com/vbrandl/hoc/pull/672), [#683](https://github.com/vbrandl/hoc/pull/683), [#684](https://github.com/vbrandl/hoc/pull/684))
|
||||
- Bump `vergen` from 8.1.3 to 8.2.6 (#621, #622, #635, #638, [#679](https://github.com/vbrandl/hoc/pull/679), [#697](https://github.com/vbrandl/hoc/pull/697))
|
||||
- Bump `tracing-actix-web` from 0.7.4 to 0.7.9 (#623, [#656](https://github.com/vbrandl/hoc/pull/656), [#682](https://github.com/vbrandl/hoc/pull/682), [#690](https://github.com/vbrandl/hoc/pull/690), [#701](https://github.com/vbrandl/hoc/pull/701))
|
||||
- Bump `git2` from 0.17.1 to 0.18.1 (#624, [#674](https://github.com/vbrandl/hoc/pull/674), [#681](https://github.com/vbrandl/hoc/pull/681))
|
||||
- Bump `tempfile` from 3.5.0 to 3.8.1 (#626, [#646](https://github.com/vbrandl/hoc/pull/646), [#658](https://github.com/vbrandl/hoc/pull/658), [#667](https://github.com/vbrandl/hoc/pull/667), [#695](https://github.com/vbrandl/hoc/pull/695))
|
||||
- Bump `serde_json` from 1.0.96 to 1.0.108 (#630, #632, #637, #641, #644, [#649](https://github.com/vbrandl/hoc/pull/649), [#663](https://github.com/vbrandl/hoc/pull/663), [#678](https://github.com/vbrandl/hoc/pull/678), [#680](https://github.com/vbrandl/hoc/pull/680), [#696](https://github.com/vbrandl/hoc/pull/696))
|
||||
- Bump `openssl` from 0.10.50 to 0.10.55 (#631)
|
||||
- Bump `tracing-bunyan-formatter` from 0.3.7 to 0.3.9 (#642, [#661](https://github.com/vbrandl/hoc/pull/661))
|
||||
- Bump `anyhow` from 1.0.71 to 1.0.75 (#643, [#662](https://github.com/vbrandl/hoc/pull/662), [#664](https://github.com/vbrandl/hoc/pull/664))
|
||||
- Bump `ructe` from 0.16.1 to 0.17.0 ([#647](https://github.com/vbrandl/hoc/pull/647))
|
||||
- Bump `actix-rt` from 2.8.0 to 2.9.0 ([#670](https://github.com/vbrandl/hoc/pull/670))
|
||||
- Bump `actix-web` from 4.3.1 to 4.4.0 ([#673](https://github.com/vbrandl/hoc/pull/673))
|
||||
- Bump `awc` from 3.1.1 to 3.2.0 ([#675](https://github.com/vbrandl/hoc/pull/675))
|
||||
- Bump `actions/checkout` from 3 to 4 ([#676](https://github.com/vbrandl/hoc/pull/676))
|
||||
- Bump `bytes` from 1.4.0 to 1.5.0 ([#677](https://github.com/vbrandl/hoc/pull/677))
|
||||
- Bump `stefanzweifel/git-auto-commit-action` from 4 to 5 ([#685](https://github.com/vbrandl/hoc/pull/685))
|
||||
- Bump `tracing` from 0.1.37 to 0.1.40 ([#688](https://github.com/vbrandl/hoc/pull/688), [#689](https://github.com/vbrandl/hoc/pull/689))
|
||||
- Bump `tracing-log` from 0.1.3 to 0.2.0 ([#691](https://github.com/vbrandl/hoc/pull/691), [#693](https://github.com/vbrandl/hoc/pull/693))
|
||||
- Bump `futures` from 0.3.28 to 0.3.29 ([#694](https://github.com/vbrandl/hoc/pull/694))
|
||||
- Bump `tracing-subscriber` from 0.3.17 to 0.3.18 ([#702](https://github.com/vbrandl/hoc/pull/702))
|
||||
|
||||
|
||||
## [0.35.0] 2023-05-04
|
||||
|
||||
* Updated [`h2`](https://github.com/hyperium/h2) from 0.3.16 to 0.3.17, fixes [SEC#11] ([#599])
|
||||
* Updated [`git2`](https://github.com/rust-lang/git2-rs) from 0.16.1 to 0.17.0 ([#602])
|
||||
* Updated [`git2`](https://github.com/rust-lang/git2-rs) from 0.17.0 to 0.17.1 ([#603])
|
||||
* Updated [`tracing-subscriber`](https://github.com/tokio-rs/tracing) from 0.3.16 to 0.3.17 ([#604])
|
||||
* Updated [`tokio`](https://github.com/tokio-rs/tokio) from 1.27.0 to 1.28.0 ([#605])
|
||||
* Updated [`tracing`](https://github.com/tokio-rs/tracing) from 0.1.37 to 0.1.38 ([#607])
|
||||
* Updated [`vergen`](https://github.com/rustyhorde/vergen) from 8.1.1 to 8.1.3 ([#608])
|
||||
* Downgrade yanked [`tracing`](https://github.com/tokio-rs/tracing) 0.1.38 to 0.1.37 ([#611])
|
||||
* Updated [`reqwest`](https://github.com/seanmonstar/reqwest) from 0.11.16 to 0.11.17 ([#609])
|
||||
* Updated [`anyhow`](https://github.com/dtolnay/anyhow) from 1.0.70 to 1.0.71 ([#610])
|
||||
|
||||
[#599]: https://github.com/vbrandl/hoc/pull/599
|
||||
[#602]: https://github.com/vbrandl/hoc/pull/602
|
||||
[#603]: https://github.com/vbrandl/hoc/pull/603
|
||||
[#604]: https://github.com/vbrandl/hoc/pull/604
|
||||
[#605]: https://github.com/vbrandl/hoc/pull/605
|
||||
[#607]: https://github.com/vbrandl/hoc/pull/607
|
||||
[#608]: https://github.com/vbrandl/hoc/pull/608
|
||||
[#611]: https://github.com/vbrandl/hoc/pull/611
|
||||
[#609]: https://github.com/vbrandl/hoc/pull/609
|
||||
[#610]: https://github.com/vbrandl/hoc/pull/610
|
||||
|
||||
[SEC#11]: https://github.com/vbrandl/hoc/security/dependabot/11
|
||||
|
||||
|
||||
## [0.34.0] 2023-04-13
|
||||
|
||||
* Updated [`tracing-actix-web`](https://github.com/LukeMathWalker/tracing-actix-web) from 0.7.2 to 0.7.3 ([#578])
|
||||
* Updated [`serde`](https://github.com/serde-rs/serde) from 1.0.156 to 1.0.158 ([#580])
|
||||
* Updated [`mime`](https://github.com/hyperium/mime) from 0.3.16 to 0.3.17 ([#582])
|
||||
* Updated [`dotenvy`](https://github.com/allan2/dotenvy) from 0.15.6 to 0.15.7 ([#583])
|
||||
* Updated [`reqwest`](https://github.com/seanmonstar/reqwest) from 0.11.14 to 0.11.16 ([#586])
|
||||
* Updated [`tokio`](https://github.com/tokio-rs/tokio) from 1.26.0 to 1.27.0 ([#588])
|
||||
* Updated [`tempfile`](https://github.com/Stebalien/tempfile) from 3.4.0 to 3.5.0 ([#590])
|
||||
* Updated [`tracing-bunyan-formatter`](https://github.com/LukeMathWalker/tracing-bunyan-formatter) from 0.3.6 to 0.3.7 ([#593])
|
||||
* Updated [`serde`](https://github.com/serde-rs/serde) from 1.0.158 to 1.0.160 ([#594])
|
||||
* Updated [`serde_json`](https://github.com/serde-rs/json) from 1.0.94 to 1.0.96 ([#595])
|
||||
* Updated [`openssl`](https://github.com/sfackler/rust-openssl) from 0.10.40 to 0.10.50, fixes [SEC#6], [SEC#7], and [SEC#8] ([#596])
|
||||
|
||||
[#578]: https://github.com/vbrandl/hoc/pull/578
|
||||
[#580]: https://github.com/vbrandl/hoc/pull/580
|
||||
[#582]: https://github.com/vbrandl/hoc/pull/582
|
||||
[#583]: https://github.com/vbrandl/hoc/pull/583
|
||||
[#586]: https://github.com/vbrandl/hoc/pull/586
|
||||
[#588]: https://github.com/vbrandl/hoc/pull/588
|
||||
[#590]: https://github.com/vbrandl/hoc/pull/590
|
||||
[#593]: https://github.com/vbrandl/hoc/pull/593
|
||||
[#594]: https://github.com/vbrandl/hoc/pull/594
|
||||
[#595]: https://github.com/vbrandl/hoc/pull/595
|
||||
[#596]: https://github.com/vbrandl/hoc/pull/596
|
||||
|
||||
[SEC#6]: https://github.com/vbrandl/hoc/security/dependabot/6
|
||||
[SEC#7]: https://github.com/vbrandl/hoc/security/dependabot/7
|
||||
[SEC#8]: https://github.com/vbrandl/hoc/security/dependabot/8
|
||||
|
||||
|
||||
## [0.33.0] 2023-03-16
|
||||
|
||||
* Updated [`futures`](https://github.com/rust-lang/futures-rs) from 0.3.26 to 0.3.27 ([#575])
|
||||
* Updated [`serde`](https://github.com/serde-rs/serde) from 1.0.152 to 1.0.156 ([#576])
|
||||
* Use edition 2021 ([#577])
|
||||
|
||||
|
||||
[#575]: https://github.com/vbrandl/hoc/pull/575
|
||||
[#576]: https://github.com/vbrandl/hoc/pull/576
|
||||
[#577]: https://github.com/vbrandl/hoc/pull/577
|
||||
|
||||
|
||||
## [0.32.0] 2023-03-06
|
||||
|
||||
* Updated [`actix-web`](https://github.com/actix/actix-web) from 4.3.0 to 4.3.1 ([#566])
|
||||
* Updated [`tempfile`](https://github.com/Stebalien/tempfile) from 3.3.0 to 3.4.0 ([#567])
|
||||
* Updated [`awc`](https://github.com/actix/actix-web) from 3.1.0 to 3.1.1 ([#568])
|
||||
* Updated [`tokio`](https://github.com/tokio-rs/tokio) from 1.25.0 to 1.26.0 ([#569])
|
||||
* Updated [`serde_json`](https://github.com/serde-rs/json) from 1.0.93 to 1.0.94 ([#570])
|
||||
|
||||
[#566]: https://github.com/vbrandl/hoc/pull/566
|
||||
[#567]: https://github.com/vbrandl/hoc/pull/567
|
||||
[#568]: https://github.com/vbrandl/hoc/pull/568
|
||||
[#569]: https://github.com/vbrandl/hoc/pull/569
|
||||
[#570]: https://github.com/vbrandl/hoc/pull/570
|
||||
|
||||
|
||||
## [0.31.0] 2023-02-13
|
||||
|
||||
### Dependency Updates
|
||||
|
||||
* Updated [`tokio`](https://github.com/tokio-rs/tokio) from 1.24.1 to 1.24.2 ([#547])
|
||||
* Updated [`badgers`](https://github.com/vbrandl/badgers) from 1.1.0 to 1.2.0 ([#548])
|
||||
* Updated [`reqwest`](https://github.com/seanmonstar/reqwest) from 0.11.13 to 0.11.14 ([#549])
|
||||
* Updated [`bumpalo`](https://github.com/fitzgen/bumpalo) from 3.10.0 to 3.12.0 ([#550])
|
||||
* Updated [`libgit2-sys`](https://github.com/rust-lang/git2-rs) from 0.14.1+1.5.0 to 0.14.2+1.5.1 ([#551])
|
||||
* Updated [`git2`](https://github.com/rust-lang/git2-rs) from 0.16.0 to 0.16.1 ([#552])
|
||||
* Updated [`actix-rt`](https://github.com/actix/actix-net) from 2.7.0 to 2.8.0 ([#553])
|
||||
* Updated [`actix-web`](https://github.com/actix/actix-web) from 4.2.1 to 4.3.0 ([#554])
|
||||
* Updated [`awc`](https://github.com/actix/actix-web) from 3.0.1 to 3.1.0 ([#555])
|
||||
* Updated [`tokio`](https://github.com/tokio-rs/tokio) from 1.24.2 to 1.25.0 ([#558])
|
||||
* Updated [`ructe`](https://github.com/kaj/ructe) from 0.15.0 to 0.16.1 ([#559])
|
||||
* Updated [`futures`](https://github.com/rust-lang/futures-rs) from 0.3.25 to 0.3.26 ([#560])
|
||||
* Updated [`bytes`](https://github.com/tokio-rs/bytes) from 1.3.0 to 1.4.0 ([#561])
|
||||
* Updated [`serde_json`](https://github.com/serde-rs/json) from 1.0.91 to 1.0.92 ([#562])
|
||||
* Updated [`vergen`](https://github.com/rustyhorde/vergen) from 7.5.0 to 7.5.1 ([#563])
|
||||
* Updated [`serde_json`](https://github.com/serde-rs/json) from 1.0.92 to 1.0.93 ([#564])
|
||||
|
||||
[#547]: https://github.com/vbrandl/hoc/pull/547
|
||||
[#548]: https://github.com/vbrandl/hoc/pull/548
|
||||
[#550]: https://github.com/vbrandl/hoc/pull/550
|
||||
[#551]: https://github.com/vbrandl/hoc/pull/551
|
||||
[#552]: https://github.com/vbrandl/hoc/pull/552
|
||||
[#553]: https://github.com/vbrandl/hoc/pull/553
|
||||
[#554]: https://github.com/vbrandl/hoc/pull/554
|
||||
[#555]: https://github.com/vbrandl/hoc/pull/555
|
||||
[#558]: https://github.com/vbrandl/hoc/pull/558
|
||||
[#559]: https://github.com/vbrandl/hoc/pull/559
|
||||
[#560]: https://github.com/vbrandl/hoc/pull/560
|
||||
[#561]: https://github.com/vbrandl/hoc/pull/561
|
||||
[#562]: https://github.com/vbrandl/hoc/pull/562
|
||||
[#563]: https://github.com/vbrandl/hoc/pull/563
|
||||
[#564]: https://github.com/vbrandl/hoc/pull/564
|
||||
|
||||
|
||||
## [0.30.0] 2023-01-16
|
||||
|
||||
### New Features
|
||||
|
||||
* Allow customization of the badge label ([#546])
|
||||
|
||||
### Dependency Updates
|
||||
|
||||
* Updated [`tracing-actix-web`](https://github.com/LukeMathWalker/tracing-actix-web) from 0.7.1 to 0.7.2 ([#542])
|
||||
* Updated [`git2`](https://github.com/rust-lang/git2-rs) from 0.15.0 to 0.16.0 ([#544])
|
||||
|
||||
|
||||
[#542]: https://github.com/vbrandl/hoc/pull/542
|
||||
[#544]: https://github.com/vbrandl/hoc/pull/544
|
||||
[#546]: https://github.com/vbrandl/hoc/pull/546
|
||||
|
||||
## [0.29.0] 2023-01-07
|
||||
|
||||
### Dependency Updates
|
||||
|
||||
* Updated [`badgers`](https://github.com/vbrandl/badgers) from 1.0.0 to 1.1.0 ([#530])
|
||||
* Updated [`serde_json`](https://github.com/serde-rs/json) from 1.0.90 to 1.0.91 ([#531])
|
||||
* Updated [`vergen`](https://github.com/rustyhorde/vergen) from 7.3.1 to 7.4.4 ([#533])
|
||||
* Updated [`tracing-actix-web`](https://github.com/LukeMathWalker/tracing-actix-web) from 0.6.2 to 0.7.1 ([#534])
|
||||
* Updated [`serde`](https://github.com/serde-rs/serde) from 1.0.151 to 1.0.152 ([#535])
|
||||
* Updated [`tokio`](https://github.com/tokio-rs/tokio) from 1.23.0 to 1.23.1 ([#536])
|
||||
* Updated [`vergen`](https://github.com/rustyhorde/vergen) from 7.4.4 to 7.5.0 ([#537])
|
||||
* Updated [`tokio`](https://github.com/tokio-rs/tokio) from 1.23.1 to 1.24.1 ([#539])
|
||||
|
||||
[#530]: https://github.com/vbrandl/hoc/pull/530
|
||||
[#531]: https://github.com/vbrandl/hoc/pull/531
|
||||
[#533]: https://github.com/vbrandl/hoc/pull/533
|
||||
[#534]: https://github.com/vbrandl/hoc/pull/534
|
||||
[#535]: https://github.com/vbrandl/hoc/pull/535
|
||||
[#536]: https://github.com/vbrandl/hoc/pull/536
|
||||
[#537]: https://github.com/vbrandl/hoc/pull/537
|
||||
[#539]: https://github.com/vbrandl/hoc/pull/539
|
||||
|
||||
## [0.28.0] 2022-12-18
|
||||
|
||||
### Fixes
|
||||
|
||||
* Fixed clippy lint `needless_borrow` ([#526])
|
||||
|
||||
### Dependency Updates
|
||||
|
||||
* Updated [`bytes`](https://github.com/tokio-rs/bytes) from 1.2.1 to 1.3.0 ([#519])
|
||||
* Updated [`config`](https://github.com/mehcode/config-rs) from 0.13.2 to 0.13.3 ([#522])
|
||||
* Updated [`serde_json`](https://github.com/serde-rs/json) from 1.0.88 to 1.0.90 ([#527])
|
||||
* Updated [`serde`](https://github.com/serde-rs/serde) from 1.0.147 to 1.0.151 ([#528])
|
||||
|
||||
[#519]: https://github.com/vbrandl/hoc/pull/519
|
||||
[#522]: https://github.com/vbrandl/hoc/pull/522
|
||||
[#526]: https://github.com/vbrandl/hoc/pull/526
|
||||
[#527]: https://github.com/vbrandl/hoc/pull/527
|
||||
[#528]: https://github.com/vbrandl/hoc/pull/528
|
||||
|
||||
## [0.27.0] 2022-10-21
|
||||
|
||||
### Dependency Updates
|
||||
|
||||
* Updated [`futures`](https://github.com/rust-lang/futures-rs) from 0.3.24 to 0.3.25 ([#511])
|
||||
* Updated [`serde_json`](https://github.com/serde-rs/json) from 1.0.86 to 1.0.87 ([#510])
|
||||
* Updated [`serde`](https://github.com/serde-rs/serde) from 1.0.145 to 1.0.147 ([#512])
|
||||
* Updated [`tracing-actix-web`](https://github.com/LukeMathWalker/tracing-actix-web) from 0.6.1 to 0.6.2 ([#513])
|
||||
* Updated [`reqwest`](https://github.com/seanmonstar/reqwest) from 0.11.12 to 0.11.13 ([#515])
|
||||
* Updated [`tokio`](https://github.com/tokio-rs/tokio) from 1.21.2 to 1.22.0 ([#516])
|
||||
* Updated [`serde_json`](https://github.com/serde-rs/json) from 1.0.87 to 1.0.88 ([#517])
|
||||
|
||||
|
||||
### Fixes
|
||||
|
||||
* Fix clippy lint `needless-borrow` ([#514])
|
||||
|
||||
[#511]: https://github.com/vbrandl/hoc/pull/511
|
||||
[#510]: https://github.com/vbrandl/hoc/pull/510
|
||||
[#512]: https://github.com/vbrandl/hoc/pull/512
|
||||
[#513]: https://github.com/vbrandl/hoc/pull/513
|
||||
[#514]: https://github.com/vbrandl/hoc/pull/514
|
||||
[#515]: https://github.com/vbrandl/hoc/pull/515
|
||||
[#516]: https://github.com/vbrandl/hoc/pull/516
|
||||
[#517]: https://github.com/vbrandl/hoc/pull/517
|
||||
|
||||
|
||||
## [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
|
4174
Cargo.lock
generated
4174
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
61
Cargo.toml
61
Cargo.toml
@ -1,48 +1,27 @@
|
||||
[package]
|
||||
name = "hoc"
|
||||
version = "0.36.0"
|
||||
version = "0.11.3"
|
||||
authors = ["Valentin Brandl <vbrandl@riseup.net>"]
|
||||
edition = "2021"
|
||||
build = "src/build.rs"
|
||||
|
||||
[lib]
|
||||
path = "src/lib.rs"
|
||||
|
||||
[[bin]]
|
||||
path = "src/main.rs"
|
||||
name = "hoc"
|
||||
edition = "2018"
|
||||
build = "build.rs"
|
||||
|
||||
[dependencies]
|
||||
actix-rt = "2.10.0"
|
||||
actix-web = "4.8.0"
|
||||
badgers = "1.2.0"
|
||||
bytes = "1.6.0"
|
||||
config = { version = "0.14.0", features = ["toml"], default-features = false }
|
||||
dotenvy = "0.15.7"
|
||||
futures = "0.3.30"
|
||||
git2 = "0.19.0"
|
||||
lazy_static = "1.5.0"
|
||||
mime = "0.3"
|
||||
number_prefix = "0.4.0"
|
||||
openssl-probe = "0.1.5"
|
||||
reqwest = "0.12.5"
|
||||
serde = "1.0.204"
|
||||
serde_derive = "1.0.204"
|
||||
serde_json = "1.0.120"
|
||||
tracing = "0.1.40"
|
||||
tracing-actix-web = "0.7.11"
|
||||
tracing-bunyan-formatter = "0.3.9"
|
||||
tracing-futures = "0.2.5"
|
||||
tracing-log = "0.2.0"
|
||||
tracing-subscriber = { version = "0.3.18", features = ["registry", "env-filter"] }
|
||||
actix-web = "1.0.7"
|
||||
badge = "0.2.0"
|
||||
bytes = "0.4.12"
|
||||
futures = "0.1.29"
|
||||
git2 = "0.9.1"
|
||||
lazy_static = "1.4.0"
|
||||
log = "0.4.8"
|
||||
log4rs = "0.8.3"
|
||||
number_prefix = "0.3.0"
|
||||
openssl-probe = "0.1.2"
|
||||
reqwest = "0.9.20"
|
||||
serde = "1.0.101"
|
||||
serde_derive = "1.0.101"
|
||||
serde_json = "1.0.40"
|
||||
structopt = "0.3.1"
|
||||
|
||||
[build-dependencies]
|
||||
anyhow = "1.0.86"
|
||||
ructe = { version = "0.17.2", features = ["mime03"] }
|
||||
vergen = { version = "8.3.1", default-features = false, features = ["git", "gitoxide"] }
|
||||
|
||||
[dev-dependencies]
|
||||
awc = "3.5.0"
|
||||
ructe = "0.17.2"
|
||||
tempfile = "3.10.1"
|
||||
tokio = "1.38.0"
|
||||
ructe = "0.7.2"
|
||||
vergen = "3.0.4"
|
||||
|
16
Dockerfile
16
Dockerfile
@ -1,16 +1,12 @@
|
||||
# FROM ekidd/rust-musl-builder:stable as builder
|
||||
FROM clux/muslrust:stable as builder
|
||||
FROM ekidd/rust-musl-builder:stable as builder
|
||||
|
||||
# create new cargo project
|
||||
RUN cargo init --lib
|
||||
# RUN USER=rust cargo init --lib
|
||||
RUN echo 'fn main() { println!("Hello, world!"); }' >> src/main.rs
|
||||
RUN USER=rust cargo init --bin
|
||||
# copy build config
|
||||
# COPY --chown=rust ./Cargo.lock ./Cargo.lock
|
||||
COPY ./Cargo.lock ./Cargo.lock
|
||||
COPY --chown=rust ./Cargo.lock ./Cargo.lock
|
||||
COPY ./Cargo.toml ./Cargo.toml
|
||||
# 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 '/src\/build.rs/d' > \
|
||||
RUN head -n $(($(grep -n "\[build-dependencies\]" Cargo.toml | cut -f1 -d:) - 1)) Cargo.toml | sed '/build.rs/d' > \
|
||||
Cargo.toml2 && rm Cargo.toml && mv Cargo.toml2 Cargo.toml
|
||||
# build to cache dependencies
|
||||
RUN cargo build --release
|
||||
@ -24,6 +20,7 @@ COPY ./.git ./.git
|
||||
# copy source code
|
||||
COPY ./static ./static
|
||||
COPY ./templates ./templates
|
||||
COPY ./build.rs ./build.rs
|
||||
COPY ./src ./src
|
||||
# build source code
|
||||
RUN cargo build --release
|
||||
@ -40,7 +37,6 @@ USER hoc
|
||||
# FROM scratch
|
||||
# COPY --from=linuxkit/ca-certificates:v0.7 / /
|
||||
|
||||
# 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 .
|
||||
COPY --from=builder /home/rust/src/target/x86_64-unknown-linux-musl/release/hoc .
|
||||
|
||||
ENTRYPOINT ["/home/hoc/hoc"]
|
||||
|
33
README.md
33
README.md
@ -1,8 +1,9 @@
|
||||
# Hits-of-Code
|
||||
|
||||
[![Hits-of-Code](https://hitsofcode.com/github/vbrandl/hoc)](https://hitsofcode.com/github/vbrandl/hoc/view)
|
||||
[![Hits-of-Code](https://hitsofcode.com/github/vbrandl/hoc)](https://hitsofcode.com/view/github/vbrandl/hoc)
|
||||
[![Drone build](https://drone.vbrandl.net/api/badges/vbrandl/hoc/status.svg)](https://drone.vbrandl.net/vbrandl/hoc)
|
||||
[![Gitlab build](https://gitlab.com/vbrandl/hoc/badges/master/pipeline.svg)](https://gitlab.com/vbrandl/hoc/pipelines)
|
||||
[![Travis build](https://travis-ci.org/vbrandl/hoc.svg?branch=master)](https://travis-ci.org/vbrandl/hoc)
|
||||
[![dependency status](https://deps.rs/repo/github/vbrandl/hoc/status.svg)](https://deps.rs/repo/github/vbrandl/hoc)
|
||||
|
||||
Small webservice, that returns a badge of the Hits-of-Code of a git repository, as described by [Yegor
|
||||
@ -19,18 +20,14 @@ The API is as simple as
|
||||
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
|
||||
appending `/json` to the reuqest path:
|
||||
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:
|
||||
|
||||
```
|
||||
https://<host>/<service>/<user>/<repo>/json
|
||||
```
|
||||
|
||||
There is also an overview page available via `https://<host>/<service>/<user>/<repo>/view`
|
||||
|
||||
To delete a repository and the cache from the server, send a `POST` request to
|
||||
`https://<host>/<service>/<user>/<repo>/delete`. On the overview page, there is a button to perform this operation. It
|
||||
will respond with a redirect to the overview page so the cache is rebuilt directly.
|
||||
There is also an overview page available via `https://<host>/view/<service>/<user>/<repo>`
|
||||
|
||||
## Building
|
||||
|
||||
@ -48,29 +45,17 @@ $ docker build .
|
||||
|
||||
inside the repository.
|
||||
|
||||
I'm currently working on migrating to [nix](https://nixos.org/nix). To get a development shell, run `nix-shell`, to
|
||||
build the package run `nix-build --attr package` and to build the Docker image, run `nix-build --attr dockerImage`.
|
||||
|
||||
|
||||
## Running
|
||||
|
||||
Rename [`hoc.toml.example`](./hoc.toml.example) to `hoc.toml` or [`.env.example`](./.env.example) to `.env` and set the
|
||||
correct value for `base_url`/`HOC_BASE_URL`. If you don't want to use a configuration or dotenv file, you can pass all
|
||||
parameters directly via environment variables. For variable names see [`.env.example`](./.env.example).
|
||||
|
||||
To start a local instance of the service just run:
|
||||
Run either the binary produced by cargo, the Docker container you just built (using docker-compose) or pull the image
|
||||
from [Docker Hub](https://hub.docker.com/r/vbrandl/hits-of-code)
|
||||
|
||||
```
|
||||
$ HOC_BASE_URL='http://0.0.0.0:8080' ./hoc
|
||||
$ docker run -it --rm vbrandl/hits-of-code --help
|
||||
```
|
||||
|
||||
You can also use the Docker image:
|
||||
|
||||
```
|
||||
$ docker run -p 8080:8080 --env HOC_BASE_URL='http://0.0.0.0:8080' -it --rm vbrandl/hits-of-code
|
||||
```
|
||||
|
||||
When running the binary directly, you need a `git` binary in your `PATH`.
|
||||
When running the binary directly, you need a git binary in your `PATH`.
|
||||
|
||||
|
||||
## License
|
||||
|
14
build.rs
Normal file
14
build.rs
Normal file
@ -0,0 +1,14 @@
|
||||
extern crate ructe;
|
||||
extern crate vergen;
|
||||
|
||||
use ructe::Ructe;
|
||||
use vergen::{generate_cargo_keys, ConstantsFlags};
|
||||
|
||||
fn main() {
|
||||
let flags = ConstantsFlags::SHA_SHORT;
|
||||
generate_cargo_keys(flags).expect("Unable to generate the cargo keys!");
|
||||
Ructe::from_env()
|
||||
.expect("ructe")
|
||||
.compile_templates("templates")
|
||||
.unwrap();
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
version: "3"
|
||||
version: "2"
|
||||
|
||||
services:
|
||||
hoc:
|
||||
@ -9,5 +9,3 @@ services:
|
||||
# ports:
|
||||
# - "127.0.0.1:8080:8080"
|
||||
restart: always
|
||||
env_file:
|
||||
- ./.env
|
||||
|
15
hoc.toml
15
hoc.toml
@ -1,15 +0,0 @@
|
||||
# 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"
|
@ -1,15 +0,0 @@
|
||||
# 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"
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": [
|
||||
"local>renovate-bot/renovate-config"
|
||||
]
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
{ pkgs ? import <nixpkgs> {} }:
|
||||
|
||||
pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
openssl
|
||||
pkg-config
|
||||
];
|
||||
}
|
12
src/build.rs
12
src/build.rs
@ -1,12 +0,0 @@
|
||||
use anyhow::Result;
|
||||
use ructe::Ructe;
|
||||
use vergen::EmitBuilder;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
EmitBuilder::builder().git_sha(true).emit()?;
|
||||
|
||||
let mut ructe = Ructe::from_env()?;
|
||||
let mut statics = ructe.statics()?;
|
||||
statics.add_files("static")?;
|
||||
Ok(ructe.compile_templates("templates")?)
|
||||
}
|
96
src/cache.rs
96
src/cache.rs
@ -1,123 +1,57 @@
|
||||
use crate::error::{Error, Result};
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
collections::HashMap,
|
||||
fs::{create_dir_all, File, OpenOptions},
|
||||
io::BufReader,
|
||||
path::Path,
|
||||
};
|
||||
|
||||
/// Enum to indicate the state of the cache
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum CacheState<'a> {
|
||||
/// Current head and cached head are the same
|
||||
Current {
|
||||
count: u64,
|
||||
commits: u64,
|
||||
cache: Cache<'a>,
|
||||
},
|
||||
Current { count: u64, commits: u64 },
|
||||
/// Cached head is older than current head
|
||||
Old {
|
||||
head: String,
|
||||
cache: Cache<'a>,
|
||||
},
|
||||
NoneForBranch(Cache<'a>),
|
||||
Old(Cache<'a>),
|
||||
/// No cache was found
|
||||
No,
|
||||
}
|
||||
|
||||
impl<'a> CacheState<'a> {
|
||||
#[instrument]
|
||||
pub(crate) fn read_from_file(
|
||||
path: impl AsRef<Path> + std::fmt::Debug,
|
||||
branch: &str,
|
||||
head: &str,
|
||||
) -> Result<CacheState<'a>> {
|
||||
trace!("Reading cache");
|
||||
pub(crate) fn read_from_file(path: impl AsRef<Path>, head: &str) -> Result<CacheState> {
|
||||
if path.as_ref().exists() {
|
||||
let cache: Cache = serde_json::from_reader(BufReader::new(File::open(path)?))?;
|
||||
Ok(cache.entries.get(branch).map_or_else(
|
||||
// TODO: get rid of clone
|
||||
|| CacheState::NoneForBranch(cache.clone()),
|
||||
|c| {
|
||||
if c.head == head {
|
||||
trace!("Cache is up to date");
|
||||
CacheState::Current {
|
||||
count: c.count,
|
||||
commits: c.commits,
|
||||
// TODO: get rid of clone
|
||||
cache: cache.clone(),
|
||||
}
|
||||
if cache.head == head {
|
||||
Ok(CacheState::Current {
|
||||
count: cache.count,
|
||||
commits: cache.commits,
|
||||
})
|
||||
} else {
|
||||
trace!("Cache is out of date");
|
||||
CacheState::Old {
|
||||
head: c.head.to_string(),
|
||||
// TODO: get rid of clone
|
||||
cache: cache.clone(),
|
||||
Ok(CacheState::Old(cache))
|
||||
}
|
||||
}
|
||||
},
|
||||
))
|
||||
} else {
|
||||
Ok(CacheState::No)
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
pub(crate) fn calculate_new_cache(
|
||||
self,
|
||||
count: u64,
|
||||
commits: u64,
|
||||
head: Cow<'a, str>,
|
||||
branch: &'a str,
|
||||
) -> Cache<'a> {
|
||||
trace!("Calculating new cache");
|
||||
pub(crate) fn calculate_new_cache(self, count: u64, commits: u64, head: Cow<'a, str>) -> Cache {
|
||||
match self {
|
||||
CacheState::Old { mut cache, .. } => {
|
||||
if let Some(cache) = cache.entries.get_mut(branch) {
|
||||
CacheState::Old(mut cache) => {
|
||||
cache.head = head;
|
||||
cache.count += count;
|
||||
cache.commits += commits;
|
||||
}
|
||||
cache
|
||||
}
|
||||
CacheState::Current { cache, .. } => cache,
|
||||
CacheState::NoneForBranch(mut cache) => {
|
||||
trace!("Creating new cache for branch");
|
||||
cache.entries.insert(
|
||||
branch.into(),
|
||||
CacheEntry {
|
||||
CacheState::No | CacheState::Current { .. } => Cache {
|
||||
head,
|
||||
count,
|
||||
commits,
|
||||
},
|
||||
);
|
||||
cache
|
||||
}
|
||||
CacheState::No => {
|
||||
trace!("Creating new cache file");
|
||||
let mut entries = HashMap::with_capacity(1);
|
||||
entries.insert(
|
||||
branch.into(),
|
||||
CacheEntry {
|
||||
head,
|
||||
count,
|
||||
commits,
|
||||
},
|
||||
);
|
||||
Cache { entries }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub(crate) struct Cache<'a> {
|
||||
pub entries: HashMap<Cow<'a, str>, CacheEntry<'a>>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub(crate) struct CacheEntry<'a> {
|
||||
/// HEAD commit ref
|
||||
pub head: Cow<'a, str>,
|
||||
/// HoC value
|
||||
@ -127,9 +61,7 @@ pub(crate) struct CacheEntry<'a> {
|
||||
}
|
||||
|
||||
impl<'a> Cache<'a> {
|
||||
#[instrument]
|
||||
pub(crate) fn write_to_file(&self, path: impl AsRef<Path> + std::fmt::Debug) -> Result<()> {
|
||||
trace!("Persisting cache to disk");
|
||||
pub(crate) fn write_to_file(&self, path: impl AsRef<Path>) -> Result<()> {
|
||||
create_dir_all(path.as_ref().parent().ok_or(Error::Internal)?)?;
|
||||
serde_json::to_writer(
|
||||
OpenOptions::new()
|
||||
|
@ -1,39 +1,71 @@
|
||||
use config::{Config, ConfigError, Environment, File};
|
||||
use crate::{error::Result, statics::OPT};
|
||||
use log::LevelFilter;
|
||||
use log4rs::{
|
||||
append::{console::ConsoleAppender, file::FileAppender},
|
||||
config::{Appender, Config, Root},
|
||||
encode::pattern::PatternEncoder,
|
||||
};
|
||||
use std::path::PathBuf;
|
||||
use structopt::StructOpt;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Settings {
|
||||
#[derive(StructOpt, Debug)]
|
||||
pub(crate) struct Opt {
|
||||
#[structopt(
|
||||
short = "o",
|
||||
long = "outdir",
|
||||
parse(from_os_str),
|
||||
default_value = "./repos"
|
||||
)]
|
||||
/// Path to store cloned repositories
|
||||
pub repodir: PathBuf,
|
||||
pub(crate) outdir: PathBuf,
|
||||
#[structopt(
|
||||
short = "c",
|
||||
long = "cachedir",
|
||||
parse(from_os_str),
|
||||
default_value = "./cache"
|
||||
)]
|
||||
/// Path to store cache
|
||||
pub cachedir: PathBuf,
|
||||
pub(crate) cachedir: PathBuf,
|
||||
#[structopt(short = "p", long = "port", default_value = "8080")]
|
||||
/// Port to listen on
|
||||
pub port: u16,
|
||||
pub(crate) port: u16,
|
||||
#[structopt(short = "h", long = "host", default_value = "0.0.0.0")]
|
||||
/// Interface to listen on
|
||||
pub host: String,
|
||||
/// Base URL
|
||||
pub base_url: String,
|
||||
pub(crate) host: String,
|
||||
#[structopt(short = "d", long = "domain", default_value = "hitsofcode.com")]
|
||||
/// Interface to listen on
|
||||
pub(crate) domain: String,
|
||||
#[structopt(short = "w", long = "workers", default_value = "4")]
|
||||
/// Number of worker threads
|
||||
pub workers: usize,
|
||||
pub(crate) workers: usize,
|
||||
#[structopt(
|
||||
short = "l",
|
||||
long = "logfile",
|
||||
parse(from_os_str),
|
||||
default_value = "./hoc.log"
|
||||
)]
|
||||
/// The logfile
|
||||
pub(crate) logfile: PathBuf,
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
/// Load the configuration from file and environment.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// * File cannot be read or parsed
|
||||
/// * Environment variables cannot be parsed
|
||||
pub fn load() -> Result<Self, ConfigError> {
|
||||
Config::builder()
|
||||
.add_source(File::with_name("hoc.toml").required(false))
|
||||
.add_source(Environment::with_prefix("hoc"))
|
||||
.set_default("repodir", "./repos")?
|
||||
.set_default("cachedir", "./cache")?
|
||||
.set_default("workers", 4)?
|
||||
.set_default("port", 8080)?
|
||||
.set_default("host", "0.0.0.0")?
|
||||
.build()?
|
||||
.try_deserialize()
|
||||
}
|
||||
pub(crate) fn init() -> Result<()> {
|
||||
std::env::set_var("RUST_LOG", "actix_web=info,hoc=info");
|
||||
// pretty_env_logger::init();
|
||||
openssl_probe::init_ssl_cert_env_vars();
|
||||
let stdout = ConsoleAppender::builder().build();
|
||||
let file = FileAppender::builder()
|
||||
.encoder(Box::new(PatternEncoder::new("{d} - {m}{n}")))
|
||||
.build(&OPT.logfile)
|
||||
.unwrap();
|
||||
let config = Config::builder()
|
||||
.appender(Appender::builder().build("stdout", Box::new(stdout)))
|
||||
.appender(Appender::builder().build("file", Box::new(file)))
|
||||
.build(
|
||||
Root::builder()
|
||||
.appender("stdout")
|
||||
.appender("file")
|
||||
.build(LevelFilter::Info),
|
||||
)?;
|
||||
log4rs::init_config(config)?;
|
||||
Ok(())
|
||||
}
|
||||
|
40
src/count.rs
40
src/count.rs
@ -1,30 +1,24 @@
|
||||
use crate::error::Result;
|
||||
use std::{
|
||||
fs::{read_dir, ReadDir},
|
||||
iter::once,
|
||||
path::Path,
|
||||
result::Result as StdResult,
|
||||
};
|
||||
use std::{fs::read_dir, 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]
|
||||
pub fn count_repositories<P>(repo_path: P) -> Result<usize>
|
||||
pub(crate) fn count_repositories<P>(repo_path: P) -> Result<usize>
|
||||
where
|
||||
P: AsRef<Path> + std::fmt::Debug,
|
||||
P: AsRef<Path>,
|
||||
{
|
||||
trace!("Counting repositories");
|
||||
std::fs::create_dir_all(&repo_path)?;
|
||||
Ok(once(read_dir(repo_path)?)
|
||||
.flat_map(sub_directories)
|
||||
.flat_map(sub_directories)
|
||||
.flat_map(sub_directories)
|
||||
.count())
|
||||
}
|
||||
|
||||
fn sub_directories(dir: ReadDir) -> impl Iterator<Item = ReadDir> {
|
||||
Ok(read_dir(repo_path)?
|
||||
.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))
|
||||
.filter_map(|entry| read_dir(entry.path()).ok())
|
||||
})
|
||||
.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())
|
||||
}
|
||||
|
57
src/error.rs
57
src/error.rs
@ -1,55 +1,52 @@
|
||||
use crate::{statics::VERSION_INFO, templates};
|
||||
use actix_web::{http::StatusCode, HttpResponse, ResponseError};
|
||||
use std::fmt;
|
||||
use crate::{
|
||||
statics::{REPO_COUNT, VERSION_INFO},
|
||||
templates,
|
||||
};
|
||||
use actix_web::{HttpResponse, ResponseError};
|
||||
use std::{fmt, sync::atomic::Ordering};
|
||||
|
||||
pub(crate) type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
pub(crate) enum Error {
|
||||
Badge(String),
|
||||
Client(reqwest::Error),
|
||||
Git(git2::Error),
|
||||
Internal,
|
||||
Io(std::io::Error),
|
||||
Log(log::SetLoggerError),
|
||||
LogBuilder(log4rs::config::Errors),
|
||||
Parse(std::num::ParseIntError),
|
||||
Serial(serde_json::Error),
|
||||
BranchNotFound,
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
Error::Badge(s) => write!(fmt, "Badge({s})"),
|
||||
Error::Client(e) => write!(fmt, "Client({e})"),
|
||||
Error::Git(e) => write!(fmt, "Git({e})"),
|
||||
Error::Badge(s) => write!(fmt, "Badge({})", s),
|
||||
Error::Client(e) => write!(fmt, "Client({})", e),
|
||||
Error::Git(e) => write!(fmt, "Git({})", e),
|
||||
Error::Internal => write!(fmt, "Internal Error"),
|
||||
Error::Io(e) => write!(fmt, "Io({e})"),
|
||||
Error::Parse(e) => write!(fmt, "Parse({e})"),
|
||||
Error::Serial(e) => write!(fmt, "Serial({e})"),
|
||||
Error::BranchNotFound => write!(fmt, "Repo doesn't have master branch"),
|
||||
Error::Io(e) => write!(fmt, "Io({})", e),
|
||||
Error::Log(e) => write!(fmt, "Log({})", e),
|
||||
Error::LogBuilder(e) => write!(fmt, "LogBuilder({})", e),
|
||||
Error::Parse(e) => write!(fmt, "Parse({})", e),
|
||||
Error::Serial(e) => write!(fmt, "Serial({})", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
if let Error::BranchNotFound = self {
|
||||
templates::p404_no_master_html(&mut buf, VERSION_INFO, 0).unwrap();
|
||||
HttpResponse::NotFound().content_type("text/html").body(buf)
|
||||
} else {
|
||||
templates::p500_html(&mut buf, VERSION_INFO, 0).unwrap();
|
||||
templates::p500(&mut buf, VERSION_INFO, REPO_COUNT.load(Ordering::Relaxed)).unwrap();
|
||||
HttpResponse::InternalServerError()
|
||||
.content_type("text/html")
|
||||
.body(buf)
|
||||
}
|
||||
|
||||
fn render_response(&self) -> HttpResponse {
|
||||
self.error_response()
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,6 +64,12 @@ impl From<git2::Error> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<log::SetLoggerError> for Error {
|
||||
fn from(err: log::SetLoggerError) -> Self {
|
||||
Error::Log(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for Error {
|
||||
fn from(err: std::io::Error) -> Self {
|
||||
Error::Io(err)
|
||||
@ -85,6 +88,12 @@ impl From<reqwest::Error> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<log4rs::config::Errors> for Error {
|
||||
fn from(err: log4rs::config::Errors) -> Self {
|
||||
Error::LogBuilder(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::num::ParseIntError> for Error {
|
||||
fn from(err: std::num::ParseIntError) -> Self {
|
||||
Error::Parse(err)
|
||||
|
555
src/lib.rs
555
src/lib.rs
@ -1,555 +0,0 @@
|
||||
#![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;
|
||||
pub mod count;
|
||||
mod error;
|
||||
mod service;
|
||||
mod statics;
|
||||
pub mod telemetry;
|
||||
mod template;
|
||||
|
||||
use crate::{
|
||||
cache::CacheState,
|
||||
config::Settings,
|
||||
error::{Error, Result},
|
||||
service::{Bitbucket, FormValue, GitHub, Gitlab, Service, Sourcehut},
|
||||
statics::{CLIENT, VERSION_INFO},
|
||||
template::{RepoGeneratorInfo, RepoInfo},
|
||||
};
|
||||
use actix_web::{
|
||||
dev::Server,
|
||||
http::header::{CacheControl, CacheDirective, Expires, LOCATION},
|
||||
middleware::{self, TrailingSlash},
|
||||
web, App, HttpResponse, HttpServer, Responder,
|
||||
};
|
||||
use badgers::{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 templates::statics::{self as template_statics, StaticFile};
|
||||
use tracing::Instrument;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/templates.rs"));
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
struct GeneratorForm<'a> {
|
||||
service: FormValue,
|
||||
user: Cow<'a, str>,
|
||||
repo: Cow<'a, str>,
|
||||
branch: Option<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 BadgeQuery {
|
||||
branch: Option<String>,
|
||||
#[serde(default = "default_label")]
|
||||
label: String,
|
||||
}
|
||||
|
||||
fn default_label() -> String {
|
||||
"Hits-of-Code".to_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!("{cache_dir}/{repo}.json");
|
||||
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!("{}/{repo}.json", &state.cache());
|
||||
let repo_dir = format!("{}/{repo}", &state.repos());
|
||||
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!("{}/{repo}", T::url_path());
|
||||
let service_url = format!("{}/{repo}", T::domain());
|
||||
let path = format!("{}/{service_url}", state.repos());
|
||||
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)?;
|
||||
#[allow(clippy::cast_precision_loss)]
|
||||
let hoc_pretty = match NumberPrefix::decimal(hoc as f64) {
|
||||
NumberPrefix::Standalone(hoc) => hoc.to_string(),
|
||||
NumberPrefix::Prefixed(prefix, hoc) => format!("{hoc:.1}{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<BadgeQuery>,
|
||||
) -> 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)>,
|
||||
query: web::Query<BadgeQuery>,
|
||||
) -> HttpResponse {
|
||||
let rc_clone = repo_count.clone();
|
||||
let label = query.label.clone();
|
||||
let mapper = move |r| match r {
|
||||
HocResult::NotFound => p404(&rc_clone),
|
||||
HocResult::Hoc { hoc_pretty, .. } => {
|
||||
let badge_opt = BadgeOptions {
|
||||
subject: label,
|
||||
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 = query.branch.as_deref().unwrap_or("master");
|
||||
let error_badge = |_| {
|
||||
let error_badge = Badge::new(BadgeOptions {
|
||||
subject: query.label.clone(),
|
||||
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)>,
|
||||
query: web::Query<BadgeQuery>,
|
||||
) -> Result<HttpResponse> {
|
||||
let branch = query.branch.as_deref().unwrap_or("master");
|
||||
let label = query.label.clone();
|
||||
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_html(
|
||||
&mut buf,
|
||||
VERSION_INFO,
|
||||
rc_clone.load(Ordering::Relaxed),
|
||||
repo_info,
|
||||
&label,
|
||||
)?;
|
||||
|
||||
Ok(HttpResponse::Ok().content_type("text/html").body(buf))
|
||||
}
|
||||
};
|
||||
handle_hoc_request::<T, _>(state, repo_count, data, branch, mapper).await
|
||||
}
|
||||
|
||||
#[get("/health_check")]
|
||||
#[allow(clippy::unused_async)]
|
||||
async fn health_check() -> HttpResponse {
|
||||
HttpResponse::Ok().finish()
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
#[allow(clippy::unused_async)]
|
||||
async fn index(
|
||||
state: web::Data<State>,
|
||||
repo_count: web::Data<AtomicUsize>,
|
||||
) -> Result<HttpResponse> {
|
||||
let mut buf = Vec::new();
|
||||
templates::index_html(
|
||||
&mut buf,
|
||||
VERSION_INFO,
|
||||
repo_count.load(Ordering::Relaxed),
|
||||
&state.settings.base_url,
|
||||
)?;
|
||||
Ok(HttpResponse::Ok().content_type("text/html").body(buf))
|
||||
}
|
||||
|
||||
#[post("/generate")]
|
||||
#[allow(clippy::unused_async)]
|
||||
async fn generate(
|
||||
params: web::Form<GeneratorForm<'_>>,
|
||||
state: web::Data<State>,
|
||||
repo_count: web::Data<AtomicUsize>,
|
||||
) -> Result<HttpResponse> {
|
||||
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_html(
|
||||
&mut buf,
|
||||
VERSION_INFO,
|
||||
repo_count.load(Ordering::Relaxed),
|
||||
&state.settings.base_url,
|
||||
&repo_info,
|
||||
)?;
|
||||
|
||||
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_html(&mut buf, VERSION_INFO, repo_count.load(Ordering::Relaxed))?;
|
||||
Ok(HttpResponse::NotFound().content_type("text/html").body(buf))
|
||||
}
|
||||
|
||||
#[allow(clippy::unused_async)]
|
||||
async fn async_p404(repo_count: web::Data<AtomicUsize>) -> Result<HttpResponse> {
|
||||
p404(&repo_count)
|
||||
}
|
||||
|
||||
/// A duration to add to current time for a far expires header.
|
||||
static FAR: Duration = Duration::from_secs(180 * 24 * 60 * 60);
|
||||
|
||||
#[get("/static/{filename}")]
|
||||
#[allow(clippy::unused_async)]
|
||||
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_or_else(|| p404(&repo_count), Result::Ok)
|
||||
}
|
||||
|
||||
#[get("/favicon.ico")]
|
||||
#[allow(clippy::unused_async)]
|
||||
async fn favicon32() -> HttpResponse {
|
||||
let data = &template_statics::favicon32_png;
|
||||
HttpResponse::Ok()
|
||||
.content_type(data.mime.clone())
|
||||
.body(data.content)
|
||||
}
|
||||
|
||||
#[allow(clippy::unused_async)]
|
||||
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 || {
|
||||
let app = 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(static_file)
|
||||
.service(favicon32)
|
||||
.service(generate)
|
||||
.default_service(web::to(async_p404));
|
||||
let app = GitHub::register_service(app);
|
||||
let app = Gitlab::register_service(app);
|
||||
let app = Bitbucket::register_service(app);
|
||||
Sourcehut::register_service(app)
|
||||
})
|
||||
.workers(workers)
|
||||
.listen(listener)?
|
||||
.run())
|
||||
}
|
||||
|
||||
/// Start the server.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// * server cannot bind to `listener`
|
||||
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
|
||||
}
|
396
src/main.rs
396
src/main.rs
@ -1,26 +1,382 @@
|
||||
use hoc::{config::Settings, telemetry};
|
||||
#![type_length_limit = "2257138"]
|
||||
|
||||
use std::net::TcpListener;
|
||||
#[macro_use]
|
||||
extern crate actix_web;
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
fn init() {
|
||||
dotenvy::dotenv().ok();
|
||||
openssl_probe::init_ssl_cert_env_vars();
|
||||
mod cache;
|
||||
mod config;
|
||||
mod count;
|
||||
mod error;
|
||||
mod service;
|
||||
mod statics;
|
||||
|
||||
telemetry::init_subscriber(telemetry::get_subscriber("hoc", "info"));
|
||||
use crate::{
|
||||
cache::CacheState,
|
||||
error::{Error, Result},
|
||||
service::{Bitbucket, FormService, GitHub, Gitlab, Service},
|
||||
statics::{CLIENT, CSS, FAVICON, OPT, REPO_COUNT, VERSION_INFO},
|
||||
};
|
||||
use actix_web::{
|
||||
error::ErrorBadRequest,
|
||||
http::header::{CacheControl, CacheDirective, Expires},
|
||||
middleware, web, App, HttpResponse, HttpServer,
|
||||
};
|
||||
use badge::{Badge, BadgeOptions};
|
||||
use bytes::Bytes;
|
||||
use futures::{unsync::mpsc, Future, Stream};
|
||||
use git2::Repository;
|
||||
use number_prefix::{NumberPrefix, Prefixed, Standalone};
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
fs::create_dir_all,
|
||||
path::Path,
|
||||
process::Command,
|
||||
sync::atomic::Ordering,
|
||||
sync::Arc,
|
||||
time::{Duration, SystemTime},
|
||||
};
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/templates.rs"));
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
struct GeneratorForm<'a> {
|
||||
service: FormService,
|
||||
user: Cow<'a, str>,
|
||||
repo: Cow<'a, str>,
|
||||
}
|
||||
|
||||
#[actix_rt::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
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
|
||||
struct State {
|
||||
repos: String,
|
||||
cache: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct JsonResponse<'a> {
|
||||
head: &'a str,
|
||||
count: u64,
|
||||
commits: u64,
|
||||
}
|
||||
|
||||
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) -> 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)?;
|
||||
let head = format!("{}", repo.head()?.target().ok_or(Error::Internal)?);
|
||||
let mut arg_commit_count = vec!["rev-list".to_string(), "--count".to_string()];
|
||||
let mut arg = vec![
|
||||
"log".to_string(),
|
||||
"--pretty=tformat:".to_string(),
|
||||
"--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, &head)?;
|
||||
match &cache {
|
||||
CacheState::Current { count, commits } => {
|
||||
info!("Using cache for {}", repo_dir);
|
||||
return Ok((*count, head, *commits));
|
||||
}
|
||||
CacheState::Old(cache) => {
|
||||
info!("Updating cache for {}", repo_dir);
|
||||
arg.push(format!("{}..HEAD", cache.head));
|
||||
arg_commit_count.push(format!("{}..HEAD", cache.head));
|
||||
}
|
||||
CacheState::No => {
|
||||
info!("Creating cache for {}", repo_dir);
|
||||
arg_commit_count.push("HEAD".to_string());
|
||||
}
|
||||
};
|
||||
arg.push("--".to_string());
|
||||
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());
|
||||
cache.write_to_file(cache_dir)?;
|
||||
|
||||
Ok((cache.count, head, commits))
|
||||
}
|
||||
|
||||
fn remote_exists(url: &str) -> impl Future<Item = bool, Error = Error> {
|
||||
CLIENT
|
||||
.head(url)
|
||||
.send()
|
||||
.map(|resp| resp.status() == reqwest::StatusCode::OK)
|
||||
.from_err()
|
||||
}
|
||||
|
||||
enum HocResult {
|
||||
Hoc {
|
||||
hoc: u64,
|
||||
commits: u64,
|
||||
hoc_pretty: String,
|
||||
head: String,
|
||||
url: String,
|
||||
repo: String,
|
||||
service_path: String,
|
||||
},
|
||||
NotFound,
|
||||
}
|
||||
|
||||
fn handle_hoc_request<T, F>(
|
||||
state: web::Data<Arc<State>>,
|
||||
data: web::Path<(String, String)>,
|
||||
mapper: F,
|
||||
) -> impl Future<Item = HttpResponse, Error = Error>
|
||||
where
|
||||
T: Service,
|
||||
F: Fn(HocResult) -> Result<HttpResponse>,
|
||||
{
|
||||
let repo = format!("{}/{}", data.0.to_lowercase(), data.1.to_lowercase());
|
||||
let service_path = format!("{}/{}", T::domain(), repo);
|
||||
let path = format!("{}/{}", state.repos, service_path);
|
||||
let url = format!("https://{}", service_path);
|
||||
remote_exists(&url)
|
||||
.and_then(move |remote_exists| {
|
||||
let file = Path::new(&path);
|
||||
if !file.exists() {
|
||||
if !remote_exists {
|
||||
warn!("Repository does not exist: {}", url);
|
||||
return Ok(HocResult::NotFound);
|
||||
}
|
||||
info!("Cloning {} for the first time", url);
|
||||
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_path, &state.repos, &state.cache)?;
|
||||
let hoc_pretty = match NumberPrefix::decimal(hoc as f64) {
|
||||
Standalone(hoc) => hoc.to_string(),
|
||||
Prefixed(prefix, hoc) => format!("{:.1}{}", hoc, prefix),
|
||||
};
|
||||
Ok(HocResult::Hoc {
|
||||
hoc,
|
||||
commits,
|
||||
hoc_pretty,
|
||||
head: head.to_string(),
|
||||
url,
|
||||
repo,
|
||||
service_path,
|
||||
})
|
||||
})
|
||||
.and_then(mapper)
|
||||
}
|
||||
|
||||
fn json_hoc<T: Service>(
|
||||
state: web::Data<Arc<State>>,
|
||||
data: web::Path<(String, String)>,
|
||||
) -> impl Future<Item = HttpResponse, Error = Error> {
|
||||
let mapper = |r| match r {
|
||||
HocResult::NotFound => p404(),
|
||||
HocResult::Hoc {
|
||||
hoc, head, commits, ..
|
||||
} => Ok(HttpResponse::Ok().json(JsonResponse {
|
||||
head: &head,
|
||||
count: hoc,
|
||||
commits,
|
||||
})),
|
||||
};
|
||||
handle_hoc_request::<T, _>(state, data, mapper)
|
||||
}
|
||||
|
||||
fn calculate_hoc<T: Service>(
|
||||
state: web::Data<Arc<State>>,
|
||||
data: web::Path<(String, String)>,
|
||||
) -> impl Future<Item = HttpResponse, Error = Error> {
|
||||
let mapper = |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)?;
|
||||
|
||||
let (tx, rx_body) = mpsc::unbounded();
|
||||
let _ = tx.unbounded_send(Bytes::from(badge.to_svg().as_bytes()));
|
||||
|
||||
let expiration = SystemTime::now() + Duration::from_secs(30);
|
||||
Ok(HttpResponse::Ok()
|
||||
.content_type("image/svg+xml")
|
||||
.set(Expires(expiration.into()))
|
||||
.set(CacheControl(vec![
|
||||
CacheDirective::MaxAge(0u32),
|
||||
CacheDirective::MustRevalidate,
|
||||
CacheDirective::NoCache,
|
||||
CacheDirective::NoStore,
|
||||
]))
|
||||
.streaming(rx_body.map_err(|_| ErrorBadRequest("bad request"))))
|
||||
}
|
||||
};
|
||||
handle_hoc_request::<T, _>(state, data, mapper)
|
||||
}
|
||||
|
||||
fn overview<T: Service>(
|
||||
state: web::Data<Arc<State>>,
|
||||
data: web::Path<(String, String)>,
|
||||
) -> impl Future<Item = HttpResponse, Error = Error> {
|
||||
let mapper = |r| match r {
|
||||
HocResult::NotFound => p404(),
|
||||
HocResult::Hoc {
|
||||
hoc,
|
||||
commits,
|
||||
hoc_pretty,
|
||||
url,
|
||||
head,
|
||||
repo,
|
||||
service_path,
|
||||
} => {
|
||||
let mut buf = Vec::new();
|
||||
templates::overview(
|
||||
&mut buf,
|
||||
VERSION_INFO,
|
||||
REPO_COUNT.load(Ordering::Relaxed),
|
||||
&OPT.domain,
|
||||
&service_path,
|
||||
&url,
|
||||
hoc,
|
||||
&hoc_pretty,
|
||||
&head,
|
||||
&T::commit_url(&repo, &head),
|
||||
commits,
|
||||
)?;
|
||||
|
||||
let (tx, rx_body) = mpsc::unbounded();
|
||||
let _ = tx.unbounded_send(Bytes::from(buf));
|
||||
|
||||
Ok(HttpResponse::Ok()
|
||||
.content_type("text/html")
|
||||
.streaming(rx_body.map_err(|_| ErrorBadRequest("bad request"))))
|
||||
}
|
||||
};
|
||||
handle_hoc_request::<T, _>(state, data, mapper)
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
fn index() -> Result<HttpResponse> {
|
||||
let mut buf = Vec::new();
|
||||
templates::index(
|
||||
&mut buf,
|
||||
VERSION_INFO,
|
||||
REPO_COUNT.load(Ordering::Relaxed),
|
||||
&OPT.domain,
|
||||
)?;
|
||||
Ok(HttpResponse::Ok().content_type("text/html").body(buf))
|
||||
}
|
||||
|
||||
#[post("/generate")]
|
||||
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.domain,
|
||||
params.service.url(),
|
||||
params.service.service(),
|
||||
&repo,
|
||||
)?;
|
||||
let (tx, rx_body) = mpsc::unbounded();
|
||||
let _ = tx.unbounded_send(Bytes::from(buf));
|
||||
|
||||
Ok(HttpResponse::Ok()
|
||||
.content_type("text/html")
|
||||
.streaming(rx_body.map_err(|_| ErrorBadRequest("bad request"))))
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
|
||||
#[get("/tacit-css.min.css")]
|
||||
fn css() -> HttpResponse {
|
||||
HttpResponse::Ok().content_type("text/css").body(CSS)
|
||||
}
|
||||
|
||||
#[get("/favicon.ico")]
|
||||
fn favicon32() -> HttpResponse {
|
||||
HttpResponse::Ok().content_type("image/png").body(FAVICON)
|
||||
}
|
||||
|
||||
fn start_server() -> Result<()> {
|
||||
let interface = format!("{}:{}", OPT.host, OPT.port);
|
||||
let state = Arc::new(State {
|
||||
repos: OPT.outdir.display().to_string(),
|
||||
cache: OPT.cachedir.display().to_string(),
|
||||
});
|
||||
Ok(HttpServer::new(move || {
|
||||
App::new()
|
||||
.data(state.clone())
|
||||
.wrap(middleware::Logger::default())
|
||||
.wrap(middleware::NormalizePath)
|
||||
.service(index)
|
||||
.service(css)
|
||||
.service(favicon32)
|
||||
.service(generate)
|
||||
.service(web::resource("/github/{user}/{repo}").to_async(calculate_hoc::<GitHub>))
|
||||
.service(web::resource("/gitlab/{user}/{repo}").to_async(calculate_hoc::<Gitlab>))
|
||||
.service(web::resource("/bitbucket/{user}/{repo}").to_async(calculate_hoc::<Bitbucket>))
|
||||
.service(web::resource("/github/{user}/{repo}/json").to_async(json_hoc::<GitHub>))
|
||||
.service(web::resource("/gitlab/{user}/{repo}/json").to_async(json_hoc::<Gitlab>))
|
||||
.service(web::resource("/bitbucket/{user}/{repo}/json").to_async(json_hoc::<Bitbucket>))
|
||||
.service(web::resource("/view/github/{user}/{repo}").to_async(overview::<GitHub>))
|
||||
.service(web::resource("/view/gitlab/{user}/{repo}").to_async(overview::<Gitlab>))
|
||||
.service(web::resource("/view/bitbucket/{user}/{repo}").to_async(overview::<Bitbucket>))
|
||||
.default_service(web::resource("").route(web::get().to_async(p404)))
|
||||
})
|
||||
.workers(OPT.workers)
|
||||
.bind(interface)?
|
||||
.run()?)
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
config::init()?;
|
||||
start_server()
|
||||
}
|
||||
|
@ -1,61 +1,33 @@
|
||||
use crate::{calculate_hoc, delete_repo_and_cache, json_hoc, overview};
|
||||
|
||||
use actix_web::{
|
||||
dev::{ServiceFactory, ServiceRequest},
|
||||
web, App,
|
||||
};
|
||||
|
||||
pub(crate) trait Service: Sized + 'static {
|
||||
pub(crate) trait Service {
|
||||
fn domain() -> &'static str;
|
||||
fn url_path() -> &'static str;
|
||||
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)]
|
||||
pub enum FormValue {
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub(crate) enum FormService {
|
||||
#[serde(rename = "github")]
|
||||
GitHub,
|
||||
#[serde(rename = "gitlab")]
|
||||
Gitlab,
|
||||
#[serde(rename = "bitbucket")]
|
||||
Bitbucket,
|
||||
#[serde(rename = "sourcehut")]
|
||||
Sourcehut,
|
||||
}
|
||||
|
||||
impl FormValue {
|
||||
impl FormService {
|
||||
pub(crate) fn url(&self) -> &str {
|
||||
match self {
|
||||
FormValue::GitHub => "github.com",
|
||||
FormValue::Gitlab => "gitlab.com",
|
||||
FormValue::Bitbucket => "bitbucket.org",
|
||||
FormValue::Sourcehut => "git.sr.ht",
|
||||
FormService::GitHub => "github.com",
|
||||
FormService::Gitlab => "gitlab.com",
|
||||
FormService::Bitbucket => "bitbucket.org",
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn service(&self) -> &str {
|
||||
match self {
|
||||
FormValue::GitHub => "github",
|
||||
FormValue::Gitlab => "gitlab",
|
||||
FormValue::Bitbucket => "bitbucket",
|
||||
FormValue::Sourcehut => "sourcehut",
|
||||
FormService::GitHub => "github",
|
||||
FormService::Gitlab => "gitlab",
|
||||
FormService::Bitbucket => "bitbucket",
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -101,17 +73,3 @@ 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)
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,22 @@
|
||||
#[derive(Clone, Copy)]
|
||||
use crate::{config::Opt, count::count_repositories};
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use structopt::StructOpt;
|
||||
|
||||
pub struct VersionInfo<'a> {
|
||||
pub commit: &'a str,
|
||||
pub version: &'a str,
|
||||
}
|
||||
|
||||
pub(crate) const VERSION_INFO: VersionInfo = VersionInfo {
|
||||
commit: env!("VERGEN_GIT_SHA"),
|
||||
commit: env!("VERGEN_SHA_SHORT"),
|
||||
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! {
|
||||
pub(crate) static ref CLIENT: reqwest::Client = reqwest::Client::new();
|
||||
pub(crate) static ref CLIENT: reqwest::r#async::Client = reqwest::r#async::Client::new();
|
||||
pub(crate) static ref OPT: Opt = Opt::from_args();
|
||||
pub(crate) static ref REPO_COUNT: AtomicUsize =
|
||||
AtomicUsize::new(count_repositories(&OPT.outdir).unwrap());
|
||||
}
|
||||
|
@ -1,25 +0,0 @@
|
||||
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)
|
||||
}
|
||||
|
||||
/// # Panics
|
||||
///
|
||||
/// This panics if the `LogTracer` cannot be initialized or `subscriber` cannot be set as global
|
||||
/// default.
|
||||
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");
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
use crate::service::FormValue;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct RepoInfo<'a> {
|
||||
pub commit_url: &'a str,
|
||||
pub commits: u64,
|
||||
pub base_url: &'a str,
|
||||
pub head: &'a str,
|
||||
pub hoc: u64,
|
||||
pub hoc_pretty: &'a str,
|
||||
pub path: &'a str,
|
||||
pub url: &'a str,
|
||||
pub branch: &'a str,
|
||||
}
|
||||
|
||||
pub struct RepoGeneratorInfo<'a> {
|
||||
pub service: FormValue,
|
||||
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::tacit_css_min_css;
|
||||
@use crate::statics::VersionInfo;
|
||||
|
||||
@(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="keywords" content="Hits-of-Code, GitHub, Badge" />
|
||||
<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>
|
||||
</head>
|
||||
<body>
|
||||
|
@ -1,16 +1,16 @@
|
||||
@use super::base_html;
|
||||
@use crate::{statics::VersionInfo, template::RepoGeneratorInfo};
|
||||
@use super::base;
|
||||
@use crate::statics::VersionInfo;
|
||||
|
||||
@(version_info: VersionInfo, repo_count: usize, base_url: &str, repo_info: &RepoGeneratorInfo)
|
||||
@(version_info: VersionInfo, repo_count: usize, domain: &str, url: &str, service: &str, path: &str)
|
||||
|
||||
@:base_html("Hits-of-Code Badges", "Badge Generator", {
|
||||
@:base("Hits-of-Code Badges", "Badge Generator", {
|
||||
|
||||
<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>
|
||||
|
||||
<pre>
|
||||
[![Hits-of-Code](@base_url/@repo_info.service.service()/@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)
|
||||
[![Hits-of-Code](https://@domain/@service/@path)](https://@domain/view/@service/@path)
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
@ -18,6 +18,6 @@ It will be rendered like this
|
||||
</p>
|
||||
|
||||
<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="https://@domain/view/@service/@path"><img src="https://@domain/@service/@path" alt="example badge" /></a>
|
||||
</pre>
|
||||
}, version_info, repo_count)
|
||||
|
@ -1,9 +1,9 @@
|
||||
@use super::base_html;
|
||||
@use super::base;
|
||||
@use crate::statics::VersionInfo;
|
||||
|
||||
@(version_info: VersionInfo, repo_count: usize, base_url: &str)
|
||||
@(version_info: VersionInfo, repo_count: usize, domain: &str)
|
||||
|
||||
@:base_html("Hits-of-Code Badges", "Hits-of-Code Badges", {
|
||||
@:base("Hits-of-Code Badges", "Hits-of-Code Badges", {
|
||||
|
||||
<p>
|
||||
This API offers badges for the Hits-of-Code metric for your repositories. This metric was proposed by
|
||||
@ -20,20 +20,20 @@ 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, 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>
|
||||
|
||||
<pre>
|
||||
[![Hits-of-Code](@base_url/<service>/<user>/<repo>)](@base_url/<service>/<user>/<repo>/view)
|
||||
[![Hits-of-Code](https://@domain/<service>/<user>/<repo>)](https://@domain/view/<service>/<user>/<repo>)
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
where <code><service></code> is one of <code>github</code>, <code>gitlab</code>, <code>bitbucket</code> or
|
||||
<code>sourcehut</code>. So the following Markdown
|
||||
where <code><service></code> is one of <code>github</code>, <code>gitlab</code> or <code>bitbucket</code>. So the
|
||||
following Markdown
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
[![Hits-of-Code](@base_url/github/vbrandl/hoc)](@base_url/github/vbrandl/hoc/view)
|
||||
[![Hits-of-Code](https://@domain/github/vbrandl/hoc)](https://@domain/view/github/vbrandl/hoc)
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
@ -41,25 +41,15 @@ would render this badge:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
<a href="@base_url/github/vbrandl/hoc/view"><img src="@base_url/github/vbrandl/hoc"
|
||||
<a href="https://@domain/view/github/vbrandl/hoc"><img src="https://@domain/github/vbrandl/hoc"
|
||||
alt="example badge" /></a>
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
By default, this service assumes the existence of a branch named <code>master</code>. If no branch with that name exists
|
||||
in your repository or you want a badge for another branch of your repository, just append
|
||||
<code>?branch=<branch-name></code> to the URL.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The badge label can be customized using the <code>label=<some-label></code> query parameter. It defaults to <code>Hits-of-Code</code>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
You can also request the HoC as JSON by appending <code>/json</code> to the request path. This will return a JSON object
|
||||
with three fields: <code>count</code> (the HoC value), <code>commits</code> (the number of commits) and
|
||||
<code>head</code> (the commit ref of HEAD). Requesting <a
|
||||
href="@base_url/github/vbrandl/hoc/json">@base_url/github/vbrandl/hoc/json</a> might return something along
|
||||
href="https://@domain/github/vbrandl/hoc/json">https://@domain/github/vbrandl/hoc/json</a> might return something along
|
||||
the lines of
|
||||
</p>
|
||||
|
||||
@ -78,14 +68,11 @@ 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" />
|
||||
<label>/</label>
|
||||
<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>
|
||||
</form>
|
||||
|
||||
@ -101,7 +88,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://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
|
||||
keyserver</a>), or by using any other UID from my key.
|
||||
</p>
|
||||
|
@ -1,17 +1,13 @@
|
||||
@use super::base_html;
|
||||
@use super::base;
|
||||
@use crate::statics::VersionInfo;
|
||||
@use crate::template::RepoInfo;
|
||||
|
||||
@(version_info: VersionInfo, repo_count: usize, repo_info: RepoInfo, label: &str)
|
||||
@(version_info: VersionInfo, repo_count: usize, domain: &str, path: &str, url: &str, hoc: u64, hoc_pretty: &str, head: &str, commit_url: &str, commits: u64)
|
||||
|
||||
@:base_html("Hits-of-Code Badges", "Overview", {
|
||||
@:base("Hits-of-Code Badges", "Overview", {
|
||||
|
||||
<p>
|
||||
The project <a href="@repo_info.url">@repo_info.url</a> has
|
||||
<strong>@repo_info.hoc_pretty</strong> (exactly @repo_info.hoc) hits of code at
|
||||
<a href="@repo_info.commit_url">@repo_info.head</a> on the
|
||||
<code>@repo_info.branch</code> branch. The repository contains
|
||||
<strong>@repo_info.commits</strong> commits.
|
||||
The project <a href="@url">@url</a> has <strong>@hoc_pretty</strong> (exactly @hoc) hits of code at
|
||||
<a href="@commit_url">@head</a>. The repository contains <strong>@commits</strong> commits.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
@ -19,11 +15,6 @@ To include the badge in your readme, use the following markdown:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
[![@label](@repo_info.base_url/@repo_info.path?branch=@repo_info.branch&label=@label)](@repo_info.base_url/@repo_info.path/view?branch=@repo_info.branch&label=@label)
|
||||
[![Hits-of-Code](https://@domain/@path)](https://@domain/view/@path)
|
||||
</pre>
|
||||
|
||||
|
||||
<form method="post" action="/@repo_info.path/delete">
|
||||
<button type="submit">Rebuild Cache</button>
|
||||
</form>
|
||||
}, version_info, repo_count)
|
||||
|
@ -1,9 +1,9 @@
|
||||
@use super::base_html;
|
||||
@use super::base;
|
||||
@use crate::statics::VersionInfo;
|
||||
|
||||
@(version_info: VersionInfo, repo_count: usize)
|
||||
|
||||
@:base_html("Page not Found - Hits-of-Code Badges", "404 - Page not Found", {
|
||||
@:base("Page not Found - Hits-of-Code Badges", "404 - Page not Found", {
|
||||
<p>
|
||||
<big>Sorry</big>. I couldn't find the page you are looking for. Please go <a href="/">back to the homepage</a>.
|
||||
</p>
|
||||
|
@ -1,16 +0,0 @@
|
||||
@use super::base_html;
|
||||
@use crate::statics::VersionInfo;
|
||||
|
||||
@(version_info: VersionInfo, repo_count: usize)
|
||||
|
||||
@:base_html("Branch not Found - Hits-of-Code Badges", "404 - Branch not Found", {
|
||||
<p>
|
||||
<big>Sorry</big>. I couldn't find the requested branch of your repositroy. Currently this service assumes the
|
||||
extistence of a branch named <code>master</code>. If you'd like to request a badge for another branch, you can do so by
|
||||
attaching <code>?branch=<branch-name></code> to the request.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
If you think, this is a mistake on my side, please <a href="mailto:mail+hoc@@vbrandl.net">drop me a mail</a>.
|
||||
</p>
|
||||
}, version_info, repo_count)
|
@ -1,9 +1,9 @@
|
||||
@use super::base_html;
|
||||
@use super::base;
|
||||
@use crate::statics::VersionInfo;
|
||||
|
||||
@(version_info: VersionInfo, repo_count: usize)
|
||||
|
||||
@:base_html("Internal Server Error - Hits-of-Code Badges", "500 - Internal Server Error", {
|
||||
@:base("Internal Server Error - Hits-of-Code Badges", "500 - Internal Server Error", {
|
||||
<p>
|
||||
<big>Oops</big>. Looks like a made a mistake. Please go <a href="/">back to the homepage</a> and try again.
|
||||
</p>
|
||||
|
@ -1,16 +0,0 @@
|
||||
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());
|
||||
}
|
@ -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,16 +0,0 @@
|
||||
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());
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
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());
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
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());
|
||||
}
|
@ -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());
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
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,
|
||||
// Those are unused but are hold to be dropped and deleted after the TestApp goes out of scope
|
||||
_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();
|
||||
|
||||
let server = hoc::run(listener, settings)
|
||||
.await
|
||||
.expect("Failed to bind address");
|
||||
|
||||
#[allow(clippy::let_underscore_future)]
|
||||
// don't await so the test server runs in the background
|
||||
let _ = tokio::spawn(server);
|
||||
|
||||
TestApp {
|
||||
address,
|
||||
_repo_dir: repo_dir,
|
||||
_cache_dir: cache_dir,
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user