Skip to content

Commit b765d8d

Browse files
committed
Fixing fcp reviewed comment bug from DB race condition.
The bot was doing this: 1. receive reviewed command, set db entry reviewed=true 2. finish processing commands, starts parsing the status comment for checkboxes 3. found an unchecked box, set db entry reviewed=false 4. updating the status comment based on the comment's prior state instead of command The easy change was to make it so that step 3 doesn't happen. Checkboxes are one-way (as was originally intended) -- no takesies-backsies. Closes #91
1 parent 26f8e42 commit b765d8d

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

src/github/nag.rs

+22-14
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,30 @@ fn update_proposal_review_status(repo: &str, proposal_id: i32) -> DashResult<()>
6666

6767
let comment = GH.get_comment(repo, proposal.fk_bot_tracking_comment)?;
6868

69-
let statuses = comment.body
69+
// parse the status comment and mark any new reviews as reviewed
70+
let reviewed = comment.body
7071
.lines()
71-
.filter(|l| l.starts_with("* ["))
72-
.map(|line| {
73-
let l = line.trim_left_matches("* [");
74-
let reviewed = l.starts_with("x");
75-
let username = l.trim_left_matches("x] @").trim_left_matches(" ] @");
76-
77-
debug!("reviewer parsed as reviewed? {} (line: \"{}\")",
78-
reviewed,
79-
l);
80-
81-
(reviewed, username)
72+
.filter_map(|line| {
73+
if line.starts_with("* [") {
74+
let l = line.trim_left_matches("* [");
75+
let reviewed = l.starts_with("x");
76+
let username = l.trim_left_matches("x] @").trim_left_matches(" ] @");
77+
78+
debug!("reviewer parsed as reviewed? {} (line: \"{}\")",
79+
reviewed,
80+
l);
81+
82+
if reviewed {
83+
Some(username)
84+
} else {
85+
None
86+
}
87+
} else {
88+
None
89+
}
8290
});
8391

84-
for (is_reviewed, username) in statuses {
92+
for username in reviewed {
8593
let user: GitHubUser = githubuser::table.filter(githubuser::login.eq(username))
8694
.first(conn)?;
8795

@@ -92,7 +100,7 @@ fn update_proposal_review_status(repo: &str, proposal_id: i32) -> DashResult<()>
92100
.filter(fk_reviewer.eq(user.id))
93101
.first(conn)?;
94102

95-
review_request.reviewed = is_reviewed;
103+
review_request.reviewed = true;
96104
diesel::update(fcp_review_request.find(review_request.id)).set(&review_request)
97105
.execute(conn)?;
98106
}

0 commit comments

Comments
 (0)