Add an issue get command to the client and use it for the view command
This commit is contained in:
parent
194e25dc14
commit
07864325d7
3 changed files with 38 additions and 16 deletions
|
@ -2,7 +2,7 @@ use crate::cli::FormatMode;
|
||||||
use crate::jira_config::JiraConfig;
|
use crate::jira_config::JiraConfig;
|
||||||
use crate::term::hyperlink;
|
use crate::term::hyperlink;
|
||||||
use crossterm::style::{Color, Stylize};
|
use crossterm::style::{Color, Stylize};
|
||||||
use libjirac::client::commands::{SearchCommand, SelfCommand};
|
use libjirac::client::commands::IssueGetCommand;
|
||||||
use libjirac::client::JiraClient;
|
use libjirac::client::JiraClient;
|
||||||
use libjirac::entities::issue::JiraIssue;
|
use libjirac::entities::issue::JiraIssue;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
@ -102,23 +102,10 @@ pub async fn exec(output: FormatMode, issue_key: &str) -> Result<(), Box<dyn std
|
||||||
println!("Loading issue data");
|
println!("Loading issue data");
|
||||||
}
|
}
|
||||||
|
|
||||||
let jql = format!("key = '{}'", issue_key);
|
|
||||||
|
|
||||||
let client = JiraClient::from(&config);
|
let client = JiraClient::from(&config);
|
||||||
|
|
||||||
let jql_cmd = SearchCommand::new(&jql);
|
let get_cmd = IssueGetCommand::new(issue_key);
|
||||||
let matched_issues = client.exec(jql_cmd).await?;
|
let fetched_issue = client.exec(get_cmd).await?;
|
||||||
|
|
||||||
let matched_issue = match matched_issues.issues.first() {
|
|
||||||
Some(x) => x,
|
|
||||||
None => {
|
|
||||||
eprintln!("No issue found with that key");
|
|
||||||
std::process::exit(1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let self_cmd = SelfCommand::<JiraIssue>::new(&matched_issue.href);
|
|
||||||
let fetched_issue = client.exec(self_cmd).await?;
|
|
||||||
|
|
||||||
match output {
|
match output {
|
||||||
FormatMode::Pretty => pretty_print(&fetched_issue)?,
|
FormatMode::Pretty => pretty_print(&fetched_issue)?,
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
mod issue_create_command;
|
mod issue_create_command;
|
||||||
|
mod issue_get_command;
|
||||||
mod issue_transitions_command;
|
mod issue_transitions_command;
|
||||||
mod issue_transitions_update_command;
|
mod issue_transitions_update_command;
|
||||||
mod search_command;
|
mod search_command;
|
||||||
mod self_command;
|
mod self_command;
|
||||||
|
|
||||||
pub use issue_create_command::IssueCreateCommand;
|
pub use issue_create_command::IssueCreateCommand;
|
||||||
|
pub use issue_get_command::IssueGetCommand;
|
||||||
pub use issue_transitions_command::IssueTransitionsCommand;
|
pub use issue_transitions_command::IssueTransitionsCommand;
|
||||||
pub use issue_transitions_update_command::IssueTransitionsUpdateCommand;
|
pub use issue_transitions_update_command::IssueTransitionsUpdateCommand;
|
||||||
pub use search_command::SearchCommand;
|
pub use search_command::SearchCommand;
|
||||||
|
|
33
crates/libjirac/src/client/commands/issue_get_command.rs
Normal file
33
crates/libjirac/src/client/commands/issue_get_command.rs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
use crate::client::{JiraCommand, JiraRequestType};
|
||||||
|
use crate::entities::issue::JiraIssue;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct IssueGetCommand {
|
||||||
|
pub key: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IssueGetCommand {
|
||||||
|
pub fn new(key: &str) -> Self {
|
||||||
|
Self {
|
||||||
|
key: key.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl JiraCommand for IssueGetCommand {
|
||||||
|
type TResponse = JiraIssue;
|
||||||
|
type TPayload = ();
|
||||||
|
const REQUEST_TYPE: JiraRequestType = JiraRequestType::Read;
|
||||||
|
|
||||||
|
fn endpoint(&self) -> String {
|
||||||
|
format!("/rest/api/2/issue/{}", self.key)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn request_body(&self) -> Option<&Self::TPayload> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn query_params(&self) -> Option<Vec<(String, String)>> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue