Compare commits
69 Commits
Author | SHA1 | Date | |
---|---|---|---|
7fc920cddd | |||
c1ea45d517 | |||
0b729da42f | |||
c0d0aa2176 | |||
41159c4ba4 | |||
b40b6bcad2 | |||
6e86f49585 | |||
c8c73b6b83 | |||
c6cc956f4d | |||
e37489d2cb | |||
8246be996e | |||
1f32f3eda4 | |||
ab6c317241 | |||
1223d429db | |||
9613aa7848 | |||
334fa8ced5 | |||
062343dd32 | |||
bdb2a151fa | |||
7e66393966 | |||
32ac5ca0d8 | |||
b3b4cd0e42 | |||
be08b87bbb | |||
cf4d427b96 | |||
b5ebc54372 | |||
231741629e | |||
135c5756b1 | |||
79cfee5fa5 | |||
1c9b5db4e1 | |||
6e0e452395 | |||
9e44731650 | |||
f673d71387 | |||
eda1822dce | |||
fb64af3456 | |||
0837284798 | |||
a7039f15b5 | |||
b1be281982 | |||
2795995f58 | |||
913cc9dc75 | |||
645d6e4a2b | |||
e455a89de4 | |||
f2cae46624 | |||
f47cbbe81a | |||
85f90c0bdb | |||
9143e5dbf8 | |||
865e3c7bbd | |||
5ebdd4067c | |||
55a1405e71 | |||
1436336b6a | |||
5a74306e49 | |||
614e5a6da5 | |||
0128e267cc | |||
c3dffac5da | |||
aaaff22907 | |||
ddfcbf11f1 | |||
3bee454548 | |||
9cff6f1f13 | |||
c946c5d0b4 | |||
88ae90af95 | |||
9f783dffa8 | |||
2cdf64ed80 | |||
9e024b530e | |||
0db7b26541 | |||
009d2c4813 | |||
f0ed6c2e23 | |||
d16a21e74e | |||
7e721ac212 | |||
4eb5d06cd1 | |||
b71207ca51 | |||
f3902f800f |
15
.github/workflows/rust.yml
vendored
Normal file
15
.github/workflows/rust.yml
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
name: Rust
|
||||||
|
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- name: Build
|
||||||
|
run: cargo build --verbose
|
||||||
|
- name: Run tests
|
||||||
|
run: cargo test --verbose
|
@ -1,6 +1,6 @@
|
|||||||
image: docker:stable
|
image: docker:19.03
|
||||||
services:
|
services:
|
||||||
- docker:dind
|
- docker:19.03-dind
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- build
|
- build
|
||||||
@ -9,6 +9,8 @@ stages:
|
|||||||
variables:
|
variables:
|
||||||
DOCKER_HOST: tcp://docker:2375
|
DOCKER_HOST: tcp://docker:2375
|
||||||
DOCKER_DRIVER: overlay2
|
DOCKER_DRIVER: overlay2
|
||||||
|
# DOCKER_TLS_CERTDIR: "/certs"
|
||||||
|
DOCKER_TLS_CERTDIR: ""
|
||||||
CONTAINER_BUILDER_IMAGE: $CI_REGISTRY_IMAGE:builder-latest
|
CONTAINER_BUILDER_IMAGE: $CI_REGISTRY_IMAGE:builder-latest
|
||||||
CONTAINER_TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
|
CONTAINER_TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
|
||||||
CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
|
CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
|
||||||
|
731
Cargo.lock
generated
731
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
22
Cargo.toml
22
Cargo.toml
@ -1,27 +1,27 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "hoc"
|
name = "hoc"
|
||||||
version = "0.10.0"
|
version = "0.11.4"
|
||||||
authors = ["Valentin Brandl <vbrandl@riseup.net>"]
|
authors = ["Valentin Brandl <vbrandl@riseup.net>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "1.0.3"
|
actix-web = "1.0.8"
|
||||||
badge = "0.2.0"
|
badge = "0.2.0"
|
||||||
bytes = "0.4.12"
|
bytes = "0.4.12"
|
||||||
futures = "0.1.28"
|
futures = "0.1.29"
|
||||||
git2 = "0.9.1"
|
git2 = "0.9.1"
|
||||||
lazy_static = "1.3.0"
|
lazy_static = "1.4.0"
|
||||||
log = "0.4.6"
|
log = "0.4.8"
|
||||||
log4rs = "0.8.3"
|
log4rs = "0.8.3"
|
||||||
number_prefix = "0.3.0"
|
number_prefix = "0.3.0"
|
||||||
openssl-probe = "0.1.2"
|
openssl-probe = "0.1.2"
|
||||||
reqwest = "0.9.17"
|
reqwest = "0.9.22"
|
||||||
serde = "1.0.93"
|
serde = "1.0.101"
|
||||||
serde_derive = "1.0.94"
|
serde_derive = "1.0.101"
|
||||||
serde_json = "1.0.40"
|
serde_json = "1.0.41"
|
||||||
structopt = "0.2.18"
|
structopt = "0.3.3"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
ructe = "0.6.4"
|
ructe = "0.7.2"
|
||||||
vergen = "3.0.4"
|
vergen = "3.0.4"
|
||||||
|
10
scripts/find-active.sh
Executable file
10
scripts/find-active.sh
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
DIR=${1:-repos}
|
||||||
|
|
||||||
|
for url in $(./scripts/list.sh "${DIR}")
|
||||||
|
do
|
||||||
|
(curl "${url}" --silent | grep -q hitsofcode) && echo "${url}" &
|
||||||
|
done
|
21
scripts/load-active.sh
Executable file
21
scripts/load-active.sh
Executable file
@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
ACTIVE=${1}
|
||||||
|
|
||||||
|
if [ -z "${ACTIVE}" ]
|
||||||
|
then
|
||||||
|
echo "Usage: $0 <list of active repos>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
while IFS= read -r url
|
||||||
|
do
|
||||||
|
imgs=$(curl "${url}" --silent | grep hitsofcode | grep -o -P 'https://camo.githubusercontent.com/[a-z0-9]+/[a-z0-9]+')
|
||||||
|
[ -z "${imgs}" ] || echo "${url}"
|
||||||
|
for img in ${imgs}
|
||||||
|
do
|
||||||
|
curl "$img" --silent > /dev/null &
|
||||||
|
done
|
||||||
|
done < "${ACTIVE}"
|
@ -46,14 +46,6 @@ pub(crate) struct Opt {
|
|||||||
)]
|
)]
|
||||||
/// The logfile
|
/// The logfile
|
||||||
pub(crate) logfile: PathBuf,
|
pub(crate) logfile: PathBuf,
|
||||||
#[structopt(subcommand)]
|
|
||||||
pub(crate) migrate: Option<Migration>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(StructOpt, Debug, Clone, Copy)]
|
|
||||||
pub(crate) enum Migration {
|
|
||||||
#[structopt(name = "migrate-commit-count")]
|
|
||||||
CacheCommitCount,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn init() -> Result<()> {
|
pub(crate) fn init() -> Result<()> {
|
||||||
|
60
src/main.rs
60
src/main.rs
@ -18,7 +18,6 @@ mod statics;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
cache::CacheState,
|
cache::CacheState,
|
||||||
config::Migration,
|
|
||||||
error::{Error, Result},
|
error::{Error, Result},
|
||||||
service::{Bitbucket, FormService, GitHub, Gitlab, Service},
|
service::{Bitbucket, FormService, GitHub, Gitlab, Service},
|
||||||
statics::{CLIENT, CSS, FAVICON, OPT, REPO_COUNT, VERSION_INFO},
|
statics::{CLIENT, CSS, FAVICON, OPT, REPO_COUNT, VERSION_INFO},
|
||||||
@ -35,7 +34,7 @@ use git2::Repository;
|
|||||||
use number_prefix::{NumberPrefix, Prefixed, Standalone};
|
use number_prefix::{NumberPrefix, Prefixed, Standalone};
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
fs::{create_dir_all, read_dir, rename},
|
fs::create_dir_all,
|
||||||
path::Path,
|
path::Path,
|
||||||
process::Command,
|
process::Command,
|
||||||
sync::atomic::Ordering,
|
sync::atomic::Ordering,
|
||||||
@ -138,8 +137,12 @@ fn hoc(repo: &str, repo_dir: &str, cache_dir: &str) -> Result<(u64, String, u64)
|
|||||||
Ok((cache.count, head, commits))
|
Ok((cache.count, head, commits))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remote_exists(url: &str) -> Result<bool> {
|
fn remote_exists(url: &str) -> impl Future<Item = bool, Error = Error> {
|
||||||
Ok(CLIENT.head(url).send()?.status() == reqwest::StatusCode::OK)
|
CLIENT
|
||||||
|
.head(url)
|
||||||
|
.send()
|
||||||
|
.map(|resp| resp.status() == reqwest::StatusCode::OK)
|
||||||
|
.from_err()
|
||||||
}
|
}
|
||||||
|
|
||||||
enum HocResult {
|
enum HocResult {
|
||||||
@ -164,15 +167,15 @@ where
|
|||||||
T: Service,
|
T: Service,
|
||||||
F: Fn(HocResult) -> Result<HttpResponse>,
|
F: Fn(HocResult) -> Result<HttpResponse>,
|
||||||
{
|
{
|
||||||
futures::future::result(Ok(()))
|
let repo = format!("{}/{}", data.0.to_lowercase(), data.1.to_lowercase());
|
||||||
.and_then(move |_| {
|
let service_path = format!("{}/{}", T::domain(), repo);
|
||||||
let repo = format!("{}/{}", data.0.to_lowercase(), data.1.to_lowercase());
|
let path = format!("{}/{}", state.repos, service_path);
|
||||||
let service_path = format!("{}/{}", T::domain(), repo);
|
let url = format!("https://{}", service_path);
|
||||||
let path = format!("{}/{}", state.repos, service_path);
|
remote_exists(&url)
|
||||||
|
.and_then(move |remote_exists| {
|
||||||
let file = Path::new(&path);
|
let file = Path::new(&path);
|
||||||
let url = format!("https://{}", service_path);
|
|
||||||
if !file.exists() {
|
if !file.exists() {
|
||||||
if !remote_exists(&url)? {
|
if !remote_exists {
|
||||||
warn!("Repository does not exist: {}", url);
|
warn!("Repository does not exist: {}", url);
|
||||||
return Ok(HocResult::NotFound);
|
return Ok(HocResult::NotFound);
|
||||||
}
|
}
|
||||||
@ -352,6 +355,7 @@ fn start_server() -> Result<()> {
|
|||||||
App::new()
|
App::new()
|
||||||
.data(state.clone())
|
.data(state.clone())
|
||||||
.wrap(middleware::Logger::default())
|
.wrap(middleware::Logger::default())
|
||||||
|
.wrap(middleware::NormalizePath)
|
||||||
.service(index)
|
.service(index)
|
||||||
.service(css)
|
.service(css)
|
||||||
.service(favicon32)
|
.service(favicon32)
|
||||||
@ -372,39 +376,7 @@ fn start_server() -> Result<()> {
|
|||||||
.run()?)
|
.run()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn migrate_cache() -> Result<()> {
|
|
||||||
let mut backup_cache = OPT.cachedir.clone();
|
|
||||||
backup_cache.set_extension("bak");
|
|
||||||
rename(&OPT.cachedir, backup_cache)?;
|
|
||||||
let outdir = OPT.outdir.display().to_string();
|
|
||||||
let cachedir = OPT.cachedir.display().to_string();
|
|
||||||
for service in read_dir(&OPT.outdir)? {
|
|
||||||
let service = service?;
|
|
||||||
for namespace in read_dir(service.path())? {
|
|
||||||
let namespace = namespace?;
|
|
||||||
for repo in read_dir(namespace.path())? {
|
|
||||||
let repo_path = repo?.path().display().to_string();
|
|
||||||
let repo_path: String =
|
|
||||||
repo_path
|
|
||||||
.split(&outdir)
|
|
||||||
.fold(String::new(), |mut acc, next| {
|
|
||||||
acc.push_str(next);
|
|
||||||
acc
|
|
||||||
});
|
|
||||||
println!("{}", repo_path);
|
|
||||||
hoc(&repo_path, &outdir, &cachedir)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
config::init()?;
|
config::init()?;
|
||||||
match &OPT.migrate {
|
start_server()
|
||||||
None => start_server(),
|
|
||||||
Some(migration) => match migration {
|
|
||||||
Migration::CacheCommitCount => migrate_cache(),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ pub(crate) const CSS: &str = include_str!("../static/tacit-css.min.css");
|
|||||||
pub(crate) const FAVICON: &[u8] = include_bytes!("../static/favicon32.png");
|
pub(crate) const FAVICON: &[u8] = include_bytes!("../static/favicon32.png");
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub(crate) static ref CLIENT: reqwest::Client = reqwest::Client::new();
|
pub(crate) static ref CLIENT: reqwest::r#async::Client = reqwest::r#async::Client::new();
|
||||||
pub(crate) static ref OPT: Opt = Opt::from_args();
|
pub(crate) static ref OPT: Opt = Opt::from_args();
|
||||||
pub(crate) static ref REPO_COUNT: AtomicUsize =
|
pub(crate) static ref REPO_COUNT: AtomicUsize =
|
||||||
AtomicUsize::new(count_repositories(&OPT.outdir).unwrap());
|
AtomicUsize::new(count_repositories(&OPT.outdir).unwrap());
|
||||||
|
Reference in New Issue
Block a user