2020-06-13 15:07:21 -04:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
|
|
use colored::*;
|
2021-12-18 20:08:46 -05:00
|
|
|
use reqwest::StatusCode;
|
2020-06-13 15:07:21 -04:00
|
|
|
use serde_derive::{Serialize, Deserialize};
|
2021-12-18 20:08:46 -05:00
|
|
|
use serde_json::Value;
|
2020-06-13 15:07:21 -04:00
|
|
|
|
2021-12-18 20:08:46 -05:00
|
|
|
use crate::request::Request;
|
|
|
|
|
use crate::util;
|
2020-06-13 15:07:21 -04:00
|
|
|
|
|
|
|
|
pub struct Issue;
|
|
|
|
|
|
2021-12-18 20:08:46 -05:00
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
pub struct MultipleIssues {
|
|
|
|
|
pub data: Vec<IssueResponse>,
|
|
|
|
|
pub ok: bool,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
pub struct IssueResponse {
|
|
|
|
|
pub id: i64,
|
|
|
|
|
pub url: String,
|
|
|
|
|
pub html_url: String,
|
|
|
|
|
pub number: i64,
|
|
|
|
|
pub user: User,
|
|
|
|
|
pub original_author: String,
|
|
|
|
|
pub original_author_id: i64,
|
|
|
|
|
pub title: String,
|
|
|
|
|
pub body: String,
|
|
|
|
|
pub ref_field: String,
|
|
|
|
|
pub labels: Vec<Value>,
|
|
|
|
|
pub milestone: Value,
|
|
|
|
|
pub assignee: Value,
|
|
|
|
|
pub assignees: Value,
|
|
|
|
|
pub state: String,
|
|
|
|
|
pub is_locked: bool,
|
|
|
|
|
pub comments: i64,
|
|
|
|
|
pub created_at: String,
|
|
|
|
|
pub updated_at: String,
|
|
|
|
|
pub closed_at: Value,
|
|
|
|
|
pub due_date: Value,
|
|
|
|
|
pub pull_request: Value,
|
|
|
|
|
pub repository: Repository,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
pub struct User {
|
|
|
|
|
pub id: i64,
|
|
|
|
|
pub login: String,
|
|
|
|
|
pub full_name: String,
|
|
|
|
|
pub email: String,
|
|
|
|
|
pub avatar_url: String,
|
|
|
|
|
pub language: String,
|
|
|
|
|
pub is_admin: bool,
|
|
|
|
|
pub last_login: String,
|
|
|
|
|
pub created: String,
|
|
|
|
|
pub restricted: bool,
|
|
|
|
|
pub username: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
pub struct Repository {
|
|
|
|
|
pub id: i64,
|
|
|
|
|
pub name: String,
|
|
|
|
|
pub owner: String,
|
|
|
|
|
pub full_name: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-06-13 15:07:21 -04:00
|
|
|
impl Issue {
|
|
|
|
|
pub fn new() -> Issue {
|
|
|
|
|
Issue {}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-18 20:08:46 -05:00
|
|
|
pub fn create_issue(&self, request: &Request) {
|
|
|
|
|
let issue_title: String;
|
|
|
|
|
let issue_description: String;
|
|
|
|
|
let _issue_assignee: Option<String>;
|
|
|
|
|
let _issue_milestone: Option<String>;
|
|
|
|
|
let _issue_tags: Option<String>;
|
|
|
|
|
|
|
|
|
|
let client = &request.client;
|
|
|
|
|
let arg_value: Vec<&str> = request
|
|
|
|
|
.arg_value
|
|
|
|
|
.subcommand()
|
|
|
|
|
.1
|
|
|
|
|
.unwrap()
|
|
|
|
|
.values_of("create")
|
|
|
|
|
.unwrap()
|
|
|
|
|
.collect();
|
|
|
|
|
let mut map: HashMap<&str, String> = HashMap::new();
|
|
|
|
|
let url = format!(
|
|
|
|
|
"{request}/repos/{owner}/{repo}/issues?token={api_token}",
|
|
|
|
|
request = request.url.as_ref().unwrap(),
|
|
|
|
|
owner = arg_value[0],
|
|
|
|
|
repo = arg_value[1],
|
|
|
|
|
api_token = request.authentication.credentials.1.as_ref().unwrap()
|
|
|
|
|
);
|
2020-06-27 22:32:38 -04:00
|
|
|
|
2021-12-18 20:08:46 -05:00
|
|
|
//let issue_title = read!("Enter a title for the issue: {}\n");
|
|
|
|
|
//let issue_description = read!("Enter a description for the issue: {}\n");
|
|
|
|
|
issue_title = util::get_input("Enter a title for the issue: ".to_string());
|
|
|
|
|
issue_description = util::get_input("Enter a description for the issue: ".to_string());
|
|
|
|
|
map.insert("title", issue_title);
|
|
|
|
|
map.insert("body", issue_description);
|
|
|
|
|
|
|
|
|
|
let response = client.post(&url).json(&map).send();
|
|
|
|
|
|
|
|
|
|
match response {
|
|
|
|
|
Ok(repo) => {
|
|
|
|
|
match repo.status() {
|
|
|
|
|
StatusCode::CREATED => println!("{}", "Issue successfully created!".green()),
|
|
|
|
|
StatusCode::FORBIDDEN => println!("{}", "Issue creation forbidden!".red()),
|
|
|
|
|
StatusCode::UNPROCESSABLE_ENTITY => println!("{}", "Issue input validation failed!".red()),
|
|
|
|
|
_ => println!(),
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Err(e) => panic!("{}", e),
|
|
|
|
|
}
|
2020-06-13 15:07:21 -04:00
|
|
|
}
|
|
|
|
|
}
|