Skip to content

Commit

Permalink
fix(git): hide internal method visibility and fix some clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed Sep 12, 2020
1 parent d5684c4 commit 55f62ac
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ use crate::COMMITS_METADATA;
use colored::*;
use git2::Oid;

pub struct Changelog {
pub(crate) struct Changelog {
pub from: Oid,
pub to: Oid,
pub date: String,
pub commits: Vec<Commit>,
}

impl Changelog {
pub fn tag_diff_to_markdown(&mut self) -> String {
pub(crate) fn tag_diff_to_markdown(&mut self) -> String {
let mut out = String::new();

out.push_str(&Changelog::header());
Expand Down
6 changes: 3 additions & 3 deletions src/commit.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::commit::CommitType::*;
use crate::error::CocoGittoError::CommitFormatError;
use crate::error::ErrorKind::CommitFormat;
use crate::COMMITS_METADATA;
use anyhow::Result;
use chrono::{NaiveDateTime, Utc};
Expand Down Expand Up @@ -68,7 +68,7 @@ impl CommitConfig {
}

impl Commit {
pub fn from_git_commit(commit: &Git2Commit) -> Result<Self> {
pub(crate) fn from_git_commit(commit: &Git2Commit) -> Result<Self> {
let shorthand = commit
.as_object()
.short_id()
Expand Down Expand Up @@ -101,7 +101,7 @@ impl Commit {
.to_string();
let cause = format!("{} {}", "cause:".red(), err);
let level = "ERROR".red().bold().to_string();
Err(anyhow!(CommitFormatError {
Err(anyhow!(CommitFormat {
level,
shorthand,
commit_message,
Expand Down
8 changes: 4 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use thiserror::Error;

#[derive(Error, Debug)]
pub enum CocoGittoError {
pub(crate) enum ErrorKind {
#[error("{level} - {commit_message} - ({shorthand})\n\t{cause}\n")]
CommitFormatError {
CommitFormat {
level: String,
shorthand: String,
commit_message: String,
cause: String,
},
#[error("{level}:\n\t{cause}\n")]
SemverError { level: String, cause: String },
Semver { level: String, cause: String },
#[error("{level}:\n\t{cause}\n")]
GitError { level: String, cause: String },
Git { level: String, cause: String },
}
7 changes: 4 additions & 3 deletions src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ pub enum CommitFilter {
pub struct CommitFilters(pub Vec<CommitFilter>);

impl CommitFilters {
pub fn no_error(&self) -> bool {
pub(crate) fn no_error(&self) -> bool {
!self.0.contains(&CommitFilter::NoError)
}

pub fn filter_git2_commit(&self, commit: &Git2Commit) -> bool {
pub(crate) fn filter_git2_commit(&self, commit: &Git2Commit) -> bool {
// Author filters
let authors = self
.0
Expand All @@ -39,7 +39,8 @@ impl CommitFilters {

filter_authors
}
pub fn filters(&self, commit: &Commit) -> bool {

pub(crate) fn filters(&self, commit: &Commit) -> bool {
// Commit type filters
let types = self
.0
Expand Down
12 changes: 4 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ pub mod settings;

use crate::changelog::Changelog;
use crate::commit::{CommitConfig, CommitMessage, CommitType};
use crate::error::CocoGittoError::SemverError;
use crate::error::ErrorKind::Semver;
use crate::filter::CommitFilters;
use crate::repository::Repository;
use crate::settings::Settings;
use anyhow::Result;
use chrono::Utc;
use colored::*;
use commit::Commit;
use git2::{Commit as Git2Commit, Oid, RebaseOptions, Repository as Git2Repository};
use git2::{Commit as Git2Commit, Oid, RebaseOptions};
use semver::Version;
use std::collections::HashMap;
use std::fs::File;
Expand Down Expand Up @@ -66,10 +66,6 @@ impl CocoGitto {
&COMMITS_METADATA
}

pub fn get_repository(&self) -> &Git2Repository {
&self.repository.0
}

pub fn check_and_edit(&self) -> Result<()> {
let from = self.repository.get_first_commit()?;
let head = self.repository.get_head_commit_oid()?;
Expand Down Expand Up @@ -259,7 +255,7 @@ impl CocoGitto {
"{} version MUST be greater than current one: {}",
cause_key, comparison
);
return Err(anyhow!(SemverError {
return Err(anyhow!(Semver {
level: "SemVer Error".red().to_string(),
cause
}));
Expand Down Expand Up @@ -410,7 +406,7 @@ impl CocoGitto {

fn get_commit_range(&self, from: Oid, to: Oid) -> Result<Vec<Git2Commit>> {
// Ensure commit exists
let repository = self.get_repository();
let repository = &self.repository.0;
repository.find_commit(from)?;
repository.find_commit(to)?;

Expand Down
10 changes: 2 additions & 8 deletions src/repository.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::error::CocoGittoError::GitError;
use crate::error::ErrorKind::Git;
use anyhow::Result;
use colored::Colorize;
use git2::{
Expand Down Expand Up @@ -63,12 +63,6 @@ impl Repository {
Err(anyhow!("err"))
}
}
pub(crate) fn get_current_branch_name(&self) -> Result<String> {
let head = &self.0.head()?;
let head = head.shorthand();
let branch_name = head.expect("Cannot get HEAT").into();
Ok(branch_name)
}

pub(crate) fn get_head_commit_oid(&self) -> Result<Oid> {
self.get_head_object().map(|commit| commit.id())
Expand Down Expand Up @@ -126,7 +120,7 @@ impl Repository {
.map(|_| ())
.map_err(|err| {
let cause_key = "cause:".red();
anyhow!(GitError {
anyhow!(Git {
level: "Git error".to_string(),
cause: format!("{} {}", cause_key, err.message())
})
Expand Down
4 changes: 2 additions & 2 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::path::PathBuf;
type CommitsMetadataSettings = HashMap<String, CommitConfig>;

#[derive(Debug, Deserialize)]
pub struct Settings {
pub(crate) struct Settings {
#[serde(default)]
pub hooks: Vec<String>,
#[serde(default)]
Expand All @@ -21,7 +21,7 @@ pub struct Settings {
}

impl Settings {
pub fn get(repository: &Repository) -> Result<Self> {
pub(crate) fn get(repository: &Repository) -> Result<Self> {
match repository.get_repo_dir() {
Some(path) => {
if path.exists() {
Expand Down

0 comments on commit 55f62ac

Please sign in to comment.