use std::{panic::PanicInfo, time::SystemTime};
use url::Url;
use crate::panic_handler::CargoPanicMetadata;
#[derive(Debug)]
pub enum RepositoryProvider {
GitHub(Url),
GitLab(Url),
}
impl RepositoryProvider {
pub fn build_issue_url(&self, info: &PanicInfo<'_>, metadata: &CargoPanicMetadata) -> Url {
let body = vec crate.*",
"*If you would like to improve these diagnostics, please contribute on GitHub.*"
].join("\n");
match self {
RepositoryProvider::GitHub(url) => {
let mut output_url = url.clone();
let path = url.path();
output_url.set_path(&format!("{}/issues/new", path));
output_url.set_query(Some(&format!(
"body={}&labels=bug",
urlencoding::encode(&body)
)));
output_url
}
RepositoryProvider::GitLab(url) => {
let mut output_url = url.clone();
let path = url.path();
output_url.set_path(&format!("{}/issues/new", path));
output_url.set_query(Some(&format!(
"issue[description]={}&issuable_template=bug",
urlencoding::encode(&body)
)));
output_url
}
}
}
}