Skip to content

Commit 44f7f11

Browse files
committed
Migrate assign handler to new EditIssueBody database handling
1 parent b7ae3a2 commit 44f7f11

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/handlers/assign.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ struct Reviewers {
111111
}
112112

113113
/// Assignment data stored in the issue/PR body.
114-
#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
114+
#[derive(Debug, Clone, PartialEq, Default, serde::Serialize, serde::Deserialize)]
115115
struct AssignData {
116116
user: Option<String>,
117117
}
@@ -624,7 +624,10 @@ pub(super) async fn handle_command(
624624

625625
set_assignee(ctx, issue, &ctx.github, &assignee).await?;
626626
} else {
627-
let e = EditIssueBody::new(&issue, "ASSIGN");
627+
let mut client = ctx.db.get().await;
628+
let mut e: EditIssueBody<'_, AssignData> =
629+
EditIssueBody::load(&mut client, &issue, "ASSIGN").await?;
630+
let d = e.data_mut();
628631

629632
let to_assign = match cmd {
630633
AssignCommand::Claim => event.user().login.clone(),
@@ -635,14 +638,14 @@ pub(super) async fn handle_command(
635638
username.clone()
636639
}
637640
AssignCommand::ReleaseAssignment => {
638-
if let Some(AssignData {
641+
if let AssignData {
639642
user: Some(current),
640-
}) = e.current_data()
643+
} = d
641644
{
642-
if current == event.user().login || is_team_member {
645+
if *current == event.user().login || is_team_member {
643646
issue.remove_assignees(&ctx.github, Selection::All).await?;
644-
e.apply(&ctx.github, String::new(), AssignData { user: None })
645-
.await?;
647+
*d = AssignData { user: None };
648+
e.apply(&ctx.github, String::new()).await?;
646649
return Ok(());
647650
} else {
648651
bail!("Cannot release another user's assignment");
@@ -653,8 +656,8 @@ pub(super) async fn handle_command(
653656
issue
654657
.remove_assignees(&ctx.github, Selection::One(&current))
655658
.await?;
656-
e.apply(&ctx.github, String::new(), AssignData { user: None })
657-
.await?;
659+
*d = AssignData { user: None };
660+
e.apply(&ctx.github, String::new()).await?;
658661
return Ok(());
659662
} else {
660663
bail!("Cannot release unassigned issue");
@@ -672,14 +675,15 @@ pub(super) async fn handle_command(
672675
);
673676
return Ok(());
674677
}
675-
let data = AssignData {
678+
*d = AssignData {
676679
user: Some(to_assign.clone()),
677680
};
678681

679-
e.apply(&ctx.github, String::new(), &data).await?;
680-
681682
match issue.set_assignee(&ctx.github, &to_assign).await {
682-
Ok(()) => return Ok(()), // we are done
683+
Ok(()) => {
684+
e.apply(&ctx.github, String::new()).await?;
685+
return Ok(());
686+
} // we are done
683687
Err(github::AssignmentError::InvalidAssignee) => {
684688
issue
685689
.set_assignee(&ctx.github, &ctx.username)
@@ -690,7 +694,7 @@ pub(super) async fn handle_command(
690694
to_assign,
691695
event.html_url().unwrap()
692696
);
693-
e.apply(&ctx.github, cmt_body, &data).await?;
697+
e.apply(&ctx.github, cmt_body).await?;
694698
}
695699
Err(e) => return Err(e.into()),
696700
}

0 commit comments

Comments
 (0)