Skip to content

Commit 03e4d9a

Browse files
committed
add q issue
1 parent 6093652 commit 03e4d9a

File tree

1 file changed

+84
-1
lines changed

1 file changed

+84
-1
lines changed

crates/q_cli/src/cli/issue.rs

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ use anstream::println;
44
use clap::Args;
55
use crossterm::style::Stylize;
66
use eyre::Result;
7+
use fig_diagnostic::Diagnostics;
78
use fig_util::system_info::is_remote;
89
use fig_util::{
910
CLI_BINARY_NAME,
11+
GITHUB_REPO_NAME,
1012
PRODUCT_NAME,
1113
};
1214

15+
const TEMPLATE_NAME: &str = "1_bug_report_template.yml";
16+
1317
#[derive(Debug, Args, PartialEq, Eq)]
1418
pub struct IssueArgs {
1519
/// Force issue creation
@@ -41,8 +45,87 @@ impl IssueArgs {
4145
_ => joined_description,
4246
};
4347

44-
todo!();
48+
let _ = IssueCreator {
49+
title: Some(issue_title),
50+
expected_behavior: None,
51+
actual_behavior: None,
52+
steps_to_reproduce: None,
53+
additional_environment: None,
54+
}
55+
.create_url()
56+
.await;
4557

4658
Ok(ExitCode::SUCCESS)
4759
}
4860
}
61+
62+
pub struct IssueCreator {
63+
/// Issue title
64+
pub title: Option<String>,
65+
/// Issue description
66+
pub expected_behavior: Option<String>,
67+
/// Issue description
68+
pub actual_behavior: Option<String>,
69+
/// Issue description
70+
pub steps_to_reproduce: Option<String>,
71+
/// Issue description
72+
pub additional_environment: Option<String>,
73+
}
74+
75+
impl IssueCreator {
76+
pub async fn create_url(&self) -> Result<url::Url> {
77+
println!("Heading over to GitHub...");
78+
79+
let warning = |text: &String| {
80+
format!("<This will be visible to anyone. Do not include personal or sensitive information>\n\n{text}")
81+
};
82+
let diagnostics = Diagnostics::new().await;
83+
84+
let os = match &diagnostics.system_info.os {
85+
Some(os) => os.to_string(),
86+
None => "None".to_owned(),
87+
};
88+
89+
let diagnostic_info = match diagnostics.user_readable() {
90+
Ok(diagnostics) => diagnostics,
91+
Err(err) => {
92+
eprintln!("Error getting diagnostics: {err}");
93+
"Error occurred while generating diagnostics".to_owned()
94+
},
95+
};
96+
97+
let environment = match &self.additional_environment {
98+
Some(ctx) => format!("{diagnostic_info}\n{ctx}"),
99+
None => diagnostic_info,
100+
};
101+
102+
let mut params = Vec::new();
103+
params.push(("template", TEMPLATE_NAME.to_string()));
104+
params.push(("os", os));
105+
params.push(("environment", warning(&environment)));
106+
107+
if let Some(t) = self.title.clone() {
108+
params.push(("title", t));
109+
}
110+
if let Some(t) = self.expected_behavior.as_ref() {
111+
params.push(("expected", warning(t)));
112+
}
113+
if let Some(t) = self.actual_behavior.as_ref() {
114+
params.push(("actual", warning(t)));
115+
}
116+
if let Some(t) = self.steps_to_reproduce.as_ref() {
117+
params.push(("reproduce", warning(t)));
118+
}
119+
120+
let url = url::Url::parse_with_params(
121+
&format!("https://github.com/{GITHUB_REPO_NAME}/issues/new"),
122+
params.iter(),
123+
)?;
124+
125+
if is_remote() || fig_util::open_url_async(url.as_str()).await.is_err() {
126+
println!("Issue Url: {}", url.as_str().underlined());
127+
}
128+
129+
Ok(url)
130+
}
131+
}

0 commit comments

Comments
 (0)