Skip to content

Commit

Permalink
feat: add parse for story id
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Mar 17, 2021
1 parent 4102e82 commit 071e717
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions core_model/src/coco_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct CocoConfig {
#[serde(skip_serializing_if = "Option::is_none")]
pub plugins: Option<Vec<CocoPlugin>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub commit_config: Option<Vec<CocoCommitConfig>>,
pub commit_config: Option<CocoCommitConfig>,
}

/// Coco Commit Config from `coco.yml`
Expand All @@ -22,7 +22,7 @@ pub struct CocoCommitConfig {

#[allow(dead_code)]
impl CocoCommitConfig {
fn verify_config(config: &CocoCommitConfig) -> Result<HashMap<String, String>, String> {
pub fn verify_config(config: &CocoCommitConfig) -> Result<HashMap<String, String>, String> {
let mut items: HashMap<String, String> = Default::default();
match Regex::new(&config.regex) {
Ok(re) => {
Expand Down
20 changes: 16 additions & 4 deletions src/app/analysis/git_analysis/commit_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ShortCommit {
pub branch: String,
pub story_id: String,
pub commit_id: String,
pub author: String,
pub email: String,
Expand All @@ -21,9 +22,10 @@ pub struct ShortCommit {
}

impl ShortCommit {
pub fn convert(commit: CocoCommit) -> ShortCommit {
Self {
pub fn convert(commit: CocoCommit, commit_config: &Option<CocoCommitConfig>) -> ShortCommit {
let mut short_commit = Self {
branch: commit.branch,
story_id: "".to_string(),
commit_id: commit.commit_id,
author: commit.author,
email: commit.email,
Expand All @@ -34,19 +36,29 @@ impl ShortCommit {
total_added: commit.total_added,
total_deleted: commit.total_deleted,
changed_file_count: commit.changed_file_count,
};

if let Some(config) = commit_config {
if let Ok(hash) = CocoCommitConfig::verify_config(config) {
if let Some(id) = hash.get("id") {
short_commit.story_id = String::from(id)
}
}
}

short_commit
}
}

pub fn analysis(url: &str, commit_config: Option<Vec<CocoCommitConfig>>) -> Vec<ShortCommit> {
pub fn analysis(url: &str, commit_config: Option<CocoCommitConfig>) -> Vec<ShortCommit> {
let local_path = url_format::uri_to_path(url);

let messages = commit_message(Some(format!("{}", local_path.display())));
let vec = GitMessageParser::parse(messages.as_str());

let mut results = vec![];
for commit in vec {
results.push(ShortCommit::convert(commit))
results.push(ShortCommit::convert(commit, &commit_config))
}

return results;
Expand Down
4 changes: 2 additions & 2 deletions src/app/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::time::Instant;

pub struct Analyst {
repos: Vec<RepoConfig>,
commit_config: Option<Vec<CocoCommitConfig>>,
commit_config: Option<CocoCommitConfig>,
}

impl From<&CocoConfig> for Analyst {
Expand Down Expand Up @@ -96,7 +96,7 @@ fn analysis_file_history(url_str: &str, git_years: f64) {
fs::write(output_file, result).expect("cannot write file");
}

fn analysis_commits(url_str: &str, commit_config: Option<Vec<CocoCommitConfig>>) {
fn analysis_commits(url_str: &str, commit_config: Option<CocoCommitConfig>) {
let branches = commit_analysis::analysis(url_str, commit_config);
let file_name = url_format::json_filename_suffix(url_str, Some("-commits"));

Expand Down

0 comments on commit 071e717

Please sign in to comment.