Skip to content

Commit

Permalink
feat: add /report command
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Mar 3, 2024
1 parent 5dab702 commit 0946877
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 1 deletion.
142 changes: 141 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ console = "0.15.8"
buildit-utils = { path = "../buildit-utils" }
jsonwebtoken = "9.2.0"
size = "0.4.1"
dickens = { git = "https://github.com/AOSC-Dev/dickens.git", version = "0.1.0" }
72 changes: 72 additions & 0 deletions server/src/bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ pub enum Command {
Start(String),
#[command(description = "Queue all ready messages: /queue [archs]")]
Queue(String),
#[command(description = "Let dickens generate report for GitHub PR: /report pr-number")]
Report(String),
}

pub struct BuildRequest<'a> {
Expand Down Expand Up @@ -599,6 +601,76 @@ pub async fn answer(
}
}
}
Command::Report(arguments) => match str::parse::<u64>(&arguments) {
Ok(pr_number) => {
// create octocrab instance
let crab = match octocrab::Octocrab::builder()
.user_access_token(ARGS.github_access_token.clone())
.build()
{
Ok(v) => v,
Err(err) => {
bot.send_message(
msg.chat.id,
format!("Cannot create octocrab instance: {err}"),
)
.await?;
return Ok(());
}
};

// get topic of pr
match crab.pulls("AOSC-Dev", "aosc-os-abbs").get(pr_number).await {
Ok(pr) => match dickens::topic::report(pr.head.ref_field.as_str()).await {
Ok(report) => {
// post report as github comment
match crab
.issues("AOSC-Dev", "aosc-os-abbs")
.create_comment(pr_number, report)
.await
{
Ok(comment) => {
bot_send_message_handle_length(
&bot,
&msg,
&format!("Report posted as comment: {}", comment.url),
)
.await?;
}
Err(err) => {
bot_send_message_handle_length(
&bot,
&msg,
&format!("Failed to create github comments: {err}."),
)
.await?;
}
}
}
Err(err) => {
bot_send_message_handle_length(
&bot,
&msg,
&format!("Failed to generate dickens report: {err}."),
)
.await?;
}
},
Err(err) => {
bot_send_message_handle_length(
&bot,
&msg,
&format!("Failed to get pr info: {err}."),
)
.await?;
}
}
}
Err(err) => {
bot_send_message_handle_length(&bot, &msg, &format!("Bad PR number: {err}"))
.await?;
}
},
};

Ok(())
Expand Down

0 comments on commit 0946877

Please sign in to comment.