Skip to content

Commit 966d5d6

Browse files
committed
Auto merge of #540 - Aaron1011:feature/warn-try-build, r=pietroalbini
Warn when try build SHA is mismatched Fixes #539 If the latest commit on the PR does not match the base commit for the detected try build, we add a warning message to the bot comment.
2 parents f0df799 + c865f7f commit 966d5d6

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

src/server/github.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub trait GitHub {
2323
fn list_teams(&self, org: &str) -> Fallible<HashMap<String, usize>>;
2424
fn team_members(&self, team: usize) -> Fallible<Vec<String>>;
2525
fn get_commit(&self, repo: &str, sha: &str) -> Fallible<Commit>;
26+
fn get_pr_head_sha(&self, repo: &str, pr: i32) -> Fallible<String>;
2627
}
2728

2829
#[derive(Clone)]
@@ -147,6 +148,15 @@ impl GitHub for GitHubApi {
147148
.json()?;
148149
Ok(commit)
149150
}
151+
152+
fn get_pr_head_sha(&self, repo: &str, pr: i32) -> Fallible<String> {
153+
let pr: PullRequestData = self
154+
.build_request(Method::GET, &format!("repos/{}/pulls/{}", repo, pr))
155+
.send()?
156+
.error_for_status()?
157+
.json()?;
158+
Ok(pr.head.sha)
159+
}
150160
}
151161

152162
#[derive(Deserialize)]
@@ -183,6 +193,16 @@ pub struct PullRequest {
183193
pub html_url: String,
184194
}
185195

196+
#[derive(Deserialize)]
197+
pub struct PullRequestData {
198+
pub head: PullRequestHead,
199+
}
200+
201+
#[derive(Deserialize)]
202+
pub struct PullRequestHead {
203+
pub sha: String,
204+
}
205+
186206
#[derive(Deserialize)]
187207
pub struct Repository {
188208
pub full_name: String,

src/server/routes/webhooks/commands.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::actions::{self, Action, ActionsCtx};
22
use crate::db::{Database, QueryUtils};
33
use crate::experiments::{CapLints, CrateSelect, Experiment, GitHubIssue, Mode, Status};
44
use crate::prelude::*;
5-
use crate::server::github::{Issue, Repository};
5+
use crate::server::github::{GitHub, Issue, Repository};
66
use crate::server::messages::{Label, Message};
77
use crate::server::routes::webhooks::args::{
88
AbortArgs, CheckArgs, EditArgs, RetryArgs, RetryReportArgs, RunArgs,
@@ -55,13 +55,17 @@ pub fn run(
5555
) -> Fallible<()> {
5656
let name = setup_run_name(&data.db, issue, args.name)?;
5757

58+
let mut message = Message::new().line(
59+
"ok_hand",
60+
format!("Experiment **`{}`** created and queued.", name),
61+
);
62+
5863
// Autodetect toolchains only if none of them was specified
59-
let (mut detected_start, mut detected_end, mut try_build) = (None, None, None);
64+
let (mut detected_start, mut detected_end) = (None, None);
6065
if args.start.is_none() && args.end.is_none() {
6166
if let Some(build) =
6267
crate::server::try_builds::get_sha(&data.db, &repo.full_name, issue.number)?
6368
{
64-
try_build = Some(build.merge_sha.clone());
6569
detected_start = Some(Toolchain {
6670
source: RustwideToolchain::ci(&build.base_sha, false),
6771
rustflags: None,
@@ -74,6 +78,20 @@ pub fn run(
7478
ci_try: true,
7579
patches: Vec::new(),
7680
});
81+
message = message.line(
82+
"robot",
83+
format!("Automatically detected try build {}", build.merge_sha),
84+
);
85+
let pr_head = data.github.get_pr_head_sha(&repo.full_name, issue.number)?;
86+
if pr_head != build.base_sha {
87+
message = message.line(
88+
"warning",
89+
format!(
90+
"Try build based on commit {}, but latest commit is {}. Did you forget to make a new try build?",
91+
build.base_sha, pr_head
92+
),
93+
);
94+
}
7795
}
7896
}
7997

@@ -110,13 +128,6 @@ pub fn run(
110128
}
111129
.apply(&ActionsCtx::new(&data.db, &data.config))?;
112130

113-
let mut message = Message::new().line(
114-
"ok_hand",
115-
format!("Experiment **`{}`** created and queued.", name),
116-
);
117-
if let Some(sha) = try_build {
118-
message = message.line("robot", format!("Automatically detected try build {}", sha));
119-
}
120131
message
121132
.line(
122133
"mag",

src/server/try_builds.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,9 @@ mod tests {
163163
.remove(&(repo.into(), sha.into()))
164164
.unwrap())
165165
}
166+
167+
fn get_pr_head_sha(&self, _repo: &str, _pr: i32) -> Fallible<String> {
168+
unimplemented!();
169+
}
166170
}
167171
}

0 commit comments

Comments
 (0)