@@ -40,6 +40,12 @@ const STATUS_CHECK_FREQUENCY: Duration = Duration::from_secs(60 * 30);
4040/// How often we try to auto close votes that have already passed.
4141const AUTO_CLOSE_FREQUENCY : Duration = Duration :: from_secs ( 60 * 60 * 24 ) ;
4242
43+ /// Label used to tag issues/prs where a vote has been created.
44+ const GITVOTE_LABEL : & str = "gitvote" ;
45+
46+ /// Label used to tag issues/prs where a vote is open.
47+ const VOTE_OPEN_LABEL : & str = "vote open" ;
48+
4349/// A votes processor is in charge of creating the requested votes, stopping
4450/// them at the scheduled time and publishing results, etc.
4551pub ( crate ) struct Processor {
@@ -313,6 +319,17 @@ impl Processor {
313319 . await ?;
314320 }
315321
322+ // Add "vote open" label to issue/pr
323+ self . gh
324+ . add_labels (
325+ inst_id,
326+ owner,
327+ repo,
328+ i. issue_number ,
329+ & [ GITVOTE_LABEL , VOTE_OPEN_LABEL ] ,
330+ )
331+ . await ?;
332+
316333 debug ! ( ?vote_id, "created" ) ;
317334 Ok ( ( ) )
318335 }
@@ -352,15 +369,23 @@ impl Processor {
352369 . post_comment ( inst_id, owner, repo, i. issue_number , & body)
353370 . await ?;
354371
355- // Create check run if needed
356- if cancelled_vote_id. is_some ( ) && i. is_pull_request {
357- let check_details = CheckDetails {
358- status : "completed" . to_string ( ) ,
359- conclusion : Some ( "success" . to_string ( ) ) ,
360- summary : "Vote cancelled" . to_string ( ) ,
361- } ;
372+ // Create check run and remove "vote open" label if the vote was cancelled
373+ if cancelled_vote_id. is_some ( ) {
374+ // Create check run if the vote is on a pull request
375+ if i. is_pull_request {
376+ let check_details = CheckDetails {
377+ status : "completed" . to_string ( ) ,
378+ conclusion : Some ( "success" . to_string ( ) ) ,
379+ summary : "Vote cancelled" . to_string ( ) ,
380+ } ;
381+ self . gh
382+ . create_check_run ( inst_id, owner, repo, i. issue_number , & check_details)
383+ . await ?;
384+ }
385+
386+ // Remove "vote open" label from issue/pr
362387 self . gh
363- . create_check_run ( inst_id, owner, repo, i. issue_number , & check_details )
388+ . remove_label ( inst_id, owner, repo, i. issue_number , VOTE_OPEN_LABEL )
364389 . await ?;
365390 }
366391
@@ -469,6 +494,11 @@ impl Processor {
469494 . await ?;
470495 }
471496
497+ // Remove "vote open" label from issue/pr
498+ self . gh
499+ . remove_label ( inst_id, owner, repo, vote. issue_number , VOTE_OPEN_LABEL )
500+ . await ?;
501+
472502 debug ! ( "closed" ) ;
473503 Ok ( Some ( ( ) ) )
474504 }
@@ -834,6 +864,15 @@ mod tests {
834864 && body == expected_body. as_str ( )
835865 } )
836866 . returning ( |_, _, _, _, _| Box :: pin ( future:: ready ( Ok ( COMMENT_ID ) ) ) ) ;
867+ gh. expect_add_labels ( )
868+ . withf ( |inst_id, owner, repo, issue_number, labels| {
869+ * inst_id == INST_ID
870+ && owner == ORG
871+ && repo == REPO
872+ && * issue_number == ISSUE_NUM
873+ && labels == vec ! [ GITVOTE_LABEL , VOTE_OPEN_LABEL ]
874+ } )
875+ . returning ( |_, _, _, _, _| Box :: pin ( future:: ready ( Ok ( ( ) ) ) ) ) ;
837876
838877 let votes_processor = Processor :: new ( Arc :: new ( db) , Arc :: new ( gh) ) ;
839878 votes_processor
@@ -899,6 +938,15 @@ mod tests {
899938 } ) ,
900939 )
901940 . returning ( |_, _, _, _, _| Box :: pin ( future:: ready ( Ok ( ( ) ) ) ) ) ;
941+ gh. expect_add_labels ( )
942+ . withf ( |inst_id, owner, repo, issue_number, labels| {
943+ * inst_id == INST_ID
944+ && owner == ORG
945+ && repo == REPO
946+ && * issue_number == ISSUE_NUM
947+ && labels == vec ! [ GITVOTE_LABEL , VOTE_OPEN_LABEL ]
948+ } )
949+ . returning ( |_, _, _, _, _| Box :: pin ( future:: ready ( Ok ( ( ) ) ) ) ) ;
902950
903951 let votes_processor = Processor :: new ( Arc :: new ( db) , Arc :: new ( gh) ) ;
904952 votes_processor
@@ -1007,6 +1055,15 @@ mod tests {
10071055 && body == expected_body. as_str ( )
10081056 } )
10091057 . returning ( |_, _, _, _, _| Box :: pin ( future:: ready ( Ok ( COMMENT_ID ) ) ) ) ;
1058+ gh. expect_remove_label ( )
1059+ . with (
1060+ eq ( INST_ID ) ,
1061+ eq ( ORG ) ,
1062+ eq ( REPO ) ,
1063+ eq ( ISSUE_NUM ) ,
1064+ eq ( VOTE_OPEN_LABEL ) ,
1065+ )
1066+ . returning ( |_, _, _, _, _| Box :: pin ( future:: ready ( Ok ( ( ) ) ) ) ) ;
10101067 let event = setup_test_issue_comment_event ( ) ;
10111068
10121069 let votes_processor = Processor :: new ( Arc :: new ( db) , Arc :: new ( gh) ) ;
@@ -1049,6 +1106,15 @@ mod tests {
10491106 } ) ,
10501107 )
10511108 . returning ( |_, _, _, _, _| Box :: pin ( future:: ready ( Ok ( ( ) ) ) ) ) ;
1109+ gh. expect_remove_label ( )
1110+ . with (
1111+ eq ( INST_ID ) ,
1112+ eq ( ORG ) ,
1113+ eq ( REPO ) ,
1114+ eq ( ISSUE_NUM ) ,
1115+ eq ( VOTE_OPEN_LABEL ) ,
1116+ )
1117+ . returning ( |_, _, _, _, _| Box :: pin ( future:: ready ( Ok ( ( ) ) ) ) ) ;
10521118 let event = setup_test_pr_event ( ) ;
10531119
10541120 let votes_processor = Processor :: new ( Arc :: new ( db) , Arc :: new ( gh) ) ;
@@ -1216,6 +1282,15 @@ mod tests {
12161282 && body == expected_body. as_str ( )
12171283 } )
12181284 . returning ( |_, _, _, _, _| Box :: pin ( future:: ready ( Ok ( COMMENT_ID ) ) ) ) ;
1285+ gh. expect_remove_label ( )
1286+ . with (
1287+ eq ( INST_ID ) ,
1288+ eq ( ORG ) ,
1289+ eq ( REPO ) ,
1290+ eq ( ISSUE_NUM ) ,
1291+ eq ( VOTE_OPEN_LABEL ) ,
1292+ )
1293+ . returning ( |_, _, _, _, _| Box :: pin ( future:: ready ( Ok ( ( ) ) ) ) ) ;
12191294
12201295 let votes_processor = Processor :: new ( Arc :: new ( db) , Arc :: new ( gh) ) ;
12211296 votes_processor. close_finished_vote ( ) . await . unwrap ( ) ;
@@ -1256,6 +1331,15 @@ mod tests {
12561331 } ) ,
12571332 )
12581333 . returning ( |_, _, _, _, _| Box :: pin ( future:: ready ( Ok ( ( ) ) ) ) ) ;
1334+ gh. expect_remove_label ( )
1335+ . with (
1336+ eq ( INST_ID ) ,
1337+ eq ( ORG ) ,
1338+ eq ( REPO ) ,
1339+ eq ( ISSUE_NUM ) ,
1340+ eq ( VOTE_OPEN_LABEL ) ,
1341+ )
1342+ . returning ( |_, _, _, _, _| Box :: pin ( future:: ready ( Ok ( ( ) ) ) ) ) ;
12591343
12601344 let votes_processor = Processor :: new ( Arc :: new ( db) , Arc :: new ( gh) ) ;
12611345 votes_processor. close_finished_vote ( ) . await . unwrap ( ) ;
@@ -1300,6 +1384,15 @@ mod tests {
13001384 } ) ,
13011385 )
13021386 . returning ( |_, _, _, _, _| Box :: pin ( future:: ready ( Ok ( ( ) ) ) ) ) ;
1387+ gh. expect_remove_label ( )
1388+ . with (
1389+ eq ( INST_ID ) ,
1390+ eq ( ORG ) ,
1391+ eq ( REPO ) ,
1392+ eq ( ISSUE_NUM ) ,
1393+ eq ( VOTE_OPEN_LABEL ) ,
1394+ )
1395+ . returning ( |_, _, _, _, _| Box :: pin ( future:: ready ( Ok ( ( ) ) ) ) ) ;
13031396
13041397 let votes_processor = Processor :: new ( Arc :: new ( db) , Arc :: new ( gh) ) ;
13051398 votes_processor. close_finished_vote ( ) . await . unwrap ( ) ;
0 commit comments