Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only search src/version in rust-lang/rust, not subtrees #85

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 40 additions & 37 deletions src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,51 +355,48 @@ impl RepositoryClient<'_> {
start: &str,
path: &str,
) -> anyhow::Result<FullCommitData> {
self.start_new_request()?;
self.client.get(true)?;
self.client.url(&format!(
"https://api.github.com/repos/{repo}/commits/{start}",
repo = self.repo
))?;
let resolved_start = self
.client
.without_body()
.send_with_response::<CommitData>()?
.sha;
for page in 1..20 {
const MAX_COMMITS: usize = 200;
const BORS_EMAIL: &str = "[email protected]";

let mut commit = start.to_string();
let mut scanned_commits = 0;
for _ in 0..MAX_COMMITS {
scanned_commits += 1;

self.start_new_request()?;
self.client.get(true)?;
self.client.url(&format!(
"https://api.github.com/repos/{repo}/commits?sha={resolved_start}&per_page=100&page={page}&author=bors",
"https://api.github.com/repos/{repo}/commits/{commit}",
repo = self.repo
))?;
let commits = self

let commit_data = self
.client
.without_body()
.send_with_response::<Vec<CommitData>>()?;
for commit in commits {
self.start_new_request()?;
self.client.get(true)?;
self.client.url(&format!(
"https://api.github.com/repos/{repo}/commits/{sha}",
repo = self.repo,
sha = commit.sha,
))?;
let commit = self
.client
.without_body()
.send_with_response::<FullCommitData>()?;
if commit.files.iter().any(|f| f.filename == path) {
return Ok(commit);
}
.send_with_response::<FullCommitData>()?;

// We pick the *first* parent commit to continue walking through the commit graph. In
// a merge commit, the first parent is always the merge base (i.e. the master branch),
// while the second parent is always the branch being merged in.
//
// This is important because we only want bors merge commits for branches merged into
// Rust's master branch, not bors merge commits in subtrees being pulled in.
let Some(parent) = &commit_data.parents.first() else {
break;
};
commit.clone_from(&parent.sha);

if commit_data.commit.author.email != BORS_EMAIL {
continue;
}
if commit_data.files.iter().any(|f| f.filename == path) {
return Ok(commit_data);
}
}

anyhow::bail!(
"Failed to find bors commit touching {:?} in start={} ancestors (scanned {} commits)",
path,
start,
20 * 100,
"Failed to find bors commit touching {path:?} in \
start={start} ancestors (scanned {scanned_commits} commits)"
);
}

Expand Down Expand Up @@ -511,15 +508,21 @@ pub(crate) struct CreateTag<'a> {

#[derive(serde::Deserialize)]
pub(crate) struct FullCommitData {
#[allow(unused)]
#[cfg_attr(not(test), allow(unused))]
pub(crate) sha: String,
pub(crate) parents: Vec<CommitParent>,
pub(crate) commit: CommitCommit,
pub(crate) files: Vec<CommitFile>,
}

#[derive(serde::Deserialize)]
pub(crate) struct CommitData {
pub(crate) sha: String,
pub(crate) struct CommitCommit {
pub(crate) author: CommitAuthor,
}

#[derive(serde::Deserialize)]
pub(crate) struct CommitAuthor {
pub(crate) email: String,
}

#[derive(serde::Deserialize)]
Expand Down
Loading