Skip to content

Commit

Permalink
Apply cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
akash1810 committed Nov 5, 2024
1 parent 2a9fceb commit 6979a34
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/google.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::time;
use anyhow::{Context, Result};
use log::info;
use serde::{Deserialize, Serialize};
use std::time;
use url::Url;
use log::info;

#[derive(Serialize, Deserialize, Debug)]
pub struct GoogleChatMessage {
Expand Down Expand Up @@ -44,17 +44,24 @@ impl GoogleChatMessage {
.send()
.await?;

if response.status().eq(&reqwest::StatusCode::TOO_MANY_REQUESTS) {
if response
.status()
.eq(&reqwest::StatusCode::TOO_MANY_REQUESTS)
{
/*
Sleep for 1.5 seconds to avoid rate limiting, at 60 requests per minute.
See https://developers.google.com/workspace/chat/limits
*/
info!("Received {} response. Sleeping for 1.5 seconds before retrying", response.status());
info!(
"Received {} response. Sleeping for 1.5 seconds before retrying",
response.status()
);
tokio::time::sleep(time::Duration::from_millis(1500)).await;
Box::pin(self.send(webhook_url, thread_key)).await?;
}

let response_text = response.text()
let response_text = response
.text()
.await
.context(format!("Failed to get response from: {}", &webhook_url))?;

Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ async fn main() -> Result<(), Error> {
.await?;

for pull_request in pull_requests_to_review {
info!("Sending message for PR {} #{}", pull_request.head.repo.name, pull_request.number);
info!(
"Sending message for PR {} #{}",
pull_request.head.repo.name, pull_request.number
);
GoogleChatMessage::from(make_message(pull_request, show_pr_age))
.send(&webhook_url, &thread_key)
.await?;
Expand Down

0 comments on commit 6979a34

Please sign in to comment.