Skip to content

Commit

Permalink
feat: expose more raw api
Browse files Browse the repository at this point in the history
  • Loading branch information
williamfzc committed Dec 23, 2024
1 parent dd17eff commit d299b29
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/api.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::graph::{Graph, RelatedSymbol};
use crate::symbol::{DefRefPair, Symbol, SymbolKind};
use pyo3::{pyclass, pymethods};
use serde::{Deserialize, Serialize};
use std::cmp::Reverse;
use std::collections::{HashMap, HashSet};
use pyo3::{pyclass, pymethods};

#[derive(Serialize, Deserialize, Clone)]
#[pyclass]
Expand Down Expand Up @@ -131,11 +131,14 @@ impl Graph {
.cloned()
.collect();

let commit_sha_list = self._relation_graph.file_related_commits(&file_name).unwrap_or_default();
let commit_sha_list = self
._relation_graph
.file_related_commits(&file_name)
.unwrap_or_default();
FileMetadata {
path: file_name,
commits: commit_sha_list,
symbols
symbols,
}
}

Expand All @@ -145,4 +148,14 @@ impl Graph {
}
self.symbol_graph.pairs_between_files(&src_file, &dst_file)
}
}

pub fn list_file_issues(&self, file_name: String) -> Vec<String> {
let result = self._relation_graph.file_related_issues(&file_name);
result.unwrap_or_default()
}

pub fn list_file_commits(&self, file_name: String) -> Vec<String> {
let result = self._relation_graph.file_related_commits(&file_name);
result.unwrap_or_default()
}
}
14 changes: 14 additions & 0 deletions src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ impl Graph {
conf.depth,
conf.exclude_author_regex,
conf.exclude_commit_regex,
conf.issue_regex,
);
let size = relation_graph.size();
info!("relation graph ready, size: {:?}", size);
Expand Down Expand Up @@ -510,12 +511,16 @@ fn create_cupido_graph(
depth: u32,
exclude_author_regex: Option<String>,
exclude_commit_regex: Option<String>,
issue_regex: Option<String>,
) -> CupidoRelationGraph {
let mut conf = Config::default();
conf.repo_path = project_path.parse().unwrap();
conf.depth = depth;
conf.author_exclude_regex = exclude_author_regex;
conf.commit_exclude_regex = exclude_commit_regex;
if issue_regex.is_some() {
conf.issue_regex = issue_regex.unwrap();
}

let collector = get_collector();
let graph = collector.walk(conf);
Expand Down Expand Up @@ -558,6 +563,9 @@ pub struct GraphConfig {
pub exclude_author_regex: Option<String>,
#[pyo3(get, set)]
pub exclude_commit_regex: Option<String>,

#[pyo3(get, set)]
pub issue_regex: Option<String>,
}

#[pymethods]
Expand All @@ -574,6 +582,7 @@ impl GraphConfig {
exclude_file_regex: String::new(),
exclude_author_regex: None,
exclude_commit_regex: None,
issue_regex: None,
}
}
}
Expand Down Expand Up @@ -683,5 +692,10 @@ mod tests {
pair.dst_symbol.range.start_point.row
);
});

let issues = g.list_file_issues(String::from("src/extractor.rs"));
let commits = g.list_file_commits(String::from("src/graph.rs"));
assert!(issues.len() > 0);
assert!(commits.len() > 0);
}
}

0 comments on commit d299b29

Please sign in to comment.