forked from the-distro/ofborg
evaluate: start to use error returns
This commit is contained in:
parent
39af0ae208
commit
9f383f4954
|
@ -84,7 +84,10 @@ impl<E: stats::SysEvents> EvaluationWorker<E> {
|
|||
}
|
||||
}
|
||||
|
||||
fn evaluate_job(&mut self, job: &evaluationjob::EvaluationJob) -> worker::Actions {
|
||||
fn evaluate_job(
|
||||
&mut self,
|
||||
job: &evaluationjob::EvaluationJob,
|
||||
) -> Result<worker::Actions, EvalWorkerError> {
|
||||
let mut vending_machine = self
|
||||
.github_vend
|
||||
.write()
|
||||
|
@ -105,7 +108,7 @@ impl<E: stats::SysEvents> EvaluationWorker<E> {
|
|||
if iss.state == "closed" {
|
||||
self.events.notify(Event::IssueAlreadyClosed);
|
||||
info!("Skipping {} because it is closed", job.pr.number);
|
||||
return self.actions().skip(&job);
|
||||
return Ok(self.actions().skip(&job));
|
||||
}
|
||||
|
||||
if issue_is_wip(&iss) {
|
||||
|
@ -124,7 +127,7 @@ impl<E: stats::SysEvents> EvaluationWorker<E> {
|
|||
self.events.notify(Event::IssueFetchFailed);
|
||||
info!("Error fetching {}!", job.pr.number);
|
||||
info!("E: {:?}", e);
|
||||
return self.actions().skip(&job);
|
||||
return Ok(self.actions().skip(&job));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -153,12 +156,7 @@ impl<E: stats::SysEvents> EvaluationWorker<E> {
|
|||
|
||||
overall_status.set_with_description("Starting", hubcaps::statuses::State::Pending);
|
||||
|
||||
if self
|
||||
.handle_strategy_err(evaluation_strategy.pre_clone(), &gists, &mut overall_status)
|
||||
.is_err()
|
||||
{
|
||||
return self.actions().skip(&job);
|
||||
}
|
||||
evaluation_strategy.pre_clone()?;
|
||||
|
||||
let project = self
|
||||
.cloner
|
||||
|
@ -183,16 +181,7 @@ impl<E: stats::SysEvents> EvaluationWorker<E> {
|
|||
info!("Checking out target branch {}", &target_branch);
|
||||
let refpath = co.checkout_origin_ref(target_branch.as_ref()).unwrap();
|
||||
|
||||
if self
|
||||
.handle_strategy_err(
|
||||
evaluation_strategy.on_target_branch(&Path::new(&refpath), &mut overall_status),
|
||||
&gists,
|
||||
&mut overall_status,
|
||||
)
|
||||
.is_err()
|
||||
{
|
||||
return self.actions().skip(&job);
|
||||
}
|
||||
evaluation_strategy.on_target_branch(&Path::new(&refpath), &mut overall_status)?;
|
||||
|
||||
let target_branch_rebuild_sniff_start = Instant::now();
|
||||
|
||||
|
@ -212,19 +201,10 @@ impl<E: stats::SysEvents> EvaluationWorker<E> {
|
|||
.set_with_description("Commit not found", hubcaps::statuses::State::Error);
|
||||
|
||||
info!("Commit {} doesn't exist", job.pr.head_sha);
|
||||
return self.actions().skip(&job);
|
||||
return Ok(self.actions().skip(&job));
|
||||
}
|
||||
|
||||
if self
|
||||
.handle_strategy_err(
|
||||
evaluation_strategy.after_fetch(&co),
|
||||
&gists,
|
||||
&mut overall_status,
|
||||
)
|
||||
.is_err()
|
||||
{
|
||||
return self.actions().skip(&job);
|
||||
}
|
||||
evaluation_strategy.after_fetch(&co)?;
|
||||
|
||||
overall_status.set_with_description("Merging PR", hubcaps::statuses::State::Pending);
|
||||
|
||||
|
@ -236,19 +216,10 @@ impl<E: stats::SysEvents> EvaluationWorker<E> {
|
|||
|
||||
evaluation_strategy.merge_conflict();
|
||||
|
||||
return self.actions().skip(&job);
|
||||
return Ok(self.actions().skip(&job));
|
||||
}
|
||||
|
||||
if self
|
||||
.handle_strategy_err(
|
||||
evaluation_strategy.after_merge(&mut overall_status),
|
||||
&gists,
|
||||
&mut overall_status,
|
||||
)
|
||||
.is_err()
|
||||
{
|
||||
return self.actions().skip(&job);
|
||||
}
|
||||
evaluation_strategy.after_merge(&mut overall_status)?;
|
||||
|
||||
println!("Got path: {:?}, building", refpath);
|
||||
overall_status
|
||||
|
@ -301,23 +272,11 @@ impl<E: stats::SysEvents> EvaluationWorker<E> {
|
|||
let mut response: worker::Actions = vec![];
|
||||
|
||||
if eval_results {
|
||||
let ret = evaluation_strategy
|
||||
.all_evaluations_passed(&Path::new(&refpath), &mut overall_status);
|
||||
match ret {
|
||||
Ok(complete) => {
|
||||
send_check_statuses(complete.checks, &repo);
|
||||
response.extend(schedule_builds(complete.builds, auto_schedule_build_archs));
|
||||
}
|
||||
Err(e) => {
|
||||
info!("Failed after all the evaluations passed");
|
||||
if self
|
||||
.handle_strategy_err(Err(e), &gists, &mut overall_status)
|
||||
.is_err()
|
||||
{
|
||||
return self.actions().skip(&job);
|
||||
}
|
||||
}
|
||||
}
|
||||
let complete = evaluation_strategy
|
||||
.all_evaluations_passed(&Path::new(&refpath), &mut overall_status)?;
|
||||
|
||||
send_check_statuses(complete.checks, &repo);
|
||||
response.extend(schedule_builds(complete.builds, auto_schedule_build_archs));
|
||||
|
||||
info!("Just about done...");
|
||||
|
||||
|
@ -330,7 +289,7 @@ impl<E: stats::SysEvents> EvaluationWorker<E> {
|
|||
self.events.notify(Event::TaskEvaluationCheckComplete);
|
||||
|
||||
info!("done!");
|
||||
self.actions().done(&job, response)
|
||||
Ok(self.actions().done(&job, response))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -491,3 +450,13 @@ fn indicates_wip(text: &str) -> bool {
|
|||
|
||||
false
|
||||
}
|
||||
|
||||
enum EvalWorkerError {
|
||||
EvalError(eval::Error),
|
||||
}
|
||||
|
||||
impl From<eval::Error> for EvalWorkerError {
|
||||
fn from(e: eval::Error) -> EvalWorkerError {
|
||||
EvalWorkerError::EvalError(e)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue