Skip to content

Commit

Permalink
actually import issues from Gitlab
Browse files Browse the repository at this point in the history
  • Loading branch information
jhspetersson committed Sep 24, 2024
1 parent 49e1df7 commit 88edc26
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
4 changes: 3 additions & 1 deletion src/connectors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod gitlab;

use gittask::{Comment, Task};
use crate::connectors::github::GithubRemoteConnector;
use crate::connectors::gitlab::GitlabRemoteConnector;

pub enum RemoteTaskState {
All,
Expand All @@ -22,8 +23,9 @@ pub trait RemoteConnector {
fn delete_remote_comment(&self, user: &String, repo: &String, comment_id: &String) -> Result<(), String>;
}

const CONNECTORS: [&dyn RemoteConnector; 1] = [
const CONNECTORS: [&dyn RemoteConnector; 2] = [
&GithubRemoteConnector,
&GitlabRemoteConnector,
];

pub fn get_matching_remote_connectors(remotes: Vec<String>) -> Vec<(Box<&'static dyn RemoteConnector>, String, String)> {
Expand Down
33 changes: 19 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,21 +214,26 @@ pub fn list_tasks() -> Result<Vec<Task>, String> {

pub fn find_task(id: &str) -> Result<Option<Task>, String> {
let repo = map_err!(Repository::discover("."));
let task_ref = map_err!(repo.find_reference(&get_ref_path()));
let task_tree = map_err!(task_ref.peel_to_tree());
let result = match task_tree.get_name(id) {
Some(entry) => {
let oid = entry.id();
let blob = map_err!(repo.find_blob(oid));
let content = blob.content();
let task = serde_json::from_slice(content).unwrap();

Some(task)
let task_ref = repo.find_reference(&get_ref_path());
match task_ref {
Ok(task_ref) => {
let task_tree = map_err!(task_ref.peel_to_tree());
let result = match task_tree.get_name(id) {
Some(entry) => {
let oid = entry.id();
let blob = map_err!(repo.find_blob(oid));
let content = blob.content();
let task = serde_json::from_slice(content).unwrap();

Some(task)
},
None => None,
};

Ok(result)
},
None => None,
};

Ok(result)
Err(_) => Ok(None)
}
}

pub fn delete_tasks(ids: &[&str]) -> Result<(), String> {
Expand Down
4 changes: 2 additions & 2 deletions src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,11 @@ fn get_user_repo(remote: &Option<String>) -> Result<(Box<&'static dyn RemoteConn
Ok(remotes) => {
let user_repo = get_matching_remote_connectors(remotes);
if user_repo.is_empty() {
return Err("No GitHub remotes".to_string());
return Err("No passing remotes".to_string());
}

if user_repo.len() > 1 {
return Err("More than one GitHub remote found. Please specify with --remote option.".to_owned());
return Err("More than one passing remote found. Please specify with --remote option.".to_owned());
}

Ok(user_repo.first().unwrap().clone())
Expand Down

0 comments on commit 88edc26

Please sign in to comment.