|
18 | 18 | //! the PR modifies.
|
19 | 19 |
|
20 | 20 | use crate::{
|
21 |
| - config::AssignConfig, |
| 21 | + config::{AssignConfig, WarnNonDefaultBranchException}, |
22 | 22 | github::{self, Event, FileDiff, Issue, IssuesAction, Selection},
|
23 | 23 | handlers::{Context, GithubClient, IssuesEvent},
|
24 | 24 | interactions::EditIssueBody,
|
@@ -73,6 +73,11 @@ const NON_DEFAULT_BRANCH: &str =
|
73 | 73 | but this one is against {target}. \
|
74 | 74 | Please double check that you specified the right target!";
|
75 | 75 |
|
| 76 | +const NON_DEFAULT_BRANCH_EXCEPTION: &str = |
| 77 | + "Pull requests targetting the {default} branch are usually filed against the {default} \ |
| 78 | + branch, but this one is against {target}. \ |
| 79 | + Please double check that you specified the right target!"; |
| 80 | + |
76 | 81 | const SUBMODULE_WARNING_MSG: &str = "These commits modify **submodules**.";
|
77 | 82 |
|
78 | 83 | fn on_vacation_msg(user: &str) -> String {
|
@@ -179,8 +184,8 @@ pub(super) async fn handle_input(
|
179 | 184 |
|
180 | 185 | // Compute some warning messages to post to new PRs.
|
181 | 186 | let mut warnings = Vec::new();
|
182 |
| - if config.warn_non_default_branch { |
183 |
| - warnings.extend(non_default_branch(event)); |
| 187 | + if let Some(exceptions) = config.warn_non_default_branch.enabled_and_exceptions() { |
| 188 | + warnings.extend(non_default_branch(exceptions, event)); |
184 | 189 | }
|
185 | 190 | warnings.extend(modifies_submodule(diff));
|
186 | 191 | if !warnings.is_empty() {
|
@@ -209,15 +214,25 @@ fn is_self_assign(assignee: &str, pr_author: &str) -> bool {
|
209 | 214 | assignee.to_lowercase() == pr_author.to_lowercase()
|
210 | 215 | }
|
211 | 216 |
|
212 |
| -/// Returns a message if the PR is opened against the non-default branch. |
213 |
| -fn non_default_branch(event: &IssuesEvent) -> Option<String> { |
| 217 | +/// Returns a message if the PR is opened against the non-default branch (or the exception branch |
| 218 | +/// if it's an exception). |
| 219 | +fn non_default_branch( |
| 220 | + exceptions: &[WarnNonDefaultBranchException], |
| 221 | + event: &IssuesEvent, |
| 222 | +) -> Option<String> { |
214 | 223 | let target_branch = &event.issue.base.as_ref().unwrap().git_ref;
|
215 |
| - let default_branch = &event.repository.default_branch; |
| 224 | + let (default_branch, warn_msg) = exceptions |
| 225 | + .iter() |
| 226 | + .find(|e| event.issue.title.contains(&e.title)) |
| 227 | + .map_or_else( |
| 228 | + || (&event.repository.default_branch, NON_DEFAULT_BRANCH), |
| 229 | + |e| (&e.branch, NON_DEFAULT_BRANCH_EXCEPTION), |
| 230 | + ); |
216 | 231 | if target_branch == default_branch {
|
217 | 232 | return None;
|
218 | 233 | }
|
219 | 234 | Some(
|
220 |
| - NON_DEFAULT_BRANCH |
| 235 | + warn_msg |
221 | 236 | .replace("{default}", default_branch)
|
222 | 237 | .replace("{target}", target_branch),
|
223 | 238 | )
|
|
0 commit comments