Struct GitJournal

Source
pub struct GitJournal {
    pub config: Config,
    /* private fields */
}
Expand description

The main structure of git-journal.

Fields§

§config: Config

The configuration structure

Implementations§

Source§

impl GitJournal

Source

pub fn new(path: &str) -> Result<Self, Error>

Constructs a new GitJournal. Searches upwards if the given path does not contain the .git directory.

§Examples
use gitjournal::GitJournal;

let journal = GitJournal::new(".").unwrap();
§Errors

When not providing a path with a valid git repository (‘.git’ folder or the initial parsing of the git tags failed.

Source

pub fn setup(&self) -> Result<(), Error>

Does the setup on the target git repository.

§Examples
use gitjournal::GitJournal;

let journal = GitJournal::new(".").unwrap();
journal.setup().expect("Setup error");

Creates a .gitjournal file with the default values inside the given path, which looks like:

# Specifies the available categories for the commit message, allowed regular expressions.
categories = ["Added", "Changed", "Fixed", "Improved", "Removed"]

# Set the characters where the categories are wrapped in
category_delimiters = ["[", "]"]

# Set to false if the output should not be colored
colored_output = true

# Specifies the default template. Will be used for tag validation and printing. Can be
# removed from the configuration file as well.
default_template = "CHANGELOG.toml"

# Show or hide the debug messages like `[OKAY] ...` or `[INFO] ...`
enable_debug = true

# Excluded tags in an array, e.g. "internal"
excluded_commit_tags = []

# Enable or disable the output and accumulation of commit footers.
enable_footers = false

# Show or hide the commit hash for every entry
show_commit_hash = false

# Show or hide the commit message prefix, e.g. JIRA-1234
show_prefix = false

# Sort the commits during the output by "date" (default) or "name"
sort_by = "date"

# Commit message template prefix which will be added during commit preparation.
template_prefix = "JIRA-1234"

It also creates a symlinks for the commit message validation and preparation hook inside the given git repository.

§Errors
  • When the writing of the default configuration fails.
  • When installation of the commit message (preparation) hook fails.
Source

pub fn prepare( &self, path: &str, commit_type: Option<&str>, ) -> Result<(), Error>

Prepare a commit message before the user edits it. This includes also a verification of the commit message, e.g. for amended commits.

§Examples
use gitjournal::GitJournal;

let journal = GitJournal::new(".").unwrap();
journal
    .prepare("./tests/commit_messages/success_1", None)
    .expect("Commit message preparation error");
§Errors

When the path is not available or writing the commit message fails.

Source

pub fn verify(&self, path: &str) -> Result<(), Error>

Verify a given commit message against the parsing rules of RFC0001

§Examples
use gitjournal::GitJournal;

let journal = GitJournal::new(".").unwrap();
journal
    .verify("tests/commit_messages/success_1")
    .expect("Commit message verification error");
§Errors

When the commit message is not valid due to RFC0001 or opening of the given file failed.

Source

pub fn parse_log( &mut self, revision_range: &str, tag_skip_pattern: &str, max_tags_count: &u32, all: &bool, skip_unreleased: &bool, ignore_tags: Option<Vec<&str>>, ) -> Result<(), Error>

Parses a revision range for a GitJournal.

§Examples
use gitjournal::GitJournal;

let mut journal = GitJournal::new(".").unwrap();
journal.parse_log("HEAD", "rc", &1, &false, &false, None);
§Errors

When something during the parsing fails, for example if the revision range is invalid.

Source

pub fn generate_template(&self) -> Result<(), Error>

Generates an output template from the current parsing results.

§Examples
use gitjournal::GitJournal;

let mut journal = GitJournal::new(".").unwrap();
journal.parse_log("HEAD", "rc", &1, &false, &false, None);
journal
    .generate_template()
    .expect("Template generation failed.");
§Errors

If the generation of the template was impossible.

Source

pub fn print_log( &self, compact: bool, template: Option<&str>, output: Option<&str>, ) -> Result<(), Error>

Prints the resulting log in a short or detailed variant. Will use the template as an output formatter if provided.

§Examples
use gitjournal::GitJournal;

let mut journal = GitJournal::new(".").unwrap();
journal.parse_log("HEAD", "rc", &1, &false, &false, None);
journal
    .print_log(true, None, None)
    .expect("Could not print short log.");
journal
    .print_log(false, None, None)
    .expect("Could not print detailed log.");
§Errors

If some commit message could not be print.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.