Skip to content

Commit

Permalink
Merge pull request #32 from sdttttt/develop
Browse files Browse the repository at this point in the history
 Upgrade to 0.9.1
  • Loading branch information
sdttttt authored Nov 14, 2020
2 parents 88af12b + 1c19213 commit c6c056b
Show file tree
Hide file tree
Showing 16 changed files with 139 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
branches: [ master, develop ]

env:
CARGO_TERM_COLOR: always
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
branches: [ master, develop ]

env:
CARGO_TERM_COLOR: always
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
branches: [ master, develop ]

env:
CARGO_TERM_COLOR: always
Expand All @@ -26,7 +26,7 @@ jobs:
path: |
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}


- uses: actions-rs/toolchain@v1
with:
Expand Down
3 changes: 3 additions & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Thanks to [@KlausDevWalker](https://github.com/KlausDevWalker) for point out the description errors in the docs.

Thanks to [@laggardkernel](https://github.com/laggardkernel) for point out the signature generation problem.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grc"
version = "0.9.0-rc.1"
version = "0.9.1"
authors = ["sdttttt <[email protected]>"]
description = "Similar to git-cz, gcr will help you to provide a better Git experience."
readme = "README.md"
Expand Down
24 changes: 7 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# GRC

![](https://img.shields.io/crates/v/grc.svg)
![GRC](https://img.shields.io/crates/v/grc.svg)
![Rust](https://github.com/sdttttt/gcr/workflows/Rust/badge.svg)
![Release](https://github.com/sdttttt/gcr/workflows/Release/badge.svg)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/6501c2d5bc19413dbbd297c6ee39e060)](https://app.codacy.com/gh/sdttttt/gcr?utm_source=github.com&utm_medium=referral&utm_content=sdttttt/gcr&utm_campaign=Badge_Grade)
[![codecov](https://codecov.io/gh/sdttttt/gcr/branch/master/graph/badge.svg)](https://codecov.io/gh/sdttttt/gcr)

Standardized Git submission tool. “Grc” is a temporary name.
Semantic git commits tool.

Similar to git-cz, grc will help you to provide a better Git experience.
Similar to `git-cz`, grc will help you to provide a better Git experience.

## Install

You can install **grc** in the following ways:

### From Cargo
### From crates.io

Please Run:

Expand All @@ -31,15 +31,9 @@ Go to [RELEASE](https://github.com/sdttttt/gcr/releases), download one you like.
Please Run:

```sh
git clone --depth=1 https://github.com/sdttttt/gcr.git

cd gcr

cargo build --release
cargo install --git https://github.com/sdttttt/gcr.git
```

grc under `target/release/`.

## Using

after the tools install, run command in your repository:
Expand Down Expand Up @@ -72,14 +66,10 @@ type = [
]
```

## Contributor

Thanks to [@KlausDevWalker](https://github.com/KlausDevWalker) for helping the docs get better.
Starting with **0.9.1**, grc using `~/.config/grc/grc.toml` as the default configuration file.

## IDEA

If you have any new ideas, you are welcome to talk to me.

`grc` has taken over all git submissions from @sdttttt


`grc` has taken over all git submissions from @sdttttt.
6 changes: 6 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Please check these before the version is released.

1. Modify the constant in metadata.rs.
2. Modify the properties in cargo.toml.
3. Update your documents. (README)
4. Figure out the type of version you released.
3 changes: 1 addition & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ publish: fmt
$(c) publish -v

.PHONY: commit
commit: fmt test
$(g) -a .
commit: fmt test run
36 changes: 27 additions & 9 deletions src/extensions.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::env;
use std::fs;
use std::io::{Error, ErrorKind};

use serde::Deserialize;

use crate::metadata::GRC_CONFIG_FILE_NAME;
use crate::metadata::{GLOBAL_CONFIG_PATH, GRC_CONFIG_FILE_NAME};

/// Extensions is GRC future config.
#[derive(Deserialize)]
Expand All @@ -13,25 +14,42 @@ pub struct Extensions {
}

impl Extensions {

/// Read Extension from the configuration file in the convention name.
pub fn from_agreement() -> Result<Self, Error> {
/// Read Extension from the configuration file in the convention name.
pub fn from_agreement() -> Result<Self, Error> {
let file_str = Self::read_config_file(GRC_CONFIG_FILE_NAME)?;
Ok(Self::deserialize(file_str)?)
if file_str.len() == 0 {
Self::from_global()
} else {
Ok(Self::deserialize(file_str)?)
}
}

#[cfg(not(target_os = "windows"))]
pub fn from_global() -> Result<Self, Error> {
let home_dir = env::var("HOME").unwrap_or(String::new());
let file_path = format!("{}/{}", home_dir.as_str(), GLOBAL_CONFIG_PATH);
Self::from(file_path.as_str())
}

#[cfg(target_os = "windows")]
pub fn from_global() -> Result<Self, Error> {
let home_dir = env::var("USERPROFILE").unwrap_or(String::new());
let file_path = format!("{}\\{}", home_dir.as_str(), GLOBAL_CONFIG_PATH);
Self::from(file_path.as_str())
}

/// Read Extension from the configuration file in the Specified name.
/// Read Extension from the configuration file in the Specified name.
pub fn from(filename: &str) -> Result<Self, Error> {
let file_str = Self::read_config_file(filename)?;
Ok(Self::deserialize(file_str)?)
}

/// got All Types in configuration file.
/// got All Types in configuration file.
pub fn types(&self) -> &Vec<String> {
&self.typ
}

/// deserialize toml configuration file to struct.
/// deserialize toml configuration file to struct.
fn deserialize(file_str: String) -> Result<Self, Error> {
if file_str.len() == 0 || file_str == "" {
return Ok(Self { typ: vec![] });
Expand All @@ -41,7 +59,7 @@ impl Extensions {
Ok(config)
}

/// read config file convert std::string::String
/// read config file convert std::string::String
fn read_config_file(filename: &str) -> Result<String, Error> {
match fs::read_to_string(filename) {
Ok(content) => Ok(content),
Expand Down
8 changes: 4 additions & 4 deletions src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use std::fmt::Display;
use console::Style;

// GCR logger.
pub fn gcr_println(content: impl Display) {
pub fn grc_println(content: impl Display) {
println!("GRC: {}", content)
}

// GCR error logger.
pub fn gcr_err_println(content: impl Display) {
pub fn grc_err_println(content: impl Display) {
let color = Style::new().red();
let output = format!("GRC(ERROR): {}", content);

Expand All @@ -22,11 +22,11 @@ mod tests {

#[test]
fn test_gcr_println() {
gcr_println("TEST CONTENT.");
grc_println("TEST CONTENT.");
}

#[test]
fn test_gcr_err_println() {
gcr_err_println("TEST ERROR CONTENT.");
grc_err_println("TEST ERROR CONTENT.");
}
}
56 changes: 28 additions & 28 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,50 +16,50 @@ use util::*;
fn main() {
// input parameters.
let arg = match Arguments::collect() {
Ok(a) => a,
Err(e) => {
gcr_err_println(e.message());
return;
}
};
Ok(a) => a,
Err(e) => {
grc_err_println(e.message());
return;
}
};

// repository path.
let path = current_path();

// repository Object instance.
let repo = match Repository::new(path, arg) {
Ok(r) => r,
Err(e) => {
gcr_err_println(e.message());
return;
}
};
// extends types.
let mut types: Vec<String> = vec![];
// parse configuration file to Extensions struct.
Ok(r) => r,
Err(e) => {
grc_err_println(e.message());
return;
}
};

// extends types.
let mut types: Vec<String> = vec![];

// parse configuration file to Extensions struct.
if let Ok(extends) = Extensions::from_agreement() {
types = extends.types().clone();
types = extends.types().clone();
}

// commit message.
let message = Messager::new().load_ext_td(&types).ask().build();
gcr_println(&message);
// before commit hook.
if let Err(e) = repo.pre_commit() {
gcr_err_println(e.message());
return;
}
grc_println(&message);

// before commit hook.
if let Err(e) = repo.pre_commit() {
grc_err_println(e.message());
return;
}

// Git commit
if let Err(e) = repo.commit(message.as_str()) {
gcr_err_println(e.message());
grc_err_println(e.message());
}

// after commit hook.
if let Err(e) = repo.after_commit() {
gcr_err_println(e.message());
grc_err_println(e.message());
}
}
19 changes: 12 additions & 7 deletions src/message.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use dialoguer::{theme::ColorfulTheme, Input, Select};

use crate::log::grc_err_println;
use crate::metadata::*;
use crate::util::remove_pound_prefix;

Expand Down Expand Up @@ -35,12 +36,16 @@ impl Messager {
Self { commit_type_descript, typ, scope, subject, body }
}

/// Load externally provided extension types.
/// Load externally provided extension types.
pub fn load_ext_td(mut self, t: &Vec<String>) -> Self {
let mut td = t
.iter()
.map(|typ: &String| -> CommitTD {
let arr_td = typ.split(SEPARATOR_SYMBOL).collect::<Vec<&str>>();
let arr_td = typ.split(SEPARATOR_SYMBOL).collect::<Vec<&str>>();
if arr_td.len() < 2 {
grc_err_println("configuration file has not been parsed correctly. Please check your configuration content.");
std::process::exit(1);
};
CommitTD::from(arr_td[0].trim(), arr_td[1].trim())
})
.collect::<Vec<CommitTD>>();
Expand All @@ -49,7 +54,7 @@ impl Messager {
self
}

// got commit message for self.
// got commit message for self.
pub fn ask(mut self) -> Self {
self.ask_type();
self.ask_scope();
Expand Down Expand Up @@ -132,7 +137,7 @@ impl Messager {
self.scope = String::from(scope.trim())
}

/// subject of commit message.
/// subject of commit message.
fn ask_subject(&mut self) {
self.subject = Input::<String>::with_theme(&ColorfulTheme::default())
.with_prompt("GRC: Commit Message ?")
Expand All @@ -147,7 +152,7 @@ impl Messager {
.unwrap()
}

/// description of commit message.
/// description of commit message.
fn ask_description(&self) -> String {
let description = Input::<String>::with_theme(&ColorfulTheme::default())
.with_prompt("GRC: Provide a longer description? (Optional)")
Expand All @@ -158,7 +163,7 @@ impl Messager {
String::from(description.trim())
}

// close PR or issue of commit message.
// close PR or issue of commit message.
fn ask_close(&self) -> String {
let closes = Input::<String>::with_theme(&ColorfulTheme::default())
.with_prompt("GRC: PR & Issues this commit closes, e.g 123: (Optional)")
Expand All @@ -169,7 +174,7 @@ impl Messager {
String::from(remove_pound_prefix(closes.trim()))
}

// self.commit_type_descript { Vec<CommitTD> } convert to { Vec<String> }.
// self.commit_type_descript { Vec<CommitTD> } convert to { Vec<String> }.
fn type_list(&self) -> Vec<String> {
self.commit_type_descript
.iter()
Expand Down
Loading

0 comments on commit c6c056b

Please sign in to comment.