Skip to content

Commit cf6ef95

Browse files
committed
Jira: create issues
1 parent a416adc commit cf6ef95

File tree

5 files changed

+62
-46
lines changed

5 files changed

+62
-46
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ edition = "2021"
55
authors = ["Andrii Maliuta"]
66

77
[workspace]
8-
#members=[
9-
# "srv",
10-
#]
11-
128
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
139

1410
[dependencies]
@@ -17,5 +13,5 @@ serde = { version = "1.0", features = ["derive"] }
1713
reqwest = { version = "0.11.12", features = ["json"] }
1814
tokio = { version = "1.21.2", features = ["full"] }
1915
base64 = "0.21.0"
20-
mongodb = "2.3.1"
21-
rand = "0.8.5"
16+
rand = "0.8.5"
17+
chrono = "0.4.24"

src/jira.rs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,9 @@ pub mod jira {
1212
pub async fn create_issue(&self, url: &str, token: String, issue: CreateIssue) -> String {
1313
let req_url = format!("{url}/rest/api/2/issue");
1414
let client = reqwest::Client::new();
15-
let body = r#"{
16-
"fields": {
17-
"project": {
18-
"id": "10000"
19-
},
20-
"summary": "Test Rust",
21-
"issuetype": {
22-
"id": "10006"
23-
},
24-
"assignee": {
25-
"name": "admin"
26-
},
27-
"reporter": {
28-
"name": "admin"
29-
},
30-
"priority": {
31-
"id": "3"
32-
},
33-
"labels": [
34-
"a",
35-
"b"
36-
],
37-
"description": "Test",
38-
"duedate": "2023-04-11"
39-
}
40-
}
41-
"#;
15+
4216
let resp: Response = client.post(&req_url)
43-
.body(body)
17+
.json(&issue)
4418
.header("Authorization", format!("Basic {token}"))
4519
.header("Accept", "application/json")
4620
.header("Content-Type", "application/json")

src/jira/jira_models.rs

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,57 @@ pub mod jira_models {
1212
}
1313

1414
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
15-
#[allow(non_snake_case)]
15+
#[serde(rename_all = "camelCase")]
1616
pub struct CreateIssue {
17-
#[serde(rename(serialize = "type"))]
18-
#[serde(rename(deserialize = "type"))]
19-
pub Type: String,
20-
#[serde(skip_serializing_if = "Option::is_none")]
21-
pub fields: Option<Fields>,
17+
pub fields: Fields,
2218
}
2319

2420
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
25-
#[allow(non_snake_case)]
21+
#[serde(rename_all = "camelCase")]
2622
pub struct Fields {
23+
pub project: Project,
24+
pub summary: String,
25+
pub issuetype: Issuetype,
26+
pub assignee: Assignee,
27+
pub reporter: Reporter,
28+
pub priority: Priority,
29+
pub labels: Vec<String>,
30+
pub description: String,
31+
pub duedate: String,
32+
}
33+
34+
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
35+
#[serde(rename_all = "camelCase")]
36+
pub struct Project {
37+
pub id: String,
38+
}
2739

40+
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
41+
#[serde(rename_all = "camelCase")]
42+
pub struct Issuetype {
43+
pub id: String,
2844
}
2945

46+
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
47+
#[serde(rename_all = "camelCase")]
48+
pub struct Assignee {
49+
pub name: String,
50+
}
51+
52+
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
53+
#[serde(rename_all = "camelCase")]
54+
pub struct Reporter {
55+
pub name: String,
56+
}
57+
58+
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
59+
#[serde(rename_all = "camelCase")]
60+
pub struct Priority {
61+
pub id: String,
62+
}
63+
64+
65+
3066

3167

3268
}

src/main.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use serde_json::{json, Value};
1414
use tokio::time::Instant;
1515
use crate::labels::labels::LabelService;
1616
use crate::model::models::{Ancestor, CreatePage, CreatePageSpace, PageBody, Storage};
17-
use crate::jira::jira_models::jira_models::CreateIssue;
17+
use crate::jira::jira_models::jira_models::{Assignee, CreateIssue, Fields, Issuetype, Priority, Project, Reporter};
1818
use crate::pages::page_service::{create_page, get_children, get_descendants, get_page};
1919
use crate::spaces::spaces::{SpaceService};
2020

@@ -30,8 +30,17 @@ async fn main() -> Result<(), Error> {
3030

3131
let is = jira::jira::IssueService();
3232
let result = is.create_issue(conf_url, token, CreateIssue {
33-
Type: "".to_string(),
34-
fields: None,
33+
fields: Fields {
34+
project: Project { id: "10000".to_string() },
35+
summary: "test".to_string(),
36+
issuetype: Issuetype{ id: "10006".to_string() },
37+
assignee: Assignee{ name: "admin".to_string() },
38+
reporter: Reporter{ name: "admin".to_string() },
39+
priority: Priority{ id: "3".to_string() },
40+
labels: vec![],
41+
description: "test".to_string(),
42+
duedate: chrono::DateTime::date_naive().to_string(),
43+
},
3544
});
3645
println!("{:?}", result.await);
3746

0 commit comments

Comments
 (0)