diff --git a/src/connectors/github.rs b/src/connectors/github.rs index 1486290..b35819c 100644 --- a/src/connectors/github.rs +++ b/src/connectors/github.rs @@ -31,13 +31,31 @@ impl RemoteConnector for GithubRemoteConnector { } } - fn list_remote_tasks(&self, user: &String, repo: &String, with_comments: bool, limit: Option, state: RemoteTaskState, task_statuses: &Vec) -> Vec { + fn list_remote_tasks( + &self, + user: &String, + repo: &String, + with_comments: bool, + with_labels: bool, + limit: Option, + state: RemoteTaskState, + task_statuses: &Vec + ) -> Vec { let state = match state { RemoteTaskState::Open => State::Open, RemoteTaskState::Closed => State::Closed, RemoteTaskState::All => State::All, }; - RUNTIME.block_on(list_issues(user, repo, with_comments, limit, state, task_statuses)) + RUNTIME.block_on( + list_issues( + user, + repo, + with_comments, + with_labels, + limit, + state, + task_statuses + )) } fn get_remote_task( @@ -166,7 +184,15 @@ impl RemoteConnector for GithubRemoteConnector { )] struct DeleteIssue; -async fn list_issues(user: &String, repo: &String, with_comments: bool, limit: Option, state: State, task_statuses: &Vec) -> Vec { +async fn list_issues( + user: &String, + repo: &String, + with_comments: bool, + with_labels: bool, + limit: Option, + state: State, + task_statuses: &Vec +) -> Vec { let mut result = vec![]; let crab = get_octocrab_instance().await; let stream = crab.issues(user, repo) @@ -197,6 +223,19 @@ async fn list_issues(user: &String, repo: &String, with_comments: bool, limit: O task.set_comments(task_comments); } + if with_labels { + if !issue.labels.is_empty() { + let labels = issue.labels.iter() + .map(|l| Label::new( + l.name.clone(), + Some(l.color.clone()), + l.description.clone() + )) + .collect(); + task.set_labels(labels); + } + } + result.push(task); } diff --git a/src/connectors/gitlab.rs b/src/connectors/gitlab.rs index d21b03d..fe61796 100644 --- a/src/connectors/gitlab.rs +++ b/src/connectors/gitlab.rs @@ -67,6 +67,7 @@ impl RemoteConnector for GitlabRemoteConnector { user: &String, repo: &String, with_comments: bool, + with_labels: bool, limit: Option, state: RemoteTaskState, task_statuses: &Vec @@ -77,6 +78,25 @@ impl RemoteConnector for GitlabRemoteConnector { RemoteTaskState::All => None }; let client = get_client(get_token_from_env().unwrap().as_str()); + + let labels = match with_labels { + true => { + let mut endpoint = gitlab::api::projects::labels::Labels::builder(); + let endpoint = endpoint.project(user.to_string() + "/" + repo); + let endpoint = endpoint.build().unwrap(); + let labels: Vec = gitlab::api::paged(endpoint, Pagination::All).query(&client).unwrap(); + let labels = labels.iter() + .map(|gl| Label::new( + gl.name.to_string(), + Some(gl.color.to_string()), + Some(gl.description.to_string()) + )) + .collect::>(); + labels + }, + false => vec![] + }; + let mut endpoint = gitlab::api::issues::ProjectIssues::builder(); let mut endpoint = endpoint.project(user.to_string() + "/" + repo).scope(IssueScope::All); endpoint = match state { @@ -105,6 +125,16 @@ impl RemoteConnector for GitlabRemoteConnector { task.set_comments(comments); } + if with_labels { + let labels = issue.labels.iter() + .filter_map(|l| match labels.iter().find(|label| label.get_name() == l.to_string()) { + Some(label) => Some(label.clone()), + None => None + }) + .collect::>(); + task.set_labels(labels); + } + result.push(task); } diff --git a/src/connectors/mod.rs b/src/connectors/mod.rs index 38dc084..f1e9ae5 100644 --- a/src/connectors/mod.rs +++ b/src/connectors/mod.rs @@ -14,7 +14,7 @@ pub enum RemoteTaskState { pub trait RemoteConnector { fn supports_remote(&self, url: &str) -> Option<(String, String)>; - fn list_remote_tasks(&self, user: &String, repo: &String, with_comments: bool, limit: Option, state: RemoteTaskState, task_statuses: &Vec) -> Vec; + fn list_remote_tasks(&self, user: &String, repo: &String, with_comments: bool, with_labels: bool, limit: Option, state: RemoteTaskState, task_statuses: &Vec) -> Vec; fn get_remote_task(&self, user: &String, repo: &String, task_id: &String, with_comments: bool, with_labels: bool, task_statuses: &Vec) -> Option; fn create_remote_task(&self, user: &String, repo: &String, task: &Task) -> Result; fn create_remote_comment(&self, user: &String, repo: &String, task_id: &String, comment: &Comment) -> Result; diff --git a/src/operations.rs b/src/operations.rs index 963db96..6f221d7 100644 --- a/src/operations.rs +++ b/src/operations.rs @@ -315,7 +315,7 @@ pub(crate) fn task_pull( None => RemoteTaskState::All }; - let tasks = connector.list_remote_tasks(&user, &repo, !no_comments, limit, state, &task_statuses); + let tasks = connector.list_remote_tasks(&user, &repo, !no_comments, !no_labels, limit, state, &task_statuses); if tasks.is_empty() { success_message("No tasks found".to_string())