feat: add git check config

This commit is contained in:
2020-12-29 00:16:33 +08:00
parent 57d97306c8
commit 0568ac6e27
3 changed files with 35 additions and 4 deletions

9
Cargo.lock generated
View File

@@ -92,6 +92,8 @@ dependencies = [
"clap",
"crates_io_api",
"rust_util",
"serde",
"serde_json",
"toml",
]
@@ -942,9 +944,9 @@ dependencies = [
[[package]]
name = "rust_util"
version = "0.6.22"
version = "0.6.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d86f4838bd1e232610932d5a26fcf58305d1dbc936590612af966f8365afe1e7"
checksum = "6149797f0ee27329552a951e08f4b0482aadb986ad7dfeb2758f9fe1aa0f6669"
dependencies = [
"lazy_static",
"libc",
@@ -1002,6 +1004,9 @@ name = "serde"
version = "1.0.117"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b88fa983de7720629c9387e9f517353ed404164b1e482c970a90c1a4aaf7dc1a"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"

View File

@@ -14,6 +14,7 @@ repository = "https://git.hatter.ink/hatter/cargotool"
[dependencies]
clap = "2.33.3"
toml = "0.5.6"
rust_util = "0.6.22"
rust_util = "0.6.23"
crates_io_api = "0.6"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

View File

@@ -1,7 +1,32 @@
use clap::{ArgMatches, SubCommand, App, Arg};
use rust_util::util_git;
use serde::{Serialize, Deserialize};
use crate::cmd::{Command, CommandResult};
// filename: gitcheck.json
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
struct GitCheckConfig {
is_master_protected: Option<bool>, // default true
protected_branches: Option<Vec<String>>,
}
impl GitCheckConfig {
fn is_master_protected(&self) -> bool {
self.is_master_protected.unwrap_or(true)
}
fn is_branch_protected(&self, branch: &str) -> bool {
if branch == "master" {
return self.is_master_protected();
}
match &self.protected_branches {
None => false,
Some(bs) => bs.iter().find(|b| *b == branch).is_some(),
}
}
}
pub struct CommandImpl;
impl Command for CommandImpl {