GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Require current PR mentions for workflow coordinator links (#5933) · Abaso007/SpacetimeDB@b0c01fb

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • tools/ci/commands/workflow-coordinator/src
    • main.rs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎tools/ci/commands/workflow-coordinator/src/main.rs‎

Copy file name to clipboardExpand all lines: tools/ci/commands/workflow-coordinator/src/main.rs
+43-1Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ struct PullRequest {
205205
number: u64,
206206
state: String,
207207
head: PullRequestRef,
208+
body: Option<String>,
208209
}
209210

210211
#[derive(Deserialize)]
@@ -336,7 +337,10 @@ fn related_private_pr(public_pr_number: Option<u64>) -> Result<Option<PullReques
336337
let mut pulls = Vec::new();
337338
for number in numbers {
338339
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+
{
340344
pulls.push(pull);
341345
}
342346
}
@@ -346,6 +350,23 @@ fn related_private_pr(public_pr_number: Option<u64>) -> Result<Option<PullReques
346350
Ok(pulls.pop())
347351
}
348352

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+
349370
fn resolve_private_source(public_pr_number: Option<u64>) -> Result<PrivateSource> {
350371
if let Some(pull) = related_private_pr(public_pr_number)? {
351372
println!("Found a linked private PR.");
@@ -578,6 +599,7 @@ mod tests {
578599
full_name: PRIVATE_REPO.to_owned(),
579600
}),
580601
},
602+
body: Some(format!("{PUBLIC_REPO}#123")),
581603
}
582604
}
583605

@@ -662,4 +684,24 @@ mod tests {
662684
})
663685
);
664686
}
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+
}
665707
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.