Skip to content

Commit 6c5294c

Browse files
authored
Merge pull request #2519 from Urgau/milestone-josh-subtrees
Handle JOSH subtrees when milestoning rust-lang/rust PRs
2 parents d21a5ed + 0b65013 commit 6c5294c

3 files changed

Lines changed: 25 additions & 12 deletions

File tree

‎src/github/repos.rs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,10 @@ impl GithubClient {
274274
response.text().await.context("raw gist from url")
275275
}
276276

277+
/// Get an individual rust-lang/rust commit details (including modified files)
277278
pub async fn rust_commit(&self, sha: &str) -> Option<GithubCommit> {
278279
let req = self.get(&format!(
279-
"{}/repos/rust-lang/rust/commits/{sha}",
280+
"{}/repos/rust-lang/rust/commits/{sha}?per_page=1000",
280281
self.api_url
281282
));
282283
match self.json(req).await {
@@ -1090,6 +1091,9 @@ pub struct GithubCommit {
10901091
pub commit: GithubCommitCommitField,
10911092
pub parents: Vec<Parent>,
10921093
pub html_url: String,
1094+
// only populated when fetching individual commits, not ranges
1095+
#[serde(default)]
1096+
pub files: Option<Vec<GithubCommitFile>>,
10931097
}
10941098

10951099
#[derive(Clone, Debug, serde::Deserialize)]
@@ -1099,6 +1103,12 @@ pub struct GithubCommitCommitField {
10991103
pub tree: GitCommitTree,
11001104
}
11011105

1106+
#[derive(Clone, Debug, serde::Deserialize)]
1107+
pub struct GithubCommitFile {
1108+
pub sha: String,
1109+
pub filename: String,
1110+
}
1111+
11021112
#[derive(Debug, serde::Deserialize)]
11031113
pub struct GitCommit {
11041114
pub sha: String,

‎src/handlers/check_commits.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ fn dummy_commit_from_body(sha: &str, body: &str) -> GithubCommit {
357357
},
358358
},
359359
parents: vec![],
360+
files: None,
360361
html_url: "".to_owned(),
361362
}
362363
}

‎src/handlers/milestone_prs.rs‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub(super) async fn handle(ctx: &Context, event: &Event) -> anyhow::Result<()> {
6363
e.issue.set_milestone(&ctx.github, &version).await?;
6464

6565
milestone_submodules(&ctx.github, e, &version).await?;
66-
milestone_git_subtrees(&ctx.github, e, &version).await?;
66+
milestone_josh_subtrees(&ctx.github, e, &version).await?;
6767

6868
Ok(())
6969
}
@@ -197,7 +197,7 @@ async fn milestone_submodule(
197197
Ok(())
198198
}
199199

200-
async fn milestone_git_subtrees(
200+
async fn milestone_josh_subtrees(
201201
gh: &GithubClient,
202202
event: &IssuesEvent,
203203
milestone_version: &str,
@@ -221,7 +221,7 @@ async fn milestone_git_subtrees(
221221
let mv = milestone_version.to_owned();
222222
let gh = gh.clone();
223223
tokio::task::spawn(async move {
224-
if let Err(e) = milestone_git_subtree(&gh, repo, commits, mv).await {
224+
if let Err(e) = milestone_josh_subtree(&gh, repo, subtree, commits, mv).await {
225225
log::error!("failed to milestone {subtree}: {e:?}");
226226
}
227227
});
@@ -231,10 +231,11 @@ async fn milestone_git_subtrees(
231231
Ok(())
232232
}
233233

234-
/// Try to sync milestones from rust-lang/rust to one of it's git subtrees.
235-
async fn milestone_git_subtree(
234+
/// Try to sync milestones from rust-lang/rust to one of it's a JOSH subtrees
235+
async fn milestone_josh_subtree(
236236
gh: &GithubClient,
237237
repo_name: &str,
238+
subtree_dir: &str,
238239
commits: Vec<crate::github::GithubCommit>,
239240
milestone_version: String,
240241
) -> anyhow::Result<()> {
@@ -280,12 +281,13 @@ async fn milestone_git_subtree(
280281

281282
let pr_numbers = merge_commits
282283
.filter_map(async |(pr_number, merge_commit)| {
283-
// Check that the merge commit exists on the git subtree
284-
subtree
285-
.github_commit(&gh, &merge_commit.sha)
286-
.await
287-
.ok()
288-
.map(|_| pr_number)
284+
// Check that the commit only modifies files in the subtree directory
285+
let commit = gh.rust_commit(&merge_commit.sha).await?;
286+
let files = commit.files?;
287+
files
288+
.iter()
289+
.all(|f| f.filename.starts_with(subtree_dir))
290+
.then_some(pr_number)
289291
})
290292
.collect::<Vec<_>>()
291293
.await;

0 commit comments

Comments
 (0)