@@ -10,6 +10,7 @@ use parser::command::{Command, Input};
10
10
pub ( super ) struct PrioritizeHandler ;
11
11
12
12
pub ( crate ) enum Prioritize {
13
+ Label ,
13
14
Start ,
14
15
End ,
15
16
}
@@ -60,7 +61,7 @@ impl Handler for PrioritizeHandler {
60
61
61
62
let mut input = Input :: new ( & body, & ctx. username ) ;
62
63
match input. parse_command ( ) {
63
- Command :: Prioritize ( Ok ( PrioritizeCommand ) ) => Ok ( Some ( Prioritize :: Start ) ) ,
64
+ Command :: Prioritize ( Ok ( PrioritizeCommand ) ) => Ok ( Some ( Prioritize :: Label ) ) ,
64
65
_ => Ok ( None ) ,
65
66
}
66
67
}
@@ -86,19 +87,25 @@ async fn handle_input(
86
87
87
88
let mut labels = issue. labels ( ) . to_owned ( ) ;
88
89
let content = match cmd {
89
- Prioritize :: Start => {
90
- // Don't add the label if it's already there, e.g., if this is a
91
- // labeled event
90
+ Prioritize :: Label => {
91
+ // Don't add the label if it's already there
92
92
if !labels. iter ( ) . any ( |l| l. name == config. label ) {
93
93
labels. push ( github:: Label {
94
94
name : config. label . clone ( ) ,
95
95
} ) ;
96
+ } else {
97
+ // TODO maybe send a GitHub message if the label is already there,
98
+ // i.e. the issue has already been requested for prioritization?
99
+ return Ok ( ( ) ) ;
96
100
}
97
- format ! (
101
+ None
102
+ }
103
+ Prioritize :: Start => {
104
+ Some ( format ! (
98
105
"@*WG-prioritization* issue [#{}]({}) has been requested for prioritization." ,
99
106
issue. number,
100
107
event. html_url( ) . unwrap( )
101
- )
108
+ ) )
102
109
}
103
110
Prioritize :: End => {
104
111
// Shouldn't be necessary in practice as we only end on label
@@ -107,36 +114,39 @@ async fn handle_input(
107
114
if let Some ( idx) = labels. iter ( ) . position ( |l| l. name == config. label ) {
108
115
labels. remove ( idx) ;
109
116
}
110
- format ! (
117
+ Some ( format ! (
111
118
"Issue [#{}]({})'s prioritization request has been removed." ,
112
119
issue. number,
113
120
event. html_url( ) . unwrap( )
114
- )
121
+ ) )
115
122
}
116
123
} ;
117
124
118
125
let github_req = issue. set_labels ( & ctx. github , labels) ;
119
126
120
- let mut zulip_topic = format ! (
121
- "{} {} {}" ,
122
- config. label,
123
- issue. zulip_topic_reference( ) ,
124
- issue. title
125
- ) ;
126
- zulip_topic. truncate ( 60 ) ; // Zulip limitation
127
-
128
- let zulip_stream = config. zulip_stream . to_string ( ) ;
129
- let zulip_req = crate :: zulip:: MessageApiRequest {
130
- type_ : "stream" ,
131
- to : & zulip_stream,
132
- topic : Some ( & zulip_topic) ,
133
- content : & content,
134
- } ;
135
-
136
- let zulip_req = zulip_req. send ( & ctx. github . raw ( ) ) ;
137
-
138
- let ( gh_res, zulip_res) = futures:: join!( github_req, zulip_req) ;
139
- gh_res?;
140
- zulip_res?;
141
- Ok ( ( ) )
127
+ if let Some ( content) = content {
128
+ let mut zulip_topic = format ! (
129
+ "{} {} {}" ,
130
+ config. label,
131
+ issue. zulip_topic_reference( ) ,
132
+ issue. title
133
+ ) ;
134
+ zulip_topic. truncate ( 60 ) ; // Zulip limitation
135
+
136
+ let zulip_stream = config. zulip_stream . to_string ( ) ;
137
+ let zulip_req = crate :: zulip:: MessageApiRequest {
138
+ type_ : "stream" ,
139
+ to : & zulip_stream,
140
+ topic : Some ( & zulip_topic) ,
141
+ content : & content,
142
+ } ;
143
+ let zulip_req = zulip_req. send ( & ctx. github . raw ( ) ) ;
144
+ let ( gh_res, zulip_res) = futures:: join!( github_req, zulip_req) ;
145
+ gh_res?;
146
+ zulip_res?;
147
+ Ok ( ( ) )
148
+ } else {
149
+ github_req. await ?;
150
+ Ok ( ( ) )
151
+ }
142
152
}
0 commit comments