@@ -31,6 +31,7 @@ pub(super) async fn handle_command(
31
31
let DecisionCommand {
32
32
resolution,
33
33
reversibility,
34
+ team : team_name,
34
35
} = cmd;
35
36
36
37
let issue = event. issue ( ) . unwrap ( ) ;
@@ -59,67 +60,91 @@ pub(super) async fn handle_command(
59
60
Ok ( ( ) )
60
61
}
61
62
_ => {
62
- let start_date: DateTime < Utc > = chrono:: Utc :: now ( ) . into ( ) ;
63
- let end_date: DateTime < Utc > =
64
- start_date. checked_add_signed ( Duration :: days ( 10 ) ) . unwrap ( ) ;
65
-
66
- let mut current: BTreeMap < String , Option < UserStatus > > = BTreeMap :: new ( ) ;
67
- let mut history: BTreeMap < String , Vec < UserStatus > > = BTreeMap :: new ( ) ;
68
-
69
- // TODO
70
- // change this to be entered by the user as part of the command
71
- // it should match the same team that we check for above when determining if the user is a member
72
- let team = github:: get_team ( & ctx. github , & "T-lang" ) . await ?. unwrap ( ) ;
73
- for member in team. members {
74
- current. insert ( member. name . clone ( ) , None ) ;
75
- history. insert ( member. name . clone ( ) , Vec :: new ( ) ) ;
63
+ match team_name {
64
+ None => {
65
+ let cmnt = ErrorComment :: new (
66
+ & issue,
67
+ "In the first vote, is necessary to specify the team name that will be involved in the decision process." ,
68
+ ) ;
69
+ cmnt. post ( & ctx. github ) . await ?;
70
+
71
+ Ok ( ( ) )
72
+ }
73
+ Some ( team_name) => {
74
+ match github:: get_team ( & ctx. github , & team_name) . await {
75
+ Ok ( Some ( team) ) => {
76
+ let start_date: DateTime < Utc > = chrono:: Utc :: now ( ) . into ( ) ;
77
+ let end_date: DateTime < Utc > =
78
+ start_date. checked_add_signed ( Duration :: days ( 10 ) ) . unwrap ( ) ;
79
+
80
+ let mut current: BTreeMap < String , Option < UserStatus > > = BTreeMap :: new ( ) ;
81
+ let mut history: BTreeMap < String , Vec < UserStatus > > = BTreeMap :: new ( ) ;
82
+
83
+ // Add team members to current and history
84
+ for member in team. members {
85
+ current. insert ( member. github . clone ( ) , None ) ;
86
+ history. insert ( member. github . clone ( ) , Vec :: new ( ) ) ;
87
+ }
88
+
89
+ // Add issue user to current and history
90
+ current. insert (
91
+ user. login . clone ( ) ,
92
+ Some ( UserStatus {
93
+ comment_id : event. html_url ( ) . unwrap ( ) . to_string ( ) ,
94
+ text : event. comment_body ( ) . unwrap ( ) . to_string ( ) ,
95
+ reversibility : reversibility,
96
+ resolution : resolution,
97
+ } ) ,
98
+ ) ;
99
+ history. insert ( user. login . clone ( ) , Vec :: new ( ) ) ;
100
+
101
+ // Initialize issue decision state
102
+ insert_issue_decision_state (
103
+ & db,
104
+ & issue. number ,
105
+ & user. login ,
106
+ & start_date,
107
+ & end_date,
108
+ & current,
109
+ & history,
110
+ & reversibility,
111
+ & resolution,
112
+ )
113
+ . await ?;
114
+
115
+ // TO DO -- Do not insert this job until we support more votes
116
+ // let metadata = serde_json::value::to_value(DecisionProcessActionMetadata {
117
+ // message: "some message".to_string(),
118
+ // get_issue_url: format!("{}/issues/{}", issue.repository().url(), issue.number),
119
+ // status: resolution,
120
+ // })
121
+ // .unwrap();
122
+ // insert_job(
123
+ // &db,
124
+ // &DECISION_PROCESS_JOB_NAME.to_string(),
125
+ // &end_date,
126
+ // &metadata,
127
+ // )
128
+ // .await?;
129
+
130
+ let comment = build_status_comment ( & history, & current) ?;
131
+ issue
132
+ . post_comment ( & ctx. github , & comment)
133
+ . await
134
+ . context ( "merge vote comment" ) ?;
135
+
136
+ Ok ( ( ) )
137
+ }
138
+ _ => {
139
+ let cmnt =
140
+ ErrorComment :: new ( & issue, "Failed to resolve to a known team." ) ;
141
+ cmnt. post ( & ctx. github ) . await ?;
142
+
143
+ Ok ( ( ) )
144
+ }
145
+ }
146
+ }
76
147
}
77
-
78
- current. insert (
79
- user. login . clone ( ) ,
80
- Some ( UserStatus {
81
- comment_id : "comment_id" . to_string ( ) ,
82
- text : "something" . to_string ( ) ,
83
- reversibility : reversibility,
84
- resolution : resolution,
85
- } ) ,
86
- ) ;
87
-
88
- insert_issue_decision_state (
89
- & db,
90
- & issue. number ,
91
- & user. login ,
92
- & start_date,
93
- & end_date,
94
- & current,
95
- & history,
96
- & reversibility,
97
- & resolution,
98
- )
99
- . await ?;
100
-
101
- // TO DO -- Do not insert this job until we support more votes
102
- // let metadata = serde_json::value::to_value(DecisionProcessActionMetadata {
103
- // message: "some message".to_string(),
104
- // get_issue_url: format!("{}/issues/{}", issue.repository().url(), issue.number),
105
- // status: resolution,
106
- // })
107
- // .unwrap();
108
- // insert_job(
109
- // &db,
110
- // &DECISION_PROCESS_JOB_NAME.to_string(),
111
- // &end_date,
112
- // &metadata,
113
- // )
114
- // .await?;
115
-
116
- let comment = build_status_comment ( & history, & current) ?;
117
- issue
118
- . post_comment ( & ctx. github , & comment)
119
- . await
120
- . context ( "merge vote comment" ) ?;
121
-
122
- Ok ( ( ) )
123
148
}
124
149
}
125
150
}
0 commit comments