mirror of
https://github.com/Noratrieb/does-it-build.git
synced 2026-01-14 18:35:01 +01:00
Only send notification update after a month of inactivity
A lower cadence was requested in https://github.com/Noratrieb/does-it-build/pull/10#issuecomment-3514228933
This commit is contained in:
parent
b244cf05b4
commit
491eb1604f
6 changed files with 115 additions and 54 deletions
20
src/db.rs
20
src/db.rs
|
|
@ -106,6 +106,7 @@ pub struct NotificationIssue {
|
|||
pub status: NotificationStatus,
|
||||
pub first_failed_nightly: String,
|
||||
pub target: String,
|
||||
pub last_update_date: Option<i64>,
|
||||
}
|
||||
|
||||
impl Db {
|
||||
|
|
@ -314,13 +315,14 @@ impl Db {
|
|||
pub async fn insert_notification(&self, notification: NotificationIssue) -> Result<()> {
|
||||
sqlx::query(
|
||||
"INSERT INTO notification_issues\
|
||||
(issue_number, status, first_failed_nightly, target)\
|
||||
VALUES (?, ?, ?, ?)",
|
||||
(issue_number, status, first_failed_nightly, target, last_update_date)\
|
||||
VALUES (?, ?, ?, ?, ?)",
|
||||
)
|
||||
.bind(notification.issue_number)
|
||||
.bind(notification.status)
|
||||
.bind(notification.first_failed_nightly)
|
||||
.bind(notification.target)
|
||||
.bind(notification.last_update_date)
|
||||
.execute(&self.conn)
|
||||
.await
|
||||
.wrap_err("inserting new notification")?;
|
||||
|
|
@ -336,4 +338,18 @@ impl Db {
|
|||
.wrap_err("marking notification as closed")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn set_notification_last_update(
|
||||
&self,
|
||||
issue_number: i64,
|
||||
last_update: jiff::Timestamp,
|
||||
) -> Result<()> {
|
||||
sqlx::query("UPDATE notification_issues SET last_update_date = ? WHERE issue_number = ?")
|
||||
.bind(last_update.as_millisecond())
|
||||
.bind(issue_number)
|
||||
.execute(&self.conn)
|
||||
.await
|
||||
.wrap_err("marking notification as closed")?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
use color_eyre::{eyre::Context, Result};
|
||||
use octocrab::issues;
|
||||
|
||||
pub struct GitHubClient {
|
||||
pub send_pings: bool,
|
||||
owner: String,
|
||||
repo: String,
|
||||
pub client: octocrab::Octocrab,
|
||||
}
|
||||
|
||||
impl GitHubClient {
|
||||
pub async fn new(
|
||||
send_pings: bool,
|
||||
client: octocrab::Octocrab,
|
||||
owner: String,
|
||||
repo: String,
|
||||
) -> Result<Self> {
|
||||
let installation = client
|
||||
.apps()
|
||||
.get_repository_installation(&owner, &repo)
|
||||
.await
|
||||
.wrap_err_with(|| format!("getting installation for {owner}/{repo}"))?;
|
||||
|
||||
let client = client
|
||||
.installation(installation.id)
|
||||
.wrap_err("getting client for installation")?;
|
||||
|
||||
Ok(Self {
|
||||
send_pings,
|
||||
owner,
|
||||
repo,
|
||||
client,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn issues(&self) -> issues::IssueHandler<'_> {
|
||||
self.client.issues(&self.owner, &self.repo)
|
||||
}
|
||||
}
|
||||
|
|
@ -84,8 +84,6 @@ pub async fn notify_build_failure(
|
|||
return Ok(());
|
||||
};
|
||||
|
||||
info!("Creating issue for target {target}, notifying {notify_usernames:?}");
|
||||
|
||||
let issue = db.find_existing_notification(target).await?;
|
||||
|
||||
let url = format!(
|
||||
|
|
@ -93,14 +91,25 @@ pub async fn notify_build_failure(
|
|||
);
|
||||
|
||||
if let Some(issue) = issue {
|
||||
// An existing issue, send a comment.
|
||||
// An existing issue, send a comment if it's been a month since the last update.
|
||||
|
||||
github_client
|
||||
.issues()
|
||||
.create_comment(
|
||||
issue.issue_number as u64,
|
||||
format!(
|
||||
"💥 The target {target} still fails to build on the nightly {nightly}!
|
||||
if issue.last_update_date.is_none_or(|last_update_date| {
|
||||
jiff::Timestamp::from_millisecond(last_update_date).is_ok_and(|last_update_date| {
|
||||
jiff::Timestamp::now()
|
||||
.since(last_update_date)
|
||||
.is_ok_and(|diff| diff.get_months() > 0)
|
||||
})
|
||||
}) {
|
||||
info!(
|
||||
"Sending update for {target}, since enough time has elapsed since the last update"
|
||||
);
|
||||
|
||||
github_client
|
||||
.issues()
|
||||
.create_comment(
|
||||
issue.issue_number as u64,
|
||||
format!(
|
||||
"💥 The target {target} still fails to build on the nightly {nightly}!
|
||||
|
||||
<{url}>
|
||||
|
||||
|
|
@ -111,14 +120,26 @@ pub async fn notify_build_failure(
|
|||
```
|
||||
|
||||
</details>
|
||||
|
||||
This update is sent after a month of inactivity.
|
||||
"
|
||||
),
|
||||
)
|
||||
.await
|
||||
.wrap_err("creating update comment")?;
|
||||
),
|
||||
)
|
||||
.await
|
||||
.wrap_err("creating update comment")?;
|
||||
|
||||
db.set_notification_last_update(issue.issue_number, jiff::Timestamp::now())
|
||||
.await
|
||||
.wrap_err("updating last_update_date in DB")?;
|
||||
} else {
|
||||
info!("Not sending update for {target}, since not enough time has elapsed since the last one");
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
info!("Creating issue for target {target}, notifying {notify_usernames:?}");
|
||||
|
||||
// Ensure the labels exist.
|
||||
let label = github_client.issues().get_label(target).await;
|
||||
match label {
|
||||
|
|
@ -176,6 +197,7 @@ This issue will be closed automatically when this target works again!"
|
|||
issue_number: issue.number as i64,
|
||||
status: NotificationStatus::Open,
|
||||
target: target.into(),
|
||||
last_update_date: Some(jiff::Timestamp::now().as_millisecond()),
|
||||
})
|
||||
.await
|
||||
.wrap_err("inserting issue into DB")?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue