4
4
use crate :: {
5
5
config:: NoMergesConfig ,
6
6
db:: issue_data:: IssueData ,
7
- github:: { IssuesAction , IssuesEvent } ,
7
+ github:: { IssuesAction , IssuesEvent , Label } ,
8
8
handlers:: Context ,
9
9
} ;
10
10
use anyhow:: Context as _;
@@ -38,16 +38,23 @@ pub(super) async fn parse_input(
38
38
return Ok ( None ) ;
39
39
}
40
40
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 {
43
43
return Ok ( None ) ;
44
- }
44
+ } ;
45
45
46
46
// Don't ping on rollups or draft PRs.
47
47
if event. issue . title . starts_with ( "Rollup of" ) || event. issue . draft {
48
48
return Ok ( None ) ;
49
49
}
50
50
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
+
51
58
let mut merge_commits = HashSet :: new ( ) ;
52
59
let commits = event
53
60
. issue
@@ -73,22 +80,17 @@ pub(super) async fn parse_input(
73
80
74
81
pub ( super ) async fn handle_input (
75
82
ctx : & Context ,
76
- _config : & NoMergesConfig ,
83
+ config : & NoMergesConfig ,
77
84
event : & IssuesEvent ,
78
85
input : NoMergesInput ,
79
86
) -> anyhow:: Result < ( ) > {
80
87
let mut client = ctx. db . get ( ) . await ;
81
88
let mut state: IssueData < ' _ , NoMergesState > =
82
89
IssueData :: load ( & mut client, & event. issue , NO_MERGES_KEY ) . await ?;
83
90
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 ( )
86
93
} else {
87
- " (since this message was last posted)"
88
- } ;
89
-
90
- let mut should_send = false ;
91
- let mut message = format ! (
92
94
"
93
95
There are merge commits (commits with multiple parents) in your changes. We have a
94
96
[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(
102
104
$ # delete any merge commits in the editor that appears
103
105
$ git push --force-with-lease
104
106
```
107
+ "
108
+ . to_string ( )
109
+ } ;
105
110
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
+
106
120
The following commits are merge commits{since_last_posted}:
121
+ "
122
+ )
123
+ . unwrap ( ) ;
107
124
108
- "
109
- ) ;
125
+ let mut should_send = false ;
110
126
for commit in & input. merge_commits {
111
127
if state. data . mentioned_merge_commits . contains ( commit) {
112
128
continue ;
@@ -118,6 +134,20 @@ pub(super) async fn handle_input(
118
134
}
119
135
120
136
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
121
151
event
122
152
. issue
123
153
. post_comment ( & ctx. github , & message)
0 commit comments