|
|
@@ -50,11 +50,12 @@ impl Command for CmdGitea { |
|
|
|
} |
|
|
|
if let Some(full_url) = parsed.get(2) { |
|
|
|
let token = env::var("GITEA_TOKEN").expect("Expected a Gitea API token in GITEA_TOKEN environment variable"); |
|
|
|
let core = Core::new().unwrap(); |
|
|
|
let https = HttpsConnector::new(); |
|
|
|
let mut core = Core::new().unwrap(); |
|
|
|
//let https = HttpsConnector::new(); |
|
|
|
let handler = core.handle(); |
|
|
|
let client = Client::configure() |
|
|
|
.connector(HttpsConnector::new(4, &core.handle()).unwrap()) |
|
|
|
.build(&core.handle()); |
|
|
|
.connector(HttpsConnector::new(4, &handler).unwrap()) |
|
|
|
.build(&handler); |
|
|
|
let mut config = apis::configuration::Configuration::new(client); |
|
|
|
config.api_key = Some(apis::configuration::ApiKey { |
|
|
|
prefix: Some("token ".to_string()), |
|
|
@@ -72,54 +73,70 @@ impl Command for CmdGitea { |
|
|
|
} |
|
|
|
} |
|
|
|
Ok(url) => { |
|
|
|
config.base_path = url.scheme().unwrap().to_owned() + "://" + url.host().unwrap() + "/api/v1/"; |
|
|
|
config.base_path = url.scheme().unwrap().to_owned() + "://" + url.host().unwrap() + "/api/v1"; |
|
|
|
println!("Base Url {}", config.base_path); |
|
|
|
let client = apis::client::APIClient::new(config); |
|
|
|
if let Some(owner) = parsed.get(3) { |
|
|
|
if let Some(repo_name) = parsed.get(4) { |
|
|
|
println!("owner {} repo {}", owner.as_str(), repo_name.as_str()); |
|
|
|
let future = client.repository_api().repo_list_releases(owner.as_str(), repo_name.as_str(), 1, 5); |
|
|
|
match future.wait() { |
|
|
|
Ok(items) => { |
|
|
|
// items is Vec of release |
|
|
|
if items.len() > 0 { |
|
|
|
println!("Release info {:?}", items[0]); |
|
|
|
// releases found, use first one (most recent) |
|
|
|
if let Err(why) = msg.channel_id.send_message(&ctx.http, |m| { |
|
|
|
return m.embed(|e| { |
|
|
|
return e.colour(Colour::from_rgb(0, 200, 0)) |
|
|
|
.title(items[0].tag_name().unwrap()) |
|
|
|
.description(items[0].body().unwrap()) |
|
|
|
.author(|a| { |
|
|
|
return a.name(items[0].name().unwrap()) |
|
|
|
.url(full_url.as_str().to_owned() + "/releases"); |
|
|
|
}) |
|
|
|
}); |
|
|
|
}) { |
|
|
|
println!("Failed to send gitea release message {:?}", why); |
|
|
|
return; |
|
|
|
//let result = async {future.await;}; |
|
|
|
if let Err(async_err) = core.run(future.then(|result| { |
|
|
|
match result { |
|
|
|
Ok(items) => { |
|
|
|
println!("Request complete"); |
|
|
|
// items is Vec of release |
|
|
|
if items.len() > 0 { |
|
|
|
//println!("Release info {:?}", items[0]); |
|
|
|
// releases found, use first one (most recent) |
|
|
|
if let Err(why) = msg.channel_id.send_message(&ctx.http, |m| { |
|
|
|
return m.embed(|e| { |
|
|
|
return e.colour(Colour::from_rgb(0, 200, 0)) |
|
|
|
.title(items[0].tag_name().unwrap()) |
|
|
|
.description(items[0].body().unwrap()) |
|
|
|
.author(|a| { |
|
|
|
return a.name(items[0].name().unwrap()) |
|
|
|
.url(full_url.as_str().to_owned() + "/releases"); |
|
|
|
}) |
|
|
|
}); |
|
|
|
}) { |
|
|
|
println!("Failed to send gitea release message {:?}", why); |
|
|
|
return futures::future::ok::<u32, u32>(42); |
|
|
|
} |
|
|
|
} else { |
|
|
|
let response = MessageBuilder::new() |
|
|
|
.push(format!("No releases found for <{}>", full_url.as_str())) |
|
|
|
.build(); |
|
|
|
if let Err(why) = msg.channel_id.say(&ctx.http, response) { |
|
|
|
println!("Failed to send gitea error message {:?}", why); |
|
|
|
return futures::future::ok::<u32, u32>(42); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
return futures::future::ok::<u32, u32>(42); |
|
|
|
} |
|
|
|
Err(reason) => { |
|
|
|
println!("Gitea API request failed {:?}", reason); |
|
|
|
let response = MessageBuilder::new() |
|
|
|
.push(format!("No releases found for <{}>", full_url.as_str())) |
|
|
|
.build(); |
|
|
|
.push(format!("Gitea API request failed {:?}", reason)) |
|
|
|
.build(); |
|
|
|
if let Err(why) = msg.channel_id.say(&ctx.http, response) { |
|
|
|
println!("Failed to send gitea error message {:?}", why); |
|
|
|
return; |
|
|
|
return futures::future::ok::<u32, u32>(42); |
|
|
|
} |
|
|
|
return futures::future::ok::<u32, u32>(42); |
|
|
|
} |
|
|
|
} |
|
|
|
})) { |
|
|
|
let response = MessageBuilder::new() |
|
|
|
.push(format!("Gitea API request failed to complete {:?}", reason)) |
|
|
|
.build(); |
|
|
|
if let Err(why) = msg.channel_id.say(&ctx.http, response) { |
|
|
|
println!("Failed to send gitea error message {:?}", why); |
|
|
|
return; |
|
|
|
} |
|
|
|
Err(reason) => { |
|
|
|
println!("Gitea API request failed {:?}", reason); |
|
|
|
let response = MessageBuilder::new() |
|
|
|
.push(format!("Gitea API request failed {:?}", reason)) |
|
|
|
.build(); |
|
|
|
if let Err(why) = msg.channel_id.say(&ctx.http, response) { |
|
|
|
println!("Failed to send gitea error message {:?}", why); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@@ -159,7 +176,7 @@ impl CmdGitea { |
|
|
|
pub fn new() -> CmdGitea { |
|
|
|
return CmdGitea { |
|
|
|
format: |
|
|
|
RegexBuilder::new(r#"^!gitea\s+(release)\s+<?(https?://[^/\s]+/([^/\s]+)/([^/\s]+))>?"#) |
|
|
|
RegexBuilder::new(r#"^!gitea\s+(release)\s+<?(https?://[^/\s]+/([^/\s]+)/([^/\s>]+))>?"#) |
|
|
|
.multi_line(true) |
|
|
|
.case_insensitive(true) |
|
|
|
.build() |
|
|
|