Skip to content

Commit a416adc

Browse files
committed
Jira: create issues
1 parent 88c7b04 commit a416adc

File tree

8 files changed

+155
-60
lines changed

8 files changed

+155
-60
lines changed

src/confluence.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mod conf_run;

src/confluence/conf_run.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
use crate::labels::labels::LabelService;
2+
3+
async fn run() {
4+
// =============== get page
5+
// let pages = get_descendants(conf_url, token, "1213317".to_string()).await;
6+
// pages.results.iter().for_each(|p| println!("{:?}", p.title));
7+
8+
// =============== get space
9+
// let space = get_space(conf_url, token, "dev16".to_string()).await;
10+
// println!("{:?}", space);
11+
12+
// =============== get spaces
13+
// let mut space_service = SpaceService { spaces: vec![] };
14+
// let vec1 = space_service.get_spaces(&conf_url, &token).await;
15+
// println!("{:?}", vec1);
16+
17+
// =============== CREATE PAGEs
18+
// let space_key = "dev3";
19+
// let parent = 1212664;
20+
//
21+
// for a in 1..20 {
22+
// let title = format!("Rust page {a}");
23+
//
24+
// let req = CreatePage {
25+
// title: title.to_string(),
26+
// ctype: "page".to_string(),
27+
// space: CreatePageSpace {
28+
// key: space_key.to_string(),
29+
// },
30+
// body: PageBody {
31+
// storage: Storage {
32+
// representation: "storage".to_string(),
33+
// value: helpers::helpers::rand_string(30).to_string(),
34+
// },
35+
// },
36+
// ancestors: vec![Ancestor {
37+
// id: parent,
38+
// }],
39+
// };
40+
// let resp = create_page(&conf_url, &token, req).await;
41+
// println!("{:?}", resp);
42+
// }
43+
44+
// ========= add labels
45+
// let ls = LabelService{labels: vec![]};
46+
// let label = String::from("bbb");
47+
// ls.add_label(conf_url, token, "2523141".to_string(), vec![label]).await;
48+
}

src/jira.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
pub(crate) mod jira_models;
2+
3+
pub mod jira {
4+
use reqwest::Response;
5+
use crate::jira::jira_models::jira_models::CreateIssue;
6+
7+
pub struct JiraClient {}
8+
9+
pub struct IssueService();
10+
11+
impl IssueService {
12+
pub async fn create_issue(&self, url: &str, token: String, issue: CreateIssue) -> String {
13+
let req_url = format!("{url}/rest/api/2/issue");
14+
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+
"#;
42+
let resp: Response = client.post(&req_url)
43+
.body(body)
44+
.header("Authorization", format!("Basic {token}"))
45+
.header("Accept", "application/json")
46+
.header("Content-Type", "application/json")
47+
.send().await.unwrap();
48+
let body = resp.text().await.unwrap();
49+
return body;
50+
}
51+
}
52+
}

src/jira/jira_models.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
pub mod jira_models {
2+
use serde::{Deserialize, Serialize};
3+
4+
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
5+
#[allow(non_snake_case)]
6+
pub struct Issue {
7+
pub id: String,
8+
pub key: String,
9+
pub proj_key: String,
10+
pub summary: String,
11+
pub description: String,
12+
}
13+
14+
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
15+
#[allow(non_snake_case)]
16+
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>,
22+
}
23+
24+
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
25+
#[allow(non_snake_case)]
26+
pub struct Fields {
27+
28+
}
29+
30+
31+
32+
}

src/jira/models.rs

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/labels.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub mod labels {
2222
}
2323

2424
impl LabelService {
25-
pub async fn add_label(url: &str, token: String, id: String, labels: Vec<String>) -> String {
25+
pub async fn add_label(&self, url: &str, token: String, id: String, labels: Vec<String>) -> String {
2626
let mut labels_vec: Vec<AddLabel> = vec![];
2727
for label in labels {
2828
labels_vec.push(AddLabel {
@@ -33,13 +33,13 @@ pub mod labels {
3333
let request_url = format!("{url}/rest/api/content/{id}/label/");
3434
let client = reqwest::Client::new();
3535
let resp: Response = client.post(&request_url)
36-
.body(labels_vec)
36+
.json(&labels_vec)
3737
.header("Authorization", format!("Basic {token}"))
3838
.header("Accept", "application/json")
3939
.header("Content-Type", "application/json")
4040
.send().await.unwrap();
4141
let body = resp.text().await.unwrap();
42-
return serde_json::from_str(body.as_str()).unwrap();
42+
return body;
4343
}
4444
}
4545
}

src/main.rs

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ mod helpers;
33
mod model;
44
mod spaces;
55
mod labels;
6+
mod jira;
7+
mod confluence;
68

79
use std::fmt::format;
810
use std::future::Future;
911
use std::iter::Map;
1012
use reqwest::{Body, Error};
1113
use serde_json::{json, Value};
1214
use tokio::time::Instant;
15+
use crate::labels::labels::LabelService;
1316
use crate::model::models::{Ancestor, CreatePage, CreatePageSpace, PageBody, Storage};
17+
use crate::jira::jira_models::jira_models::CreateIssue;
1418
use crate::pages::page_service::{create_page, get_children, get_descendants, get_page};
1519
use crate::spaces::spaces::{SpaceService};
1620

@@ -22,50 +26,17 @@ async fn main() -> Result<(), Error> {
2226

2327
// data
2428
let token = base64::encode(b"admin:admin");
25-
let conf_url = "http://localhost:8110";
26-
27-
// =============== get page
28-
// let pages = get_descendants(conf_url, token, "1213317".to_string()).await;
29-
// pages.results.iter().for_each(|p| println!("{:?}", p.title));
30-
31-
// =============== get space
32-
// let space = get_space(conf_url, token, "dev16".to_string()).await;
33-
// println!("{:?}", space);
34-
35-
// =============== get spaces
36-
let mut space_service = SpaceService { spaces: vec![] };
37-
let vec1 = space_service.get_spaces(&conf_url, &token).await;
38-
println!("{:?}", vec1);
39-
40-
// =============== CREATE PAGEs
41-
// let space_key = "dev3";
42-
// let parent = 1212664;
43-
//
44-
// for a in 1..20 {
45-
// let title = format!("Rust page {a}");
46-
//
47-
// let req = CreatePage {
48-
// title: title.to_string(),
49-
// ctype: "page".to_string(),
50-
// space: CreatePageSpace {
51-
// key: space_key.to_string(),
52-
// },
53-
// body: PageBody {
54-
// storage: Storage {
55-
// representation: "storage".to_string(),
56-
// value: helpers::helpers::rand_string(30).to_string(),
57-
// },
58-
// },
59-
// ancestors: vec![Ancestor {
60-
// id: parent,
61-
// }],
62-
// };
63-
// let resp = create_page(&conf_url, &token, req).await;
64-
// println!("{:?}", resp);
65-
// }
29+
let conf_url = "http://localhost:9500";
6630

31+
let is = jira::jira::IssueService();
32+
let result = is.create_issue(conf_url, token, CreateIssue {
33+
Type: "".to_string(),
34+
fields: None,
35+
});
36+
println!("{:?}", result.await);
6737

6838

39+
// end
6940
let mut end: u128 = start.elapsed().as_millis();
7041
println!("{:?}", println!(">>> Action took :: {end} millis"));
7142

src/model/space.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pub mod space {
22
use serde::{Deserialize, Serialize};
33

4-
#[derive(Deserialize, Serialize, Debug)]
4+
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
55
pub struct Space {
66
pub id: i64,
77
pub key: String,
@@ -13,7 +13,7 @@ pub mod space {
1313
pub _expandable: SpaceExpandable
1414
}
1515

16-
#[derive(Deserialize, Serialize, Debug)]
16+
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
1717
pub struct Spaces {
1818
pub results: Vec<SpaceResult>,
1919
pub start: i8,
@@ -22,7 +22,7 @@ pub mod space {
2222
pub _links: SpacesLinks,
2323
}
2424

25-
#[derive(Deserialize, Serialize, Debug)]
25+
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
2626
pub struct SpaceResult {
2727
pub id: i64,
2828
pub key: String,
@@ -34,7 +34,7 @@ pub mod space {
3434
pub _expandable: SpaceExpandable
3535
}
3636

37-
#[derive(Deserialize, Serialize, Debug)]
37+
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
3838
pub struct SpaceLinks {
3939
pub webui: String,
4040
pub collection: String,
@@ -47,7 +47,7 @@ pub mod space {
4747
pub sself: String,
4848
}
4949

50-
#[derive(Deserialize, Serialize, Debug)]
50+
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
5151
pub struct SpaceResultLinks {
5252
pub webui: String,
5353
#[serde(rename(serialize = "self"))]
@@ -56,7 +56,7 @@ pub mod space {
5656
pub sself: String,
5757
}
5858

59-
#[derive(Deserialize, Serialize, Debug)]
59+
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
6060
pub struct SpacesLinks {
6161
#[serde(rename(serialize = "self"))]
6262
#[serde(rename(deserialize = "self"))]
@@ -80,7 +80,7 @@ pub mod space {
8080
pub homepage: String,
8181
}
8282

83-
#[derive(Deserialize, Serialize, Debug)]
83+
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
8484
pub struct CreateSpace {
8585
pub key: String,
8686
pub name: String,

0 commit comments

Comments
 (0)