silly goober bot
at main 73 lines 1.9 kB view raw
1use color_eyre::eyre::Result; 2use nixpkgs_track_lib::{branch_contains_commit, fetch_nixpkgs_pull_request}; 3use poise::{serenity_prelude::CreateEmbed, CreateReply}; 4use std::fmt::Write as _; 5 6use crate::types::Context; 7 8const BRANCHES: [&str; 5] = [ 9 "master", 10 "staging", 11 "nixpkgs-unstable", 12 "nixos-unstable-small", 13 "nixos-unstable", 14]; 15 16/// Track nixpkgs PRs 17#[poise::command( 18 slash_command, 19 install_context = "Guild|User", 20 interaction_context = "Guild|BotDm|PrivateChannel" 21)] 22pub async fn nixpkgs( 23 ctx: Context<'_>, 24 #[description = "pr"] 25 #[min = 0] 26 pr: u64, 27) -> Result<()> { 28 ctx.defer().await?; 29 30 let pull_request = fetch_nixpkgs_pull_request( 31 crate::types::W(ctx.data().client.clone()), 32 pr, 33 Some(&ctx.data().github_token), 34 ) 35 .await?; 36 37 let Some(commit_sha) = pull_request.merge_commit_sha else { 38 ctx.say("This pull request is very old. I can't track it!") 39 .await?; 40 return Ok(()); 41 }; 42 43 let mut embed_description = String::new(); 44 for branch in BRANCHES { 45 let github_token = ctx.data().github_token.clone(); 46 let commit_sha = commit_sha.clone(); 47 48 let has_pull_request = branch_contains_commit( 49 crate::types::W(ctx.data().client.clone()), 50 branch, 51 &commit_sha, 52 Some(&github_token), 53 ) 54 .await?; 55 56 let _ = writeln!( 57 embed_description, 58 "{}: {}", 59 branch, 60 if has_pull_request { "" } else { "" } 61 ); 62 } 63 64 let embed = CreateReply::default().embed( 65 CreateEmbed::new() 66 .title(format!("{} - #{}", pull_request.title, pull_request.number)) 67 .url(pull_request.html_url) 68 .description(embed_description), 69 ); 70 71 ctx.send(embed).await?; 72 Ok(()) 73}