-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcreate_support_ticket.rs
89 lines (86 loc) · 2.92 KB
/
create_support_ticket.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use super::ConfigSettings;
use goji::issues::*;
use goji::{Credentials, Jira};
use helpers::error::*;
use log::debug;
use serde_json::value::Value;
/// Create a new JIRA support ticket and return the ticket ID associated with it
pub fn create_support_ticket(
settings: &ConfigSettings,
title: &str,
description: &str,
) -> BynarResult<String> {
let issue_description = CreateIssue {
fields: Fields {
assignee: Assignee {
name: settings.jira_ticket_assignee.clone(),
},
components: vec![Component {
name: "Ceph".into(),
}],
description: description.into(),
issuetype: IssueType {
id: settings.jira_issue_type.clone(),
},
priority: Priority {
id: settings.jira_priority.clone(),
},
project: Project {
key: settings.jira_project_id.clone(),
},
summary: title.into(),
},
};
let jira: Jira = match settings.proxy {
Some(ref url) => {
let client = reqwest::Client::builder()
.proxy(reqwest::Proxy::all(url)?)
.build()?;
Jira::from_client(
settings.jira_host.to_string(),
Credentials::Basic(settings.jira_user.clone(), settings.jira_password.clone()),
client,
)?
}
None => Jira::new(
settings.jira_host.to_string(),
Credentials::Basic(settings.jira_user.clone(), settings.jira_password.clone()),
)?,
};
let issue = Issues::new(&jira);
debug!(
"Creating JIRA ticket with information: {:?}",
issue_description
);
let results = issue.create(issue_description)?;
Ok(results.id)
}
/// Check to see if a JIRA support ticket is marked as resolved
pub fn ticket_resolved(settings: &ConfigSettings, issue_id: &str) -> BynarResult<bool> {
let jira: Jira = match settings.proxy {
Some(ref url) => {
let client = reqwest::Client::builder()
.proxy(reqwest::Proxy::all(url)?)
.build()?;
Jira::from_client(
settings.jira_host.to_string(),
Credentials::Basic(settings.jira_user.clone(), settings.jira_password.clone()),
client,
)?
}
None => Jira::new(
settings.jira_host.to_string(),
Credentials::Basic(settings.jira_user.clone(), settings.jira_password.clone()),
)?,
};
let issue = Issues::new(&jira);
debug!("Fetching issue: {} for resolution information", issue_id);
let results = issue.get(issue_id)?;
match results.fields.get("resolutiondate") {
Some(Value::Null) => Ok(false),
Some(Value::String(_)) => Ok(true),
Some(_) => Ok(false),
//resolutiondate doesn't exist
None => Ok(false),
}
}