manager: Factor out a common context object

Clean up the global data a bit by bundling it in a context object.
This commit is contained in:
Rahix 2025-05-22 18:47:31 +02:00
parent eebbd9c453
commit bc54cd91fd
5 changed files with 84 additions and 77 deletions

View file

@ -8,17 +8,16 @@ pub struct BotCommentInfo {
}
pub async fn make_bot_comment(
forgejo: &forgejo_api::Forgejo,
meta: &crate::event_meta::IssueEventMeta,
ctx: &crate::Context,
issue_number: u64,
) -> anyhow::Result<CommentId> {
let initial_message =
"_Please be patient, this issue is currently being integrated into the techtree..._";
let res = forgejo
let res = ctx.forgejo
.issue_create_comment(
&meta.issue.repository.owner,
&meta.issue.repository.name,
&ctx.owner,
&ctx.repo,
issue_number,
forgejo_api::structs::CreateIssueCommentOption {
body: initial_message.to_owned(),
@ -31,14 +30,13 @@ pub async fn make_bot_comment(
}
pub async fn find_bot_comment(
forgejo: &forgejo_api::Forgejo,
meta: &crate::event_meta::RepoMeta,
ctx: &crate::Context,
issue_number: u64,
) -> anyhow::Result<Option<BotCommentInfo>> {
let mut comments = forgejo
let mut comments = ctx.forgejo
.issue_get_comments(
&meta.owner,
&meta.name,
&ctx.owner,
&ctx.repo,
issue_number,
forgejo_api::structs::IssueGetCommentsQuery {
..Default::default()
@ -61,15 +59,14 @@ pub async fn find_bot_comment(
}
pub async fn update_bot_comment(
forgejo: &forgejo_api::Forgejo,
meta: &crate::event_meta::RepoMeta,
ctx: &crate::Context,
id: CommentId,
new_body: String,
) -> anyhow::Result<()> {
forgejo
ctx.forgejo
.issue_edit_comment(
&meta.owner,
&meta.name,
&ctx.owner,
&ctx.repo,
id,
forgejo_api::structs::EditIssueCommentOption {
body: new_body,
@ -83,12 +80,11 @@ pub async fn update_bot_comment(
}
pub async fn remove_stale_label(
forgejo: &forgejo_api::Forgejo,
meta: &crate::event_meta::RepoMeta,
ctx: &crate::Context,
issue_number: u64,
) -> anyhow::Result<()> {
let labels = forgejo
.issue_get_labels(&meta.owner, &meta.name, issue_number)
let labels = ctx.forgejo
.issue_get_labels(&ctx.owner, &ctx.repo, issue_number)
.await
.context("Failed fetching issue labels")?;
@ -101,10 +97,10 @@ pub async fn remove_stale_label(
if let Some(stale_label_id) = stale_label_id {
log::info!("Removing `Stale` label from issue #{issue_number}...");
let res = forgejo
let res = ctx.forgejo
.issue_remove_label(
&meta.owner,
&meta.name,
&ctx.owner,
&ctx.repo,
issue_number,
stale_label_id,
forgejo_api::structs::DeleteLabelsOption {