Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Needs review] Feature: @rfcbot poll [teams] #219

Merged
merged 24 commits into from
Aug 16, 2018

Conversation

Centril
Copy link
Contributor

@Centril Centril commented Jun 20, 2018

This should fix #214 and fix #225 ... hopefully.

I've also refactored a bunch of stuff for readability (less rightward drift, etc.).

@Centril Centril requested a review from anp June 20, 2018 10:05
@Centril Centril changed the title Feature: @rfcbot poll [teams] [WIP] Feature: @rfcbot poll [teams] Jun 20, 2018
@Centril Centril changed the title [WIP] Feature: @rfcbot poll [teams] [Needs review] Feature: @rfcbot poll [teams] Jun 21, 2018
@Centril
Copy link
Contributor Author

Centril commented Jun 21, 2018

Should probably also fix the individual dashboard to display polls which are awaiting a user's signoff?

@@ -32,6 +32,7 @@ extern crate url;
extern crate urlencoded;
#[macro_use]
extern crate maplit;
extern crate itertools;

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

README.md Outdated
"poll" | "polled" | "polling" | "polls" |
"query" | "queried" | "querying" | "queries" |
"inquire" | "inquired" | "inquiring" | "inquires" |
"quiz" | "quized" | "quizing" | "quizzes" |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quizzed and quizzing FWIW

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops :P

ResolveConcern(&'a str),
FeedbackRequest(&'a str),
AskQuestion {
teams: BTreeSet<&'a str>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this contain Team structs instead of strings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... That would add some additional unnecessary allocation. And this is really the TeamLabel (would still require allocation), which isn't inside the Team struct.

pub fn from_str_all(command: &'a str) -> impl Iterator<Item = RfcBotCommand<'a>> {
// Get the tokens for each command line (starts with a bot mention)
command.lines()
.filter(|&l| l.starts_with(RFC_BOT_MENTION))

This comment was marked as resolved.

This comment was marked as resolved.

})
}

fn from_invocation_line<'a>(command: &'a str) -> DashResult<RfcBotCommand<'a>> {

This comment was marked as resolved.

This comment was marked as resolved.

command[name_start..].trim()
}

fn strip_prefix<'h>(haystack: &'h str, prefix: &str) -> &'h str {

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.


fn match_team_candidate(team_candidate: &str) -> Option<&'static TeamLabel> {
#[cfg(not(test))]
let setup = &*teams::SETUP;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move this conditional compilation into teams.rs?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And maybe make it a feature so we can still run tests against the config on disk?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't super happy about this mechanism, so that sounds great. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and removed global state instead; much cleaner!

let setup = &*teams::test::TEST_SETUP;

setup.teams().find(|&(label, team)| {
strip_prefix(&label.0, "T-") == strip_prefix(team_candidate, "T-") ||

This comment was marked as resolved.

This comment was marked as resolved.


let mut question = parse_command_text(command, subcommand);
let mut teams = BTreeSet::new();
while let Some(team_candidate) = question.split_whitespace().next() {

This comment was marked as resolved.


let mut question = parse_command_text(command, subcommand);
let mut teams = BTreeSet::new();
while let Some(team_candidate) = question.split_whitespace().next() {

This comment was marked as resolved.

Copy link
Member

@anp anp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Looking this over and it looks mostly good to me. Unfortunately because the large refactoring (command.rs) is in the same commit as the new poll functionality it's a bit difficult to review. Once my various nits are addressed, lets just get it on prod when you'll be around to fix things?

@@ -185,7 +130,147 @@ fn update_proposal_review_status(proposal_id: i32) -> DashResult<()> {
Ok(())
}

fn update_poll_review_status(poll_id: i32) -> DashResult<()> {
let conn = &*DB_POOL.get()?;
// this is an updated comment from the bot itself
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is?

@@ -185,7 +130,147 @@ fn update_proposal_review_status(proposal_id: i32) -> DashResult<()> {
Ok(())
}

fn update_poll_review_status(poll_id: i32) -> DashResult<()> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bare numbers in fn args make me a little nervous. Can we separate out the "find the Poll struct from the raw input" and the "update the data model" functionality?

let conn = &*DB_POOL.get()?;
// this is an updated comment from the bot itself

// parse out each "reviewed" status for each user, then update them

This comment was marked as resolved.

This comment was marked as resolved.


{
use domain::schema::poll_review_request::dsl::*;
let mut review_request: PollReviewRequest = poll_review_request
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling it a PollReviewRequest seems odd to me in this context -- isn't it more like a PollResponseRequest or PollRequest?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to PollResponseRequest.

Ok(())
}

fn parse_ticky_boxes<'a>(what: &'a str, id: i32, comment: &'a IssueComment)

This comment was marked as resolved.

This comment was marked as resolved.

throw!(why)
});

for mut survey in pending {

This comment was marked as resolved.

This comment was marked as resolved.

Copy link
Member

@anp anp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking really sweet!

@@ -185,7 +130,147 @@ fn update_proposal_review_status(proposal_id: i32) -> DashResult<()> {
Ok(())
}

fn update_poll_response_status(poll_id: i32) -> DashResult<()> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function seems pretty well scoped to the Poll type -- what do you think about making it a method and leaving the exact query used to retrieve the Poll flexible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to punt on larger refactorings now and ship it :)

let conn = &*DB_POOL.get()?;
// this is an updated comment from the bot itself

// parse out each "responded" status for each user, then update them
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment still in the right place?

}

let comment: IssueComment = issuecomment::table
.find(survey.fk_bot_tracking_comment)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading this code now, I'm wondering whether things like this shouldn't also be impl'd as small methods on the Poll type to more clearly separate the logic of a poll from its db semantics.

i.e.

let comment: IssueComment = self.tracking_comment()?;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally yes - that would be optimal, but I think this is a larger refactoring that would affect much more code than this PR, so I'd like to punt for now :)

for username in parse_ticky_boxes("poll", survey.id, &comment) {
let user: GitHubUser = githubuser::table
.filter(githubuser::login.eq(username))
.first(conn)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC this will currently fail the entire poll if someone typo's one of the provided usernames. Do we have an error reporting mechanism for that?

fn evaluate_nags() -> DashResult<()> {
evaluate_pendings()?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this now, should we attempt to make progress on all three and combine the errors if more than one fails?

-> DashResult<()> {
use self::RfcBotCommand::*;
match self {
AskQuestion { teams, question } =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use a single internal name for questions/polls etc?

Copy link
Member

@anp anp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:D

@Centril
Copy link
Contributor Author

Centril commented Aug 16, 2018

:shipit:

@Centril Centril merged commit ce8e298 into rust-lang:master Aug 16, 2018
@Centril Centril deleted the feature/poll-team-2 branch August 16, 2018 03:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Accept command "@rfcbot : fcp postpone" (literally) @rfcbot poll [team]
3 participants