Skip to content

Commit

Permalink
build: add more checks and fix clippy hints
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Zaunseder committed Feb 21, 2024
1 parent 9e5ccf4 commit 6d4c8b3
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 49 deletions.
19 changes: 10 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
name: Rust
name: CI

on:
push:
branches: [ "main" ]
branches: ["*"]
pull_request:
branches: [ "main" ]
branches: ["main"]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Lint
run: cargo clippy && cargo fmt --check
- name: Run tests
run: cargo test --verbose
7 changes: 6 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
mod parser;
mod rules;

use std::{env::current_dir, io::{stdin, Read}, path::PathBuf, process::ExitCode};
use std::{
env::current_dir,
io::{stdin, Read},
path::PathBuf,
process::ExitCode,
};

use clap::Parser;
use miette::GraphicalReportHandler;
Expand Down
75 changes: 38 additions & 37 deletions src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt;

use serde::Serialize;

use pest::{Parser, Span};
Expand Down Expand Up @@ -28,10 +30,6 @@ impl<'a> CommitSpan<'a> {
}
}

pub fn to_string(&self) -> String {
self.input.to_string()
}

pub fn start(&self) -> usize {
self.start
}
Expand All @@ -41,6 +39,12 @@ impl<'a> CommitSpan<'a> {
}
}

impl fmt::Display for CommitSpan<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.input)
}
}

#[derive(Debug, Serialize)]
pub struct Commit<'a> {
/// The complete header of the commit message including the type, scope and subject
Expand Down Expand Up @@ -94,44 +98,39 @@ pub fn parse_commit(commit_msg: &str) -> Commit {
};

for pair in pairs {
match pair.as_rule() {
Rule::commit => {
commit.raw = pair.as_str().to_string();

for inner_pair in pair.into_inner() {
match inner_pair.as_rule() {
Rule::header => {
commit.header = CommitSpan::from(inner_pair.as_span());

for header_pair in inner_pair.into_inner() {
match header_pair.as_rule() {
Rule::commit_type => {
commit.commit_type = CommitSpan::from(header_pair.as_span())
}
Rule::scope => {
commit.scope = Some(CommitSpan::from(header_pair.as_span()))
}
Rule::subject => {
commit.subject = CommitSpan::from(header_pair.as_span())
}
_ => {}
if let Rule::commit = pair.as_rule() {
commit.raw = pair.as_str().to_string();

for inner_pair in pair.into_inner() {
match inner_pair.as_rule() {
Rule::header => {
commit.header = CommitSpan::from(inner_pair.as_span());

for header_pair in inner_pair.into_inner() {
match header_pair.as_rule() {
Rule::commit_type => {
commit.commit_type = CommitSpan::from(header_pair.as_span())
}
Rule::scope => {
commit.scope = Some(CommitSpan::from(header_pair.as_span()))
}
Rule::subject => {
commit.subject = CommitSpan::from(header_pair.as_span())
}
_ => {}
}
}
Rule::body => commit.body = Some(CommitSpan::from(inner_pair.as_span())),
Rule::footer => {
commit.footer = Some(CommitSpan::from(inner_pair.as_span()))
}
Rule::commit_type => {
commit.commit_type = CommitSpan::from(inner_pair.as_span())
}
Rule::scope => commit.scope = Some(CommitSpan::from(inner_pair.as_span())),
Rule::subject => commit.subject = CommitSpan::from(inner_pair.as_span()),
_ => {}
}
Rule::body => commit.body = Some(CommitSpan::from(inner_pair.as_span())),
Rule::footer => commit.footer = Some(CommitSpan::from(inner_pair.as_span())),
Rule::commit_type => {
commit.commit_type = CommitSpan::from(inner_pair.as_span())
}
Rule::scope => commit.scope = Some(CommitSpan::from(inner_pair.as_span())),
Rule::subject => commit.subject = CommitSpan::from(inner_pair.as_span()),
_ => {}
}
}
_ => {}
}
}

Expand Down Expand Up @@ -170,7 +169,9 @@ mod tests {
want_err: false,
},
TestConfig {
name: String::from("body and footer missing with newline at the end (stdio input adds a newline)"),
name: String::from(
"body and footer missing with newline at the end (stdio input adds a newline)",
),
commit: String::from("feat(nice): add cool feature\n"),
want_err: false,
},
Expand Down
4 changes: 2 additions & 2 deletions src/rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ struct RulesDetails {
scope_enum: EnumOpts,
#[serde(rename = "scope-max-length")]
scope_max_length: LengthOpts,
#[serde(rename = "scope-case")]
scope_case: CaseOpts,
// #[serde(rename = "scope-case")]
// scope_case: CaseOpts,
}

/// Config
Expand Down

0 comments on commit 6d4c8b3

Please sign in to comment.