44use crate :: {
55 config:: NoMergesConfig ,
66 db:: issue_data:: IssueData ,
7- github:: { IssuesAction , IssuesEvent } ,
7+ github:: { IssuesAction , IssuesEvent , Label } ,
88 handlers:: Context ,
99} ;
1010use anyhow:: Context as _;
@@ -38,16 +38,23 @@ pub(super) async fn parse_input(
3838 return Ok ( None ) ;
3939 }
4040
41- // Require an empty configuration block to enable no-merges notifications.
42- if config . is_none ( ) {
41+ // Require a `[no_merges]` configuration block to enable no-merges notifications.
42+ let Some ( config ) = config else {
4343 return Ok ( None ) ;
44- }
44+ } ;
4545
4646 // Don't ping on rollups or draft PRs.
4747 if event. issue . title . starts_with ( "Rollup of" ) || event. issue . draft {
4848 return Ok ( None ) ;
4949 }
5050
51+ // Don't trigger if the PR has any of the excluded labels.
52+ for label in event. issue . labels ( ) {
53+ if config. exclude_labels . contains ( & label. name ) {
54+ return Ok ( None ) ;
55+ }
56+ }
57+
5158 let mut merge_commits = HashSet :: new ( ) ;
5259 let commits = event
5360 . issue
@@ -73,22 +80,17 @@ pub(super) async fn parse_input(
7380
7481pub ( super ) async fn handle_input (
7582 ctx : & Context ,
76- _config : & NoMergesConfig ,
83+ config : & NoMergesConfig ,
7784 event : & IssuesEvent ,
7885 input : NoMergesInput ,
7986) -> anyhow:: Result < ( ) > {
8087 let mut client = ctx. db . get ( ) . await ;
8188 let mut state: IssueData < ' _ , NoMergesState > =
8289 IssueData :: load ( & mut client, & event. issue , NO_MERGES_KEY ) . await ?;
8390
84- let since_last_posted = if state . data . mentioned_merge_commits . is_empty ( ) {
85- ""
91+ let mut message = if let Some ( ref message ) = config . message {
92+ message . clone ( )
8693 } else {
87- " (since this message was last posted)"
88- } ;
89-
90- let mut should_send = false ;
91- let mut message = format ! (
9294 "
9395 There are merge commits (commits with multiple parents) in your changes. We have a
9496 [no merge policy](https://rustc-dev-guide.rust-lang.org/git.html#no-merge-policy) so
@@ -102,11 +104,25 @@ pub(super) async fn handle_input(
102104 $ # delete any merge commits in the editor that appears
103105 $ git push --force-with-lease
104106 ```
107+ "
108+ . to_string ( )
109+ } ;
105110
111+ let since_last_posted = if state. data . mentioned_merge_commits . is_empty ( ) {
112+ ""
113+ } else {
114+ " (since this message was last posted)"
115+ } ;
116+ write ! (
117+ message,
118+ "
119+
106120 The following commits are merge commits{since_last_posted}:
121+ "
122+ )
123+ . unwrap ( ) ;
107124
108- "
109- ) ;
125+ let mut should_send = false ;
110126 for commit in & input. merge_commits {
111127 if state. data . mentioned_merge_commits . contains ( commit) {
112128 continue ;
@@ -118,6 +134,20 @@ pub(super) async fn handle_input(
118134 }
119135
120136 if should_send {
137+ // Set labels
138+ let labels = config
139+ . labels
140+ . iter ( )
141+ . cloned ( )
142+ . map ( |name| Label { name } )
143+ . collect ( ) ;
144+ event
145+ . issue
146+ . add_labels ( & ctx. github , labels)
147+ . await
148+ . context ( "failed to set no_merges labels" ) ?;
149+
150+ // Post comment
121151 event
122152 . issue
123153 . post_comment ( & ctx. github , & message)
0 commit comments