From cb3ed7441297ec1ef7510bf062534615f2d521be Mon Sep 17 00:00:00 2001 From: Valentine Briese Date: Wed, 17 Jul 2024 21:06:41 -0700 Subject: [PATCH] Add display names and profile links to `/sponsors` --- src/commands/sponsors.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/commands/sponsors.rs b/src/commands/sponsors.rs index b54160b..3c0f060 100644 --- a/src/commands/sponsors.rs +++ b/src/commands/sponsors.rs @@ -16,7 +16,7 @@ pub(crate) async fn sponsors(ctx: Context<'_>) -> Result<(), Error> { let response: serde_json::Value = octocrab::instance() .graphql( &serde_json::json!({ - "query": format!("{{ viewer {{ sponsors(first: 100, tierId: \"{tier}\") {{ nodes {{ ... on User {{ login }} ... on Organization {{ login }} }} }} }} }}"), + "query": format!("{{ viewer {{ sponsors(first: 100, tierId: \"{tier}\") {{ nodes {{ ... on User {{ login name }} ... on Organization {{ login name }} }} }} }} }}"), }), ) .await?; @@ -45,11 +45,21 @@ pub(crate) async fn sponsors(ctx: Context<'_>) -> Result<(), Error> { "This project is made possible by these absolutely *lovely* sponsors {FLOOF_HEART}\n" ); - for username in nodes { - if let serde_json::Value::String(username) = username { - message += &format!("\n- {username}"); + for object in nodes { + if let serde_json::Value::Object(object) = object { + if let serde_json::Value::String(login) = object + .get("login") + .context("Expected `login` field to be `Value::String`")? + { + if let serde_json::Value::String(name) = object + .get("name") + .context("Expected `name` field to be `Value::String`")? + { + message += &format!("\n- {name} ([{login}](https://github.com/{login}))"); + } + } } else { - bail!("Expected `username` to be `Value::String`") + bail!("Expected `object` to be `Value::Object`"); } }