Skip to content

Commit

Permalink
Add display names and profile links to /sponsors
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinegb committed Jul 18, 2024
1 parent dfca027 commit cb3ed74
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/commands/sponsors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down Expand Up @@ -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`");
}
}

Expand Down

0 comments on commit cb3ed74

Please sign in to comment.