Skip to content

Commit 7713255

Browse files
Mauricio Cassolajoulei
authored andcommitted
Run format
1 parent ec48792 commit 7713255

File tree

6 files changed

+56
-51
lines changed

6 files changed

+56
-51
lines changed

parser/src/command.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use regex::Regex;
55

66
pub mod assign;
77
pub mod close;
8+
pub mod decision;
89
pub mod glacier;
910
pub mod nominate;
1011
pub mod note;
@@ -13,7 +14,6 @@ pub mod prioritize;
1314
pub mod relabel;
1415
pub mod second;
1516
pub mod shortcut;
16-
pub mod decision;
1717

1818
#[derive(Debug, PartialEq)]
1919
pub enum Command<'a> {

parser/src/command/decision.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,35 @@
88
//! Command: `@bot merge`, `@bot hold`, `@bot restart`, `@bot dissent`, `@bot stabilize` or `@bot close`.
99
//! ```
1010
11-
use crate::token::{Token, Tokenizer};
1211
use crate::error::Error;
13-
use serde::{Deserialize, Serialize};
12+
use crate::token::{Token, Tokenizer};
1413
use postgres_types::{FromSql, ToSql};
14+
use serde::{Deserialize, Serialize};
1515

1616
/// A command as parsed and received from calling the bot with some arguments,
1717
/// like `@rustbot merge`
1818
#[derive(Debug, Eq, PartialEq)]
1919
pub struct DecisionCommand {
2020
pub resolution: Resolution,
21-
pub reversibility: Reversibility
21+
pub reversibility: Reversibility,
2222
}
2323

2424
impl DecisionCommand {
2525
pub fn parse<'a>(input: &mut Tokenizer<'a>) -> Result<Option<Self>, Error<'a>> {
2626
if let Some(Token::Word("merge")) = input.peek_token()? {
27-
Ok(Some(Self {
28-
resolution: Resolution::Merge,
29-
reversibility: Reversibility::Reversible
30-
})) } else {
27+
Ok(Some(Self {
28+
resolution: Resolution::Merge,
29+
reversibility: Reversibility::Reversible,
30+
}))
31+
} else {
3132
Ok(None)
3233
}
3334
}
3435
}
3536

3637
#[derive(Debug, Eq, PartialEq)]
3738
pub enum ParseError {
38-
InvalidFirstCommand
39+
InvalidFirstCommand,
3940
}
4041

4142
#[derive(Serialize, Deserialize, Debug, Clone, ToSql, FromSql, Eq, PartialEq)]

src/db.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use std::sync::{Arc, Mutex};
88
use tokio::sync::{OwnedSemaphorePermit, Semaphore};
99
use tokio_postgres::Client as DbClient;
1010

11-
pub mod issue_decision_state;
1211
pub mod issue_data;
12+
pub mod issue_decision_state;
1313
pub mod jobs;
1414
pub mod notifications;
1515
pub mod rustc_commits;
@@ -280,7 +280,7 @@ CREATE TYPE reversibility AS ENUM ('reversible', 'irreversible');
280280
"
281281
CREATE TYPE resolution AS ENUM ('hold', 'merge');
282282
",
283-
"CREATE TABLE issue_decision_state (
283+
"CREATE TABLE issue_decision_state (
284284
issue_id BIGINT PRIMARY KEY,
285285
initiator TEXT NOT NULL,
286286
start_date TIMESTAMP WITH TIME ZONE NOT NULL,

src/db/issue_decision_state.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
//! The issue decision state table provides a way to store
1+
//! The issue decision state table provides a way to store
22
//! the decision process state of each issue
33
4-
use serde::{Deserialize, Serialize};
4+
use anyhow::{Context as _, Result};
55
use chrono::{DateTime, FixedOffset};
6-
use std::collections::BTreeMap;
76
use parser::command::decision::{Resolution, Reversibility};
8-
use anyhow::{Context as _, Result};
7+
use serde::{Deserialize, Serialize};
8+
use std::collections::BTreeMap;
99
use tokio_postgres::Client as DbClient;
1010

1111
#[derive(Debug, Serialize, Deserialize)]
@@ -54,13 +54,13 @@ pub async fn insert_issue_decision_state(
5454
}
5555

5656
pub async fn update_issue_decision_state(
57-
db: &DbClient,
57+
db: &DbClient,
5858
issue_number: &u64,
5959
end_date: &DateTime<FixedOffset>,
6060
current: &BTreeMap<String, UserStatus>,
6161
history: &BTreeMap<String, Vec<UserStatus>>,
6262
reversibility: &Reversibility,
63-
resolution: &Resolution
63+
resolution: &Resolution,
6464
) -> Result<()> {
6565
tracing::trace!("update_issue_decision_state(issue_id={})", issue_number);
6666
let issue_id = *issue_number as i64;
@@ -74,18 +74,21 @@ pub async fn update_issue_decision_state(
7474
Ok(())
7575
}
7676

77-
pub async fn get_issue_decision_state(db: &DbClient, issue_number: &u64) -> Result<IssueDecisionState> {
77+
pub async fn get_issue_decision_state(
78+
db: &DbClient,
79+
issue_number: &u64,
80+
) -> Result<IssueDecisionState> {
7881
tracing::trace!("get_issue_decision_state(issue_id={})", issue_number);
7982
let issue_id = *issue_number as i64;
8083

8184
let state = db
8285
.query_one(
8386
"SELECT * FROM issue_decision_state WHERE issue_id = $1",
84-
&[&issue_id]
87+
&[&issue_id],
8588
)
8689
.await
8790
.context("Getting decision state data")?;
88-
91+
8992
deserialize_issue_decision_state(&state)
9093
}
9194

@@ -95,7 +98,8 @@ fn deserialize_issue_decision_state(row: &tokio_postgres::row::Row) -> Result<Is
9598
let start_date: DateTime<FixedOffset> = row.try_get(2)?;
9699
let end_date: DateTime<FixedOffset> = row.try_get(3)?;
97100
let current: BTreeMap<String, UserStatus> = serde_json::from_value(row.try_get(4).unwrap())?;
98-
let history: BTreeMap<String, Vec<UserStatus>> = serde_json::from_value(row.try_get(5).unwrap())?;
101+
let history: BTreeMap<String, Vec<UserStatus>> =
102+
serde_json::from_value(row.try_get(5).unwrap())?;
99103
let reversibility: Reversibility = row.try_get(6)?;
100104
let resolution: Resolution = row.try_get(7)?;
101105

src/handlers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ impl fmt::Display for HandlerError {
2626
mod assign;
2727
mod autolabel;
2828
mod close;
29+
mod decision;
2930
pub mod docs_update;
3031
mod github_releases;
3132
mod glacier;
@@ -45,7 +46,6 @@ mod review_submitted;
4546
mod rfc_helper;
4647
pub mod rustc_commits;
4748
mod shortcut;
48-
mod decision;
4949

5050
pub async fn handle(ctx: &Context, event: &Event) -> Vec<HandlerError> {
5151
let config = config::get(&ctx.github, event.repo()).await;

src/handlers/decision.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
use anyhow::Context as Ctx;
21
use crate::{
3-
config::DecisionConfig,
4-
github::{Event},
5-
handlers::Context,
2+
config::DecisionConfig, db::issue_decision_state::*, github::Event, handlers::Context,
63
interactions::ErrorComment,
7-
db::issue_decision_state::*
84
};
5+
use anyhow::Context as Ctx;
96
use chrono::{DateTime, Duration, FixedOffset};
107
use parser::command::decision::{DecisionCommand, Resolution::*, Reversibility::*};
118
use std::collections::BTreeMap;
12-
use chrono::{DateTime, FixedOffset, Duration};
139

1410
// get state for issue_id from db
1511
// if no state (first call)
@@ -33,20 +29,19 @@ pub(super) async fn handle_command(
3329

3430
let DecisionCommand {
3531
resolution,
36-
reversibility
32+
reversibility,
3733
} = cmd;
3834

3935
let issue = event.issue().unwrap();
4036
let user = event.user();
4137

42-
let is_team_member =
43-
user
44-
.is_team_member(&ctx.github)
45-
.await
46-
.unwrap_or(false);
38+
let is_team_member = user.is_team_member(&ctx.github).await.unwrap_or(false);
4739

4840
if !is_team_member {
49-
let cmnt = ErrorComment::new(&issue, "Only team members can be part of the decision process.");
41+
let cmnt = ErrorComment::new(
42+
&issue,
43+
"Only team members can be part of the decision process.",
44+
);
5045
cmnt.post(&ctx.github).await?;
5146
return Ok(());
5247
}
@@ -57,41 +52,45 @@ pub(super) async fn handle_command(
5752
// Hold => "hold".into(),
5853
// Custom(name) => name,
5954
// };
60-
55+
6156
// let mut current_statuses = state.current_statuses;
6257
// let mut status_history = state.status_history;
63-
58+
6459
// if let Some(entry) = current_statuses.get_mut(&user) {
6560
// let past = status_history.entry(user).or_insert(Vec::new());
66-
61+
6762
// past.push(entry.clone());
68-
63+
6964
// *entry = UserStatus::new(name, issue_id, comment_id);
7065
// } else {
7166
// current_statuses.insert(user, UserStatus::new("hold".into(), issue_id, comment_id));
7267
// }
73-
68+
7469
// Ok(State {
7570
// current_statuses,
7671
// status_history,
7772
// ..state
7873
// })
7974
Ok(())
80-
},
75+
}
8176
_ => {
8277
match resolution {
8378
Hold => Ok(()), // change me!
8479
Merge => {
8580
let start_date: DateTime<FixedOffset> = chrono::Utc::now().into();
86-
let end_date: DateTime<FixedOffset> = start_date.checked_add_signed(Duration::days(10)).unwrap();
81+
let end_date: DateTime<FixedOffset> =
82+
start_date.checked_add_signed(Duration::days(10)).unwrap();
8783

8884
let mut current: BTreeMap<String, UserStatus> = BTreeMap::new();
89-
current.insert("mcass19".to_string(), UserStatus{
90-
comment_id: "comment_id".to_string(),
91-
text: "something".to_string(),
92-
reversibility: Reversible,
93-
resolution: Merge,
94-
});
85+
current.insert(
86+
"mcass19".to_string(),
87+
UserStatus {
88+
comment_id: "comment_id".to_string(),
89+
text: "something".to_string(),
90+
reversibility: Reversible,
91+
resolution: Merge,
92+
},
93+
);
9594
let history: BTreeMap<String, Vec<UserStatus>> = BTreeMap::new();
9695

9796
insert_issue_decision_state(
@@ -104,15 +103,16 @@ pub(super) async fn handle_command(
104103
&history,
105104
&reversibility,
106105
&Merge,
107-
).await?;
106+
)
107+
.await?;
108108

109109
// let team = github::get_team(&ctx.github, &"T-lang"); // change this to be configurable in toml?
110-
110+
111111
let comment = format!(
112112
"Wow, it looks like you want to merge this, {}.\n| Team member | State |\n|-------------|-------|\n| julmontesdeoca | merge |\n| mcass19 | |",
113113
user.login
114114
);
115-
115+
116116
issue
117117
.post_comment(&ctx.github, &comment)
118118
.await

0 commit comments

Comments
 (0)