manager: Fix double comment bug
When the job for the new issue is scheduled later than another manager run, we create a second comment due to the previously unconditional comment creating. Always look for an existing comment first.
This commit is contained in:
parent
f11d8459ba
commit
eebbd9c453
|
@ -49,9 +49,21 @@ async fn run() -> anyhow::Result<()> {
|
||||||
let forgejo = Forgejo::new(auth, server_url).context("Could not create API access object")?;
|
let forgejo = Forgejo::new(auth, server_url).context("Could not create API access object")?;
|
||||||
|
|
||||||
let new_comment_id = if meta.action == event_meta::IssueAction::Opened {
|
let new_comment_id = if meta.action == event_meta::IssueAction::Opened {
|
||||||
let res = issue::make_bot_comment(&forgejo, &meta, meta.issue.number).await;
|
let bot_comment =
|
||||||
|
issue::find_bot_comment(&forgejo, &meta.issue.repository, meta.issue.number)
|
||||||
|
.await
|
||||||
|
.with_context(|| {
|
||||||
|
format!(
|
||||||
|
"Failed searching for bot comment for issue #{}",
|
||||||
|
meta.issue.number
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
let id = match res {
|
let id = match bot_comment {
|
||||||
|
Some(comment) => Some(comment.id),
|
||||||
|
None => {
|
||||||
|
let res = issue::make_bot_comment(&forgejo, &meta, meta.issue.number).await;
|
||||||
|
match res {
|
||||||
Ok(id) => Some(id),
|
Ok(id) => Some(id),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::warn!(
|
log::warn!(
|
||||||
|
@ -60,9 +72,13 @@ async fn run() -> anyhow::Result<()> {
|
||||||
);
|
);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
log::info!("Waiting for a minute, as the issue is brand new. We will likely catch some more updates this way!");
|
log::info!(
|
||||||
|
"Waiting for a minute, as the issue is brand new. We will likely catch some more updates this way!"
|
||||||
|
);
|
||||||
tokio::time::sleep(std::time::Duration::from_secs(60)).await;
|
tokio::time::sleep(std::time::Duration::from_secs(60)).await;
|
||||||
|
|
||||||
id
|
id
|
||||||
|
|
Loading…
Reference in a new issue