Browse Source

Fix gitea release not sending even when OpenSSL available:

master
NGnius (Graham) 4 years ago
parent
commit
cd7c49fc39
2 changed files with 57 additions and 40 deletions
  1. +56
    -39
      src/commands/cmd_gitea.rs
  2. +1
    -1
      swagger

+ 56
- 39
src/commands/cmd_gitea.rs View File

@@ -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()


+ 1
- 1
swagger

@@ -1 +1 @@
Subproject commit d2e3da78352d2c6ffcfec212cff0ebb0d190ecf2
Subproject commit 529880f7b36d383ed89ccb39112bc129d1cab5c1