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,20 +49,36 @@ async fn run() -> anyhow::Result<()> {
|
|||
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 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 {
|
||||
Ok(id) => Some(id),
|
||||
Err(e) => {
|
||||
log::warn!(
|
||||
"Error while creating the informational comment on issue #{}:\n{e:?}",
|
||||
meta.issue.number
|
||||
);
|
||||
None
|
||||
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),
|
||||
Err(e) => {
|
||||
log::warn!(
|
||||
"Error while creating the informational comment on issue #{}:\n{e:?}",
|
||||
meta.issue.number
|
||||
);
|
||||
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;
|
||||
|
||||
id
|
||||
|
|
Loading…
Reference in a new issue