Skip to content

Commit

Permalink
Fixing fcp reviewed comment bug from DB race condition.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
anp committed Oct 25, 2016
1 parent 26f8e42 commit b765d8d
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/github/nag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,30 @@ fn update_proposal_review_status(repo: &str, proposal_id: i32) -> DashResult<()>

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

let statuses = comment.body
// parse the status comment and mark any new reviews as reviewed
let reviewed = comment.body
.lines()
.filter(|l| l.starts_with("* ["))
.map(|line| {
let l = line.trim_left_matches("* [");
let reviewed = l.starts_with("x");
let username = l.trim_left_matches("x] @").trim_left_matches(" ] @");

debug!("reviewer parsed as reviewed? {} (line: \"{}\")",
reviewed,
l);

(reviewed, username)
.filter_map(|line| {
if line.starts_with("* [") {
let l = line.trim_left_matches("* [");
let reviewed = l.starts_with("x");
let username = l.trim_left_matches("x] @").trim_left_matches(" ] @");

debug!("reviewer parsed as reviewed? {} (line: \"{}\")",
reviewed,
l);

if reviewed {
Some(username)
} else {
None
}
} else {
None
}
});

for (is_reviewed, username) in statuses {
for username in reviewed {
let user: GitHubUser = githubuser::table.filter(githubuser::login.eq(username))
.first(conn)?;

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

review_request.reviewed = is_reviewed;
review_request.reviewed = true;
diesel::update(fcp_review_request.find(review_request.id)).set(&review_request)
.execute(conn)?;
}
Expand Down

0 comments on commit b765d8d

Please sign in to comment.