Skip to content

Commit

Permalink
feat: issue list
Browse files Browse the repository at this point in the history
  • Loading branch information
williamfzc committed Mar 8, 2024
1 parent 3e34a2f commit 456c189
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
9 changes: 2 additions & 7 deletions src/relation/graph_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ impl RelationGraph {
return self.find_related(commit_name, &self.commit_mapping, &self.author_mapping);
}

pub fn authors(&self) -> Result<Vec<String>, Error> {
let keys: Vec<String> = self
.author_mapping
.keys()
.map(|key| key.as_ref().clone())
.collect();
return Ok(keys);
pub fn authors(&self) -> Vec<String> {
return self.get_keys(&self.author_mapping);
}
}
17 changes: 14 additions & 3 deletions src/relation/graph_query.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::relation::graph::{GraphSize, NodeData, RelationGraph};
use crate::relation::graph::{GraphSize, NodeData, NodeMapping, RelationGraph};
use std::fmt::Error;

/// query API
Expand All @@ -15,11 +15,22 @@ impl RelationGraph {
self.issue_mapping.get(name)
}

pub(crate) fn get_keys(&self, node_mapping: &NodeMapping) -> Vec<String> {
return node_mapping
.keys()
.map(|key| key.as_ref().clone())
.collect();
}

pub fn issues(&self) -> Vec<String> {
return self.get_keys(&self.issue_mapping);
}

pub(crate) fn find_related(
&self,
entry: &String,
src: &crate::relation::graph::NodeMapping,
target: &crate::relation::graph::NodeMapping,
src: &NodeMapping,
target: &NodeMapping,
) -> Result<Vec<String>, Error> {
if !src.contains_key(entry) {
return Err(Error::default());
Expand Down
9 changes: 8 additions & 1 deletion src/server/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ pub fn create_router() -> Router {
"/issue",
Router::new()
.route("/-/files", get(issue_related_files_handler))
.route("/-/commits", get(issue_related_commits_handler)),
.route("/-/commits", get(issue_related_commits_handler))
.route("/list", get(issues)),
)
.nest(
"/commit",
Expand Down Expand Up @@ -103,6 +104,12 @@ async fn issue_related_commits_handler(
};
}

async fn issues() -> axum::Json<Vec<String>> {
let conf = crate::server::app::SERVER_CONFIG.read().unwrap();
return axum::Json(conf.graph.issues());
}


async fn commit_related_files_handler(
Query(params): Query<CommitParams>,
) -> axum::Json<Vec<String>> {
Expand Down
8 changes: 1 addition & 7 deletions src/server/handler_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,5 @@ pub(crate) async fn commit_related_authors_handler(

pub(crate) async fn authors() -> axum::Json<Vec<String>> {
let conf = crate::server::app::SERVER_CONFIG.read().unwrap();
return match conf.graph.authors() {
Ok(authors) => axum::Json(authors),
Err(error) => {
error!("authors error: {}", error);
axum::Json(Vec::new())
}
};
return axum::Json(conf.graph.authors());
}
9 changes: 8 additions & 1 deletion tests/graph_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ fn graph_query() {
"Issue should be related to at least one file"
);

// Test Issues
let issues = graph.issues();
assert!(
!issues.is_empty(),
"Issue should not be empty"
);

// Print results for inspection
println!("File: {}", file_name);
println!("File-related issues: {:?}", issues);
Expand All @@ -61,7 +68,7 @@ fn graph_ext() {
let collector = get_collector();
let graph = collector.walk(config);

assert!(graph.authors().is_ok());
assert!(!graph.authors().is_empty());
assert!(graph
.author_related_commits(&String::from("williamfzc <[email protected]>"))
.is_ok());
Expand Down

0 comments on commit 456c189

Please sign in to comment.