@@ -205,6 +205,7 @@ struct PullRequest { |
205 | 205 | number: u64, |
206 | 206 | state: String, |
207 | 207 | head: PullRequestRef, |
| 208 | + body: Option<String>, |
208 | 209 | } |
209 | 210 |
|
210 | 211 | #[derive(Deserialize)] |
@@ -336,7 +337,10 @@ fn related_private_pr(public_pr_number: Option<u64>) -> Result<Option<PullReques |
336 | 337 | let mut pulls = Vec::new(); |
337 | 338 | for number in numbers { |
338 | 339 | let pull = pull_request(PRIVATE_REPO, number)?; |
339 | | - if pull.state == "open" && pull.head.repo.as_ref().map(|repo| repo.full_name.as_str()) == Some(PRIVATE_REPO) { |
| 340 | + if pull.state == "open" |
| 341 | + && pull.head.repo.as_ref().map(|repo| repo.full_name.as_str()) == Some(PRIVATE_REPO) |
| 342 | + && mentions_public_pr(pull.body.as_deref(), public_pr_number) |
| 343 | + { |
340 | 344 | pulls.push(pull); |
341 | 345 | } |
342 | 346 | } |
@@ -346,6 +350,23 @@ fn related_private_pr(public_pr_number: Option<u64>) -> Result<Option<PullReques |
346 | 350 | Ok(pulls.pop()) |
347 | 351 | } |
348 | 352 |
|
| 353 | +fn mentions_public_pr(body: Option<&str>, public_pr_number: u64) -> bool { |
| 354 | + let Some(body) = body else { |
| 355 | + return false; |
| 356 | + }; |
| 357 | + let body = body.to_ascii_lowercase(); |
| 358 | + let public_repo_name = PUBLIC_REPO.rsplit_once('/').map_or(PUBLIC_REPO, |(_, repo)| repo); |
| 359 | + [ |
| 360 | + format!("{PUBLIC_REPO}#{public_pr_number}"), |
| 361 | + format!("{public_repo_name}#{public_pr_number}"), |
| 362 | + format!("github.com/{PUBLIC_REPO}/pull/{public_pr_number}"), |
| 363 | + format!("github.com/{PUBLIC_REPO}/issues/{public_pr_number}"), |
| 364 | + ] |
| 365 | + .into_iter() |
| 366 | + .map(|reference| reference.to_ascii_lowercase()) |
| 367 | + .any(|reference| body.contains(&reference)) |
| 368 | +} |
| 369 | + |
349 | 370 | fn resolve_private_source(public_pr_number: Option<u64>) -> Result<PrivateSource> { |
350 | 371 | if let Some(pull) = related_private_pr(public_pr_number)? { |
351 | 372 | println!("Found a linked private PR."); |
@@ -578,6 +599,7 @@ mod tests { |
578 | 599 | full_name: PRIVATE_REPO.to_owned(), |
579 | 600 | }), |
580 | 601 | }, |
| 602 | + body: Some(format!("{PUBLIC_REPO}#123")), |
581 | 603 | } |
582 | 604 | } |
583 | 605 |
|
@@ -662,4 +684,24 @@ mod tests { |
662 | 684 | }) |
663 | 685 | ); |
664 | 686 | } |
| 687 | + |
| 688 | + #[test] |
| 689 | + fn public_pr_mentions_include_github_reference_formats() { |
| 690 | + for body in [ |
| 691 | + format!("Depends on {PUBLIC_REPO}#123"), |
| 692 | + "Depends on SpacetimeDB#123".to_owned(), |
| 693 | + format!("Depends on https://github.com/{PUBLIC_REPO}/pull/123"), |
| 694 | + format!("Depends on https://github.com/{PUBLIC_REPO}/issues/123"), |
| 695 | + format!("Depends on https://www.github.com/{PUBLIC_REPO}/pull/123"), |
| 696 | + ] { |
| 697 | + assert!(mentions_public_pr(Some(&body), 123), "{body}"); |
| 698 | + } |
| 699 | + } |
| 700 | + |
| 701 | + #[test] |
| 702 | + fn public_pr_mentions_reject_missing_or_wrong_repo_mentions() { |
| 703 | + for body in [None, Some(""), Some("clockworklabs/SpacetimeDBPrivate#123")] { |
| 704 | + assert!(!mentions_public_pr(body, 123), "{body:?}"); |
| 705 | + } |
| 706 | + } |
665 | 707 | } |