feat(tasks/evaluation-filter): consume from VCSEvents
Simplified to the maximum, it consumes from VCSEvents in the case of creation & update. It does not handle cancellation yet. Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
This commit is contained in:
parent
6a628c3cdd
commit
bb08c8cb97
1 changed files with 13 additions and 59 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::acl;
|
||||
use crate::ghevent;
|
||||
use crate::message::{evaluationjob, Change, Repo};
|
||||
use crate::message::evaluationjob;
|
||||
use crate::message::vcs::VCSEvent;
|
||||
use crate::worker;
|
||||
|
||||
use async_trait::async_trait;
|
||||
|
@ -19,7 +19,7 @@ impl EvaluationFilterWorker {
|
|||
|
||||
#[async_trait]
|
||||
impl worker::SimpleWorker for EvaluationFilterWorker {
|
||||
type J = ghevent::PullRequestEvent;
|
||||
type J = VCSEvent;
|
||||
|
||||
async fn msg_to_job(
|
||||
&mut self,
|
||||
|
@ -37,70 +37,24 @@ impl worker::SimpleWorker for EvaluationFilterWorker {
|
|||
}
|
||||
}
|
||||
|
||||
async fn consumer(
|
||||
&mut self,
|
||||
_chan: &mut lapin::Channel,
|
||||
job: &ghevent::PullRequestEvent,
|
||||
) -> worker::Actions {
|
||||
let span = debug_span!("job", pr = ?job.number);
|
||||
async fn consumer(&mut self, _chan: &mut lapin::Channel, job: &VCSEvent) -> worker::Actions {
|
||||
let span = debug_span!("event", event = ?job);
|
||||
let _enter = span.enter();
|
||||
|
||||
if !self.acl.is_repo_eligible(&job.repository.full_name) {
|
||||
info!("Repo not authorized ({})", job.repository.full_name);
|
||||
return vec![worker::Action::Ack];
|
||||
}
|
||||
|
||||
if job.pull_request.state != ghevent::PullRequestState::Open {
|
||||
info!(
|
||||
"PR is not open ({}#{})",
|
||||
job.repository.full_name, job.number
|
||||
);
|
||||
return vec![worker::Action::Ack];
|
||||
}
|
||||
|
||||
let interesting: bool = match job.action {
|
||||
ghevent::PullRequestAction::Opened
|
||||
| ghevent::PullRequestAction::Synchronize
|
||||
| ghevent::PullRequestAction::Reopened => true,
|
||||
ghevent::PullRequestAction::Edited => {
|
||||
if let Some(ref changes) = job.changes {
|
||||
changes.base.is_some()
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
ghevent::PullRequestAction::Unknown => false,
|
||||
let (change, repo) = match job {
|
||||
VCSEvent::ChangeCreated { change, repo } => (change, repo),
|
||||
VCSEvent::ChangeUpdated { change, repo } => (change, repo),
|
||||
_ => return vec![worker::Action::Ack],
|
||||
};
|
||||
|
||||
if !interesting {
|
||||
info!(
|
||||
"Not interesting: {}#{} because of {:?}",
|
||||
job.repository.full_name, job.number, job.action
|
||||
);
|
||||
|
||||
if !self.acl.is_repo_eligible(&repo.full_name) {
|
||||
info!("Repo not authorized ({})", &repo.full_name);
|
||||
return vec![worker::Action::Ack];
|
||||
}
|
||||
|
||||
info!(
|
||||
"Found {}#{} to be interesting because of {:?}",
|
||||
job.repository.full_name, job.number, job.action
|
||||
);
|
||||
let repo_msg = Repo {
|
||||
clone_url: job.repository.clone_url.clone(),
|
||||
full_name: job.repository.full_name.clone(),
|
||||
owner: job.repository.owner.login.clone(),
|
||||
name: job.repository.name.clone(),
|
||||
};
|
||||
|
||||
let change_msg = Change {
|
||||
number: job.number,
|
||||
head_sha: job.pull_request.head.sha.clone(),
|
||||
target_branch: Some(job.pull_request.base.git_ref.clone()),
|
||||
};
|
||||
|
||||
let msg = evaluationjob::EvaluationJob {
|
||||
repo: repo_msg,
|
||||
change: change_msg,
|
||||
repo: repo.clone(),
|
||||
change: change.clone(),
|
||||
};
|
||||
|
||||
vec![
|
||||
|
|
Loading…
Reference in a new issue