Skip to content

Commit

Permalink
refactor: organize imports and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
tranzystorekk authored and oknozor committed Nov 30, 2021
1 parent 6fe1a27 commit 807d033
Show file tree
Hide file tree
Showing 27 changed files with 140 additions and 134 deletions.
4 changes: 3 additions & 1 deletion Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ chrono = "^0"
config = { version = "^0", default-features = false, features = ["toml"] }
edit = "^0"
itertools = "^0"
serde_derive = "^1"
serde = "^1"
serde = { version = "^1", features = ["derive"] }
tempfile = "^3"
semver = "^1"
shell-words = "^1"
Expand Down
5 changes: 2 additions & 3 deletions src/bin/coco.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#![cfg(not(tarpaulin_include))]
use std::fmt::Write;

use cocogitto::{CocoGitto, COMMITS_METADATA};

use anyhow::{bail, Result};
use conventional_commit_parser::commit::Footer;
use itertools::Itertools;
use structopt::clap::{AppSettings, Shell};
use structopt::StructOpt;

use cocogitto::CocoGitto;
use cocogitto::COMMITS_METADATA;

const APP_SETTINGS: &[AppSettings] = &[
AppSettings::UnifiedHelpMessage,
AppSettings::ColoredHelp,
Expand Down
8 changes: 4 additions & 4 deletions src/bin/cog.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#![cfg(not(tarpaulin_include))]
use std::path::PathBuf;

use anyhow::{Context, Result};
use structopt::clap::{AppSettings, Shell};
use structopt::StructOpt;

use cocogitto::conventional::commit;
use cocogitto::conventional::version::VersionIncrement;
use cocogitto::git::hook::HookKind;
use cocogitto::log::filter::{CommitFilter, CommitFilters};
use cocogitto::log::output::Output;
use cocogitto::{CocoGitto, SETTINGS};

use anyhow::{Context, Result};
use structopt::clap::{AppSettings, Shell};
use structopt::StructOpt;

const APP_SETTINGS: &[AppSettings] = &[
AppSettings::SubcommandRequiredElseHelp,
AppSettings::UnifiedHelpMessage,
Expand Down
11 changes: 7 additions & 4 deletions src/conventional/changelog.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use crate::conventional::commit::Commit;
use crate::{OidOf, SETTINGS};
use anyhow::Result;
use itertools::Itertools;
use std::fmt::Write;
use std::fs;
use std::path::PathBuf;

use crate::conventional::commit::Commit;
use crate::{OidOf, SETTINGS};

use anyhow::{anyhow, Result};
use itertools::Itertools;

pub(crate) struct Changelog {
pub from: OidOf,
pub to: OidOf,
Expand Down Expand Up @@ -91,6 +93,7 @@ mod test {
use crate::conventional::changelog::Changelog;
use crate::conventional::commit::Commit;
use crate::OidOf;

use anyhow::Result;
use chrono::Utc;
use conventional_commit_parser::commit::{CommitType, ConventionalCommit};
Expand Down
11 changes: 7 additions & 4 deletions src/conventional/commit.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use std::cmp::Ordering;
use std::fmt::{self, Formatter};

use crate::error::CocogittoError::CommitFormat;
use crate::SETTINGS;
use anyhow::Result;

use anyhow::{anyhow, Result};
use chrono::{NaiveDateTime, Utc};
use colored::*;
use conventional_commit_parser::commit::ConventionalCommit;
use conventional_commit_parser::error::ParseError;
use git2::Commit as Git2Commit;
use std::cmp::Ordering;
use std::fmt;
use std::fmt::Formatter;
use serde::{Deserialize, Serialize};

#[derive(Debug, Eq, PartialEq)]
pub struct Commit {
Expand Down Expand Up @@ -239,6 +241,7 @@ pub fn verify(author: Option<String>, message: &str) -> Result<(), ParseError> {
#[cfg(test)]
mod test {
use crate::conventional::commit::{verify, Commit};

use chrono::NaiveDateTime;
use conventional_commit_parser::commit::{CommitType, ConventionalCommit};
use speculoos::prelude::*;
Expand Down
17 changes: 9 additions & 8 deletions src/conventional/version.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use anyhow::Result;
use crate::conventional::commit::Commit;
use crate::git::repository::Repository;

use anyhow::{anyhow, bail, Result};
use colored::*;
use conventional_commit_parser::commit::CommitType;
use git2::Commit as Git2Commit;
use itertools::Itertools;
use semver::Version;

use crate::conventional::commit::Commit;
use crate::git::repository::Repository;

#[derive(Debug, PartialEq)]
pub enum VersionIncrement {
Major,
Expand Down Expand Up @@ -172,16 +172,17 @@ impl VersionIncrement {
// Auto version tests resides in test/ dir since it rely on git log
// To generate the version
mod test {
use std::str::FromStr;

use crate::conventional::commit::Commit;
use crate::conventional::version::VersionIncrement;

use anyhow::Result;
use chrono::Utc;
use conventional_commit_parser::commit::{CommitType, ConventionalCommit};
use semver::Version;
use speculoos::prelude::*;

use crate::conventional::commit::Commit;
use crate::conventional::version::VersionIncrement;
use std::str::FromStr;

impl Commit {
fn commit_fixture(commit_type: CommitType, is_breaking_change: bool) -> Self {
Commit {
Expand Down
5 changes: 3 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::fmt::{self, Debug, Display, Formatter};

use crate::OidOf;

use colored::*;
use std::fmt;
use std::fmt::{Debug, Display, Formatter};

#[derive(Debug)]
pub(crate) enum CocogittoError {
Expand Down
21 changes: 11 additions & 10 deletions src/git/hook.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use crate::CocoGitto;
use anyhow::Result;

use std::fs::Permissions;
use std::fs::{self, Permissions};
#[cfg(target_family = "unix")]
use std::os::unix::fs::PermissionsExt;

use std::fs;
use std::path::Path;

use crate::CocoGitto;

use anyhow::{anyhow, Result};

pub static PRE_PUSH_HOOK: &[u8] = include_bytes!("assets/pre-push");
pub static PREPARE_COMMIT_HOOK: &[u8] = include_bytes!("assets/prepare-commit-msg");
const PRE_COMMIT_HOOK_PATH: &str = ".git/hooks/pre-commit";
Expand Down Expand Up @@ -60,14 +59,16 @@ fn create_hook(path: &Path, kind: HookKind) -> Result<()> {

#[cfg(test)]
mod tests {
use crate::git::hook::HookKind;
use crate::CocoGitto;
use anyhow::Result;
use speculoos::prelude::*;
use std::env;
use std::fs::File;
use std::path::PathBuf;
use std::process::Command;

use crate::git::hook::HookKind;
use crate::CocoGitto;

use anyhow::Result;
use speculoos::prelude::*;
use tempfile::TempDir;

#[test]
Expand Down
22 changes: 10 additions & 12 deletions src/git/repository.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use std::fmt::{Debug, Formatter};
use std::path::Path;

use anyhow::Result;
use crate::error::CocogittoError::{self, Git};
use crate::git::status::Statuses;
use crate::OidOf;

use anyhow::{anyhow, ensure, Result};
use colored::Colorize;
use git2::{
Commit as Git2Commit, Diff, DiffOptions, IndexAddOption, Object, ObjectType, Oid,
Expand All @@ -9,13 +14,6 @@ use git2::{
use itertools::Itertools;
use semver::Version;

use crate::error::CocogittoError;
use crate::error::CocogittoError::Git;
use crate::OidOf;

use super::status::Statuses;
use std::fmt::{Debug, Formatter};

pub(crate) struct Repository(pub(crate) Git2Repository);

impl Repository {
Expand Down Expand Up @@ -288,12 +286,12 @@ impl Debug for Repository {
mod test {
use std::process::{Command, Stdio};

use anyhow::Result;
use tempfile::TempDir;

use super::Repository;
use crate::git::repository::Repository;
use crate::OidOf;

use anyhow::Result;
use speculoos::prelude::*;
use tempfile::TempDir;

#[test]
fn init_repo() -> Result<()> {
Expand Down
14 changes: 8 additions & 6 deletions src/git/status.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::fmt::{self, Formatter};

use crate::git::status::Changes::{Deleted, Modified, New, Renamed, TypeChange};

use colored::*;
use git2::StatusEntry as Git2StatusEntry;
use git2::Statuses as Git2Statuses;
use std::fmt;
use std::fmt::Formatter;

pub(crate) struct Statuses(pub Vec<Status>);

Expand Down Expand Up @@ -103,12 +104,13 @@ impl fmt::Debug for Statuses {

#[cfg(test)]
mod test {
use std::fs;

use crate::git::status::{Changes, Statuses};
use anyhow::Result;
use git2::Repository;
use git2::StatusOptions;

use anyhow::{anyhow, Result};
use git2::{Repository, StatusOptions};
use speculoos::prelude::*;
use std::fs;
use tempfile::TempDir;

#[test]
Expand Down
13 changes: 6 additions & 7 deletions src/hook/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
mod parser;

use std::collections::VecDeque;
use std::fmt;
use std::ops::Range;
use std::process::Command;
use std::str::FromStr;

use anyhow::Result;
use semver::Version;

use parser::Token;

mod parser;
use anyhow::{anyhow, ensure, Result};
use semver::Version;

#[derive(Debug, Eq, PartialEq)]
pub struct VersionSpan {
Expand Down Expand Up @@ -143,10 +143,9 @@ impl Hook {
mod test {
use std::str::FromStr;

use speculoos::prelude::*;
use crate::{Hook, Result};

use crate::Hook;
use crate::Result;
use speculoos::prelude::*;

#[test]
fn parse_empty_string() {
Expand Down
13 changes: 8 additions & 5 deletions src/hook/parser.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use std::collections::VecDeque;

use pest::iterators::{Pair, Pairs};
use semver::{BuildMetadata, Prerelease};

use crate::hook::{HookSpan, VersionSpan};

use pest::iterators::{Pair, Pairs};
use pest::Parser;
use pest_derive::Parser as ParserDerive;
use semver::{BuildMetadata, Prerelease};

#[doc(hidden)]
#[derive(Parser)]
#[derive(ParserDerive)]
#[grammar = "hook/version_dsl.pest"]
struct HookDslParser;

Expand Down Expand Up @@ -92,11 +93,13 @@ fn parse_operator(tokens: &mut VecDeque<Token>, pairs: Pairs<'_, Rule>) -> anyho

#[cfg(test)]
mod test {
use std::collections::VecDeque;

use crate::hook::parser::Token;
use crate::hook::{parser, VersionSpan};

use semver::Prerelease;
use speculoos::prelude::*;
use std::collections::VecDeque;

#[test]
fn parse_version_and_latest() {
Expand Down
Loading

0 comments on commit 807d033

Please sign in to comment.