Skip to content

Commit

Permalink
style: Address cargo clippy and cargo fmt
Browse files Browse the repository at this point in the history
* feat(ci): Run cargo test in ci

Signed-off-by: KunoiSayami <[email protected]>
  • Loading branch information
KunoiSayami committed Dec 11, 2021
1 parent b675f37 commit c4811be
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 18 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ jobs:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
- name: Build binary
uses: actions-rs/cargo@v1
with:
command: build
args: --release
- name: Running test
uses: actions-rs/cargo@v1
with:
command: test
args: --release
- name: Rename binary
id: rename
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "github-webhook-notification"
version = "1.1.0"
version = "1.1.1"
edition = "2021"

[dependencies]
Expand Down
26 changes: 14 additions & 12 deletions src/configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,24 @@ impl Telegram {
impl From<&TomlTelegram> for Telegram {
fn from(value: &TomlTelegram) -> Self {
let receivers: Vec<i64> = match value.send_to() {
Value::String(s) => vec![i64::from_str(s.as_str())
.expect("Can't parse string value to i64")],
Value::Integer(i) => vec![i.clone()],
Value::Array(v) => v.into_iter().map(|x|
match x {
Value::String(s) => i64::from_str(s).expect("Can't parse array string to i64"),
Value::Integer(i) => i.clone(),
_ => panic!("Unexpected value {:?}", x)
}
).collect(),
_ => panic!("Unexpected value {:?}", value.send_to())
Value::String(s) => {
vec![i64::from_str(s.as_str()).expect("Can't parse string value to i64")]
}
Value::Integer(i) => vec![*i],
Value::Array(v) => v
.iter()
.map(|x| match x {
Value::String(s) => i64::from_str(s).expect("Can't parse array string to i64"),
Value::Integer(i) => *i,
_ => panic!("Unexpected value {:?}", x),
})
.collect(),
_ => panic!("Unexpected value {:?}", value.send_to()),
};
Self {
bot_token: value.bot_token().clone(),
api_server: value.api_server().clone(),
send_to: receivers
send_to: receivers,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/datastructures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl Guard for AuthorizationGuard {
}

let uri = request.uri.to_string();
if uri.contains("?") {
if uri.contains('?') {
let (_, queries) = uri.split_once('?').unwrap();
if queries.contains('&') {
for query in queries.split('&') {
Expand Down
12 changes: 10 additions & 2 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ mod test {
assert_eq!(cfg.telegram().bot_token(), "1145141919:810abcdefg");
let result = vec![114514, 1919810i64];
assert_eq!(cfg.telegram().send_to().len(), result.len());
assert_eq!(cfg.telegram().send_to().into_iter().zip(&result).filter(|&(a,b)| a == b).count(), result.len());
assert_eq!(
cfg.telegram()
.send_to()
.into_iter()
.zip(&result)
.filter(|&(a, b)| a == b)
.count(),
result.len()
);
}
}
}

0 comments on commit c4811be

Please sign in to comment.