forked from the-distro/ofborg
If a commit is missing, dump the job. If the commit fails to merge, reportt the error
This commit is contained in:
parent
512d02264b
commit
ffcae86401
|
@ -105,6 +105,21 @@ impl CachedProjectCo {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn commit_exists(&self, commit: &OsStr) -> bool {
|
||||
let mut lock = self.lock().expect("Failed to lock");
|
||||
|
||||
let result = Command::new("git")
|
||||
.arg("show")
|
||||
.arg(commit)
|
||||
.current_dir(self.clone_to())
|
||||
.status()
|
||||
.expect("git show <commit> failed");
|
||||
|
||||
lock.unlock();
|
||||
|
||||
return result.success();
|
||||
}
|
||||
|
||||
pub fn merge_commit(&self, commit: &OsStr) -> Result<(), Error> {
|
||||
let mut lock = self.lock()?;
|
||||
|
||||
|
|
|
@ -20,6 +20,40 @@ pub struct Actions {
|
|||
}
|
||||
|
||||
impl Actions {
|
||||
pub fn commit_missing(&mut self, _job: &BuildJob) -> worker::Actions {
|
||||
return vec![
|
||||
worker::Action::Ack
|
||||
];
|
||||
}
|
||||
|
||||
pub fn merge_failed(&mut self, job: &BuildJob) -> worker::Actions {
|
||||
let msg = buildresult::BuildResult {
|
||||
repo: job.repo.clone(),
|
||||
pr: job.pr.clone(),
|
||||
system: self.system.clone(),
|
||||
output: vec![String::from("Merge failed")],
|
||||
success: false
|
||||
};
|
||||
|
||||
let props = protocol::basic::BasicProperties {
|
||||
content_type: Some("application/json".to_owned()),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
||||
return vec![
|
||||
worker::Action::Publish(worker::QueueMsg{
|
||||
exchange: Some("build-results".to_owned()),
|
||||
routing_key: None,
|
||||
mandatory: true,
|
||||
immediate: false,
|
||||
properties: Some(props),
|
||||
content: serde_json::to_string(&msg).unwrap().into_bytes()
|
||||
}),
|
||||
worker::Action::Ack
|
||||
];
|
||||
}
|
||||
|
||||
pub fn build_finished(&mut self, job: &BuildJob, success: bool, lines: Vec<String>) -> worker::Actions {
|
||||
let msg = buildresult::BuildResult {
|
||||
repo: job.repo.clone(),
|
||||
|
|
|
@ -64,7 +64,16 @@ impl worker::SimpleWorker for BuildWorker {
|
|||
|
||||
let refpath = co.checkout_ref(target_branch.as_ref()).unwrap();
|
||||
co.fetch_pr(job.pr.number).unwrap();
|
||||
co.merge_commit(job.pr.head_sha.as_ref()).unwrap();
|
||||
|
||||
if !co.commit_exists(job.pr.head_sha.as_ref()) {
|
||||
info!("Commit {} doesn't exist", job.pr.head_sha);
|
||||
return self.actions().commit_missing(&job);
|
||||
}
|
||||
|
||||
if let Err(_) = co.merge_commit(job.pr.head_sha.as_ref()) {
|
||||
info!("Failed to merge {}", job.pr.head_sha);
|
||||
return self.actions().merge_failed(&job);
|
||||
}
|
||||
|
||||
println!("Got path: {:?}, building", refpath);
|
||||
|
||||
|
|
Loading…
Reference in a new issue