Skip to content

Commit 0c50534

Browse files
committed
Remove autolabel new_pr_labels_applied state
1 parent e1decff commit 0c50534

File tree

1 file changed

+3
-25
lines changed

1 file changed

+3
-25
lines changed

src/handlers/autolabel.rs

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::db::issue_data::IssueData;
21
use crate::{
32
config::AutolabelConfig,
43
github::{IssuesAction, IssuesEvent, Label},
@@ -7,16 +6,6 @@ use crate::{
76
use anyhow::Context as _;
87
use tracing as log;
98

10-
/// Key for the state in the database
11-
const AUTOLABEL_KEY: &str = "autolabel";
12-
13-
/// State stored in the database
14-
#[derive(Debug, Default, PartialEq, Clone, serde::Deserialize, serde::Serialize)]
15-
struct AutolabelState {
16-
/// If true, then `autolabel.new_pr` labels have already been applied to this PR.
17-
new_pr_labels_applied: bool,
18-
}
19-
209
pub(super) struct AutolabelInput {
2110
add: Vec<Label>,
2211
remove: Vec<Label>,
@@ -44,12 +33,6 @@ pub(super) async fn parse_input(
4433
| IssuesAction::ReadyForReview
4534
| IssuesAction::ConvertedToDraft
4635
) {
47-
let mut db = ctx.db.get().await;
48-
let mut state: IssueData<'_, AutolabelState> =
49-
IssueData::load(&mut db, &event.issue, AUTOLABEL_KEY)
50-
.await
51-
.map_err(|e| e.to_string())?;
52-
5336
let files = event
5437
.issue
5538
.diff(&ctx.github)
@@ -102,24 +85,21 @@ pub(super) async fn parse_input(
10285

10386
// Treat the following situations as a "new PR":
10487
// 1) New PRs opened as non-draft
105-
// 2) PRs opened as draft that are marked as "ready for review" for the first time.
88+
// 2) PRs opened as draft that are marked as "ready for review".
10689
let is_new_non_draft_pr =
10790
event.action == IssuesAction::Opened && !event.issue.draft;
108-
let is_first_time_ready_for_review = event.action == IssuesAction::ReadyForReview
109-
&& !state.data.new_pr_labels_applied;
110-
if cfg.new_pr && (is_new_non_draft_pr || is_first_time_ready_for_review) {
91+
let is_ready_for_review = event.action == IssuesAction::ReadyForReview;
92+
if cfg.new_pr && (is_new_non_draft_pr || is_ready_for_review) {
11193
autolabels.push(Label {
11294
name: label.to_owned(),
11395
});
114-
state.data.new_pr_labels_applied = true;
11596
}
11697

11798
// If a PR is converted to draft remove all the "new PR" labels
11899
if cfg.new_pr && event.action == IssuesAction::ConvertedToDraft {
119100
to_remove.push(Label {
120101
name: label.to_owned(),
121102
});
122-
state.data.new_pr_labels_applied = false;
123103
}
124104
} else {
125105
if cfg.new_issue && event.action == IssuesAction::Opened {
@@ -130,8 +110,6 @@ pub(super) async fn parse_input(
130110
}
131111
}
132112

133-
state.save().await.map_err(|e| e.to_string())?;
134-
135113
if !autolabels.is_empty() || !to_remove.is_empty() {
136114
return Ok(Some(AutolabelInput {
137115
add: autolabels,

0 commit comments

Comments
 (0)