|
|
@@ -61,7 +61,6 @@ impl Command for CmdGitea { |
|
|
|
prefix: Some("token ".to_string()), |
|
|
|
key: token, |
|
|
|
}); |
|
|
|
println!("Url {}", full_url.as_str()); |
|
|
|
match Uri::from_str(full_url.as_str()) { |
|
|
|
Err(why) => { |
|
|
|
let response = MessageBuilder::new() |
|
|
@@ -74,30 +73,38 @@ impl Command for CmdGitea { |
|
|
|
} |
|
|
|
Ok(url) => { |
|
|
|
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); |
|
|
|
//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| { |
|
|
|
let mut files = "".to_owned(); |
|
|
|
for f in items[0].assets().unwrap() { |
|
|
|
files += &format!("[{}]({})\n", f.name().unwrap(), f.browser_download_url().unwrap()) |
|
|
|
} |
|
|
|
if files.len() > 4 { |
|
|
|
e.field("Download", files, true); |
|
|
|
} |
|
|
|
return e.colour(Colour::from_rgb(0, 200, 0)) |
|
|
|
.title(items[0].tag_name().unwrap()) |
|
|
|
.title(format!("{} {}", repo_name.as_str(), 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"); |
|
|
|
}) |
|
|
|
.footer(|f| { |
|
|
|
return f.text(items[0].author().unwrap().login().unwrap()) |
|
|
|
.icon_url(items[0].author().unwrap().avatar_url().unwrap()); |
|
|
|
}) |
|
|
|
}); |
|
|
|
}) { |
|
|
|
println!("Failed to send gitea release message {:?}", why); |
|
|
@@ -128,7 +135,7 @@ impl Command for CmdGitea { |
|
|
|
} |
|
|
|
})) { |
|
|
|
let response = MessageBuilder::new() |
|
|
|
.push(format!("Gitea API request failed to complete {:?}", reason)) |
|
|
|
.push(format!("Gitea API request failed to complete {:?}", async_err)) |
|
|
|
.build(); |
|
|
|
if let Err(why) = msg.channel_id.say(&ctx.http, response) { |
|
|
|
println!("Failed to send gitea error message {:?}", why); |
|
|
|