Skip to content

Commit a1f2baf

Browse files
committed
add ci
1 parent 5cd23d4 commit a1f2baf

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

.github/workflows/rust.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v3
17+
18+
- name: Run rustfmt
19+
run: cargo fmt --all -- --check
20+
21+
- name: Run clippy
22+
run: cargo clippy --all-targets --all-features -- -D warnings
23+
24+
- name: Run test
25+
run: cargo test
26+

src/main.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,7 @@ fn main() {
5959
if body.is_empty() {
6060
vec![]
6161
} else {
62-
body
63-
.split("\n")
64-
.into_iter()
65-
.map(|item| String::from(item))
66-
.collect()
62+
body.split('\n').map(String::from).collect()
6763
}
6864
}
6965
Err(err) => {

src/utils.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::error::Result;
2-
use std::{os::unix::prelude::PermissionsExt, path::PathBuf, process::Command};
2+
use std::{os::unix::prelude::PermissionsExt, path::Path, process::Command};
33
use tiny_http::{Request, Response};
44

55
pub fn has_header(req: &Request, key: &str, value: &str) -> bool {
@@ -12,20 +12,20 @@ pub fn has_header(req: &Request, key: &str, value: &str) -> bool {
1212
false
1313
}
1414

15-
pub fn executable(file_path: &PathBuf) -> bool {
15+
pub fn executable(file_path: &Path) -> bool {
1616
match file_path.metadata() {
1717
Ok(data) => data.is_file() && data.permissions().mode() & 0o111 != 0,
1818
Err(_) => false,
1919
}
2020
}
2121

22-
pub fn run_command(script_path: &PathBuf, params: Vec<String>) -> Result<String> {
22+
pub fn run_command(script_path: &Path, params: Vec<String>) -> Result<String> {
2323
let output = Command::new(script_path).args(params).output()?;
2424

2525
if !output.status.success() {
2626
return Err(String::from_utf8(output.stderr)?.into());
2727
}
28-
return Ok(String::from_utf8(output.stdout)?);
28+
Ok(String::from_utf8(output.stdout)?)
2929
}
3030

3131
pub fn send_response<S>(request: Request, status_code: i32, body: S)

0 commit comments

Comments
 (0)