@@ -19,6 +19,7 @@ use crate::github::{CommitSha, GithubUser, LabelTrigger, MergeError, PullRequest
19
19
use crate :: permissions:: PermissionType ;
20
20
use crate :: utils:: text:: suppress_github_mentions;
21
21
use anyhow:: { Context , anyhow} ;
22
+ use itertools:: Itertools ;
22
23
use octocrab:: params:: checks:: CheckRunConclusion ;
23
24
use octocrab:: params:: checks:: CheckRunOutput ;
24
25
use octocrab:: params:: checks:: CheckRunStatus ;
@@ -87,7 +88,11 @@ pub(super) async fn command_try_build(
87
88
& repo. client ,
88
89
& pr. github . head . sha ,
89
90
& base_sha,
90
- & auto_merge_commit_message ( pr, repo. client . repository ( ) , "<try>" , jobs) ,
91
+ & create_merge_commit_message (
92
+ pr,
93
+ repo. client . repository ( ) ,
94
+ MergeType :: Try { try_jobs : jobs } ,
95
+ ) ,
91
96
)
92
97
. await ?
93
98
{
@@ -339,28 +344,54 @@ fn get_pending_build(pr: &PullRequestModel) -> Option<&BuildModel> {
339
344
. and_then ( |b| ( b. status == BuildStatus :: Pending ) . then_some ( b) )
340
345
}
341
346
342
- fn auto_merge_commit_message (
347
+ /// Prefix used to specify custom try jobs in PR descriptions.
348
+ const CUSTOM_TRY_JOB_PREFIX : & str = "try-job:" ;
349
+
350
+ enum MergeType {
351
+ Try { try_jobs : Vec < String > } ,
352
+ }
353
+
354
+ fn create_merge_commit_message (
343
355
pr : & PullRequestData ,
344
356
name : & GithubRepoName ,
345
- reviewer : & str ,
346
- jobs : Vec < String > ,
357
+ merge_type : MergeType ,
347
358
) -> String {
348
359
let pr_number = pr. number ( ) ;
360
+
361
+ let reviewer = match & merge_type {
362
+ MergeType :: Try { .. } => "<try>" ,
363
+ } ;
364
+
365
+ let mut pr_description = suppress_github_mentions ( & pr. github . message ) ;
366
+ match & merge_type {
367
+ // Strip all PR text for try builds, to avoid useless issue pings on the repository.
368
+ // Only keep any lines starting with `CUSTOM_TRY_JOB_PREFIX`.
369
+ MergeType :: Try { .. } => {
370
+ pr_description = pr_description
371
+ . lines ( )
372
+ . map ( |l| l. trim ( ) )
373
+ . filter ( |l| l. starts_with ( CUSTOM_TRY_JOB_PREFIX ) )
374
+ . join ( "\n " ) ;
375
+ }
376
+ } ;
377
+
349
378
let mut message = format ! (
350
379
r#"Auto merge of {repo_owner}/{repo_name}#{pr_number} - {pr_label}, r={reviewer}
351
380
{pr_title}
352
381
353
- {pr_message }"# ,
382
+ {pr_description }"# ,
354
383
pr_label = pr. github. head_label,
355
384
pr_title = pr. github. title,
356
- pr_message = suppress_github_mentions( & pr. github. message) ,
357
385
repo_owner = name. owner( ) ,
358
386
repo_name = name. name( )
359
387
) ;
360
388
361
- // if jobs is empty, try-job won't be added to the message
362
- for job in jobs {
363
- message. push_str ( & format ! ( "\n try-job: {}" , job) ) ;
389
+ match merge_type {
390
+ MergeType :: Try { try_jobs } => {
391
+ for job in try_jobs {
392
+ message. push_str ( & format ! ( "\n {CUSTOM_TRY_JOB_PREFIX} {}" , job) ) ;
393
+ }
394
+ }
364
395
}
365
396
message
366
397
}
@@ -470,15 +501,55 @@ mod tests {
470
501
}
471
502
472
503
#[ sqlx:: test]
473
- async fn try_merge_commit_message ( pool : sqlx:: PgPool ) {
504
+ async fn try_commit_message_strip_description ( pool : sqlx:: PgPool ) {
474
505
run_test ( pool, async |tester : & mut BorsTester | {
506
+ tester
507
+ . edit_pr ( default_repo_name ( ) , default_pr_number ( ) , |pr| {
508
+ pr. description = r"This is a very good PR.
509
+
510
+ It fixes so many issues, sir."
511
+ . to_string ( ) ;
512
+ } )
513
+ . await ?;
514
+
475
515
tester. post_comment ( "@bors try" ) . await ?;
476
516
tester. expect_comments ( 1 ) . await ;
517
+
518
+ insta:: assert_snapshot!( tester. get_branch_commit_message( & tester. try_branch( ) ) , @r"
519
+ Auto merge of rust-lang/borstest#1 - pr-1, r=<try>
520
+ PR #1
521
+ " ) ;
522
+ Ok ( ( ) )
523
+ } )
524
+ . await ;
525
+ }
526
+
527
+ #[ sqlx:: test]
528
+ async fn try_commit_message_strip_description_keep_try_jobs ( pool : sqlx:: PgPool ) {
529
+ run_test ( pool, async |tester : & mut BorsTester | {
530
+ tester
531
+ . edit_pr ( default_repo_name ( ) , default_pr_number ( ) , |pr| {
532
+ pr. description = r"This is a very good PR.
533
+
534
+ try-job: Foo
535
+
536
+ It fixes so many issues, sir.
537
+
538
+ try-job: Bar
539
+ "
540
+ . to_string ( ) ;
541
+ } )
542
+ . await ?;
543
+
544
+ tester. post_comment ( "@bors try" ) . await ?;
545
+ tester. expect_comments ( 1 ) . await ;
546
+
477
547
insta:: assert_snapshot!( tester. get_branch_commit_message( & tester. try_branch( ) ) , @r"
478
548
Auto merge of rust-lang/borstest#1 - pr-1, r=<try>
479
549
PR #1
480
550
481
- Description of PR #1
551
+ try-job: Foo
552
+ try-job: Bar
482
553
" ) ;
483
554
Ok ( ( ) )
484
555
} )
0 commit comments