Merge pull request #487 from LnL7/lapin-comment-poster
lapin github-comment-poster
This commit is contained in:
commit
6329c1ac15
|
@ -1,75 +1,66 @@
|
||||||
use ofborg::config;
|
|
||||||
use ofborg::easyamqp::{self, ChannelExt, ConsumerExt};
|
|
||||||
use ofborg::tasks;
|
|
||||||
use ofborg::worker;
|
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use std::error::Error;
|
||||||
|
|
||||||
use amqp::Basic;
|
use async_std::task;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
fn main() {
|
use ofborg::config;
|
||||||
let cfg = config::load(env::args().nth(1).unwrap().as_ref());
|
use ofborg::easyamqp::{self, ChannelExt, ConsumerExt};
|
||||||
|
use ofborg::easylapin;
|
||||||
|
use ofborg::tasks;
|
||||||
|
|
||||||
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
ofborg::setup_log();
|
ofborg::setup_log();
|
||||||
|
|
||||||
let mut session = easyamqp::session_from_config(&cfg.rabbitmq).unwrap();
|
let arg = env::args()
|
||||||
let mut channel = session.open_channel(1).unwrap();
|
.nth(1)
|
||||||
|
.expect("usage: github-comment-poster <config>");
|
||||||
|
let cfg = config::load(arg.as_ref());
|
||||||
|
|
||||||
channel
|
let conn = easylapin::from_config(&cfg.rabbitmq)?;
|
||||||
.declare_exchange(easyamqp::ExchangeConfig {
|
let mut chan = task::block_on(conn.create_channel())?;
|
||||||
exchange: "build-results".to_owned(),
|
|
||||||
exchange_type: easyamqp::ExchangeType::Fanout,
|
|
||||||
passive: false,
|
|
||||||
durable: true,
|
|
||||||
auto_delete: false,
|
|
||||||
no_wait: false,
|
|
||||||
internal: false,
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
channel
|
chan.declare_exchange(easyamqp::ExchangeConfig {
|
||||||
.declare_queue(easyamqp::QueueConfig {
|
exchange: "build-results".to_owned(),
|
||||||
|
exchange_type: easyamqp::ExchangeType::Fanout,
|
||||||
|
passive: false,
|
||||||
|
durable: true,
|
||||||
|
auto_delete: false,
|
||||||
|
no_wait: false,
|
||||||
|
internal: false,
|
||||||
|
})?;
|
||||||
|
|
||||||
|
chan.declare_queue(easyamqp::QueueConfig {
|
||||||
|
queue: "build-results".to_owned(),
|
||||||
|
passive: false,
|
||||||
|
durable: true,
|
||||||
|
exclusive: false,
|
||||||
|
auto_delete: false,
|
||||||
|
no_wait: false,
|
||||||
|
})?;
|
||||||
|
|
||||||
|
chan.bind_queue(easyamqp::BindQueueConfig {
|
||||||
|
queue: "build-results".to_owned(),
|
||||||
|
exchange: "build-results".to_owned(),
|
||||||
|
routing_key: None,
|
||||||
|
no_wait: false,
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let handle = chan.consume(
|
||||||
|
tasks::githubcommentposter::GitHubCommentPoster::new(cfg.github_app_vendingmachine()),
|
||||||
|
easyamqp::ConsumeConfig {
|
||||||
queue: "build-results".to_owned(),
|
queue: "build-results".to_owned(),
|
||||||
passive: false,
|
consumer_tag: format!("{}-github-comment-poster", cfg.whoami()),
|
||||||
durable: true,
|
no_local: false,
|
||||||
|
no_ack: false,
|
||||||
|
no_wait: false,
|
||||||
exclusive: false,
|
exclusive: false,
|
||||||
auto_delete: false,
|
},
|
||||||
no_wait: false,
|
)?;
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
channel
|
task::block_on(handle);
|
||||||
.bind_queue(easyamqp::BindQueueConfig {
|
|
||||||
queue: "build-results".to_owned(),
|
|
||||||
exchange: "build-results".to_owned(),
|
|
||||||
routing_key: None,
|
|
||||||
no_wait: false,
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
channel.basic_prefetch(1).unwrap();
|
drop(conn); // Close connection.
|
||||||
let mut channel = channel
|
|
||||||
.consume(
|
|
||||||
worker::new(tasks::githubcommentposter::GitHubCommentPoster::new(
|
|
||||||
cfg.github_app_vendingmachine(),
|
|
||||||
)),
|
|
||||||
easyamqp::ConsumeConfig {
|
|
||||||
queue: "build-results".to_owned(),
|
|
||||||
consumer_tag: format!("{}-github-comment-poster", cfg.whoami()),
|
|
||||||
no_local: false,
|
|
||||||
no_ack: false,
|
|
||||||
no_wait: false,
|
|
||||||
exclusive: false,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
channel.start_consuming();
|
|
||||||
|
|
||||||
info!("Finished consuming?");
|
|
||||||
|
|
||||||
channel.close(200, "Bye").unwrap();
|
|
||||||
info!("Closed the channel");
|
|
||||||
session.close(200, "Good Bye");
|
|
||||||
info!("Closed the session... EOF");
|
info!("Closed the session... EOF");
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,6 +133,13 @@ impl BuildResult {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn pr(&self) -> Pr {
|
||||||
|
match self {
|
||||||
|
BuildResult::Legacy { pr, .. } => pr.to_owned(),
|
||||||
|
BuildResult::V1 { pr, .. } => pr.to_owned(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn status(&self) -> BuildStatus {
|
pub fn status(&self) -> BuildStatus {
|
||||||
match *self {
|
match *self {
|
||||||
BuildResult::Legacy {
|
BuildResult::Legacy {
|
||||||
|
|
|
@ -6,7 +6,7 @@ use crate::worker;
|
||||||
|
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use hubcaps::checks::{CheckRunOptions, CheckRunState, Conclusion, Output};
|
use hubcaps::checks::{CheckRunOptions, CheckRunState, Conclusion, Output};
|
||||||
use tracing::info;
|
use tracing::{debug, debug_span, info};
|
||||||
|
|
||||||
pub struct GitHubCommentPoster {
|
pub struct GitHubCommentPoster {
|
||||||
github_vend: GithubAppVendingMachine,
|
github_vend: GithubAppVendingMachine,
|
||||||
|
@ -50,22 +50,33 @@ impl worker::SimpleWorker for GitHubCommentPoster {
|
||||||
let mut checks: Vec<CheckRunOptions> = vec![];
|
let mut checks: Vec<CheckRunOptions> = vec![];
|
||||||
let repo: Repo;
|
let repo: Repo;
|
||||||
|
|
||||||
match job {
|
let pr = match job {
|
||||||
PostableEvent::BuildQueued(queued_job) => {
|
PostableEvent::BuildQueued(queued_job) => {
|
||||||
repo = queued_job.job.repo.clone();
|
repo = queued_job.job.repo.clone();
|
||||||
for architecture in queued_job.architectures.iter() {
|
for architecture in queued_job.architectures.iter() {
|
||||||
checks.push(job_to_check(&queued_job.job, &architecture, Utc::now()));
|
checks.push(job_to_check(&queued_job.job, &architecture, Utc::now()));
|
||||||
}
|
}
|
||||||
|
queued_job.job.pr.to_owned()
|
||||||
}
|
}
|
||||||
PostableEvent::BuildFinished(finished_job) => {
|
PostableEvent::BuildFinished(finished_job) => {
|
||||||
let result = finished_job.legacy();
|
let result = finished_job.legacy();
|
||||||
repo = result.repo.clone();
|
repo = result.repo.clone();
|
||||||
checks.push(result_to_check(&result, Utc::now()));
|
checks.push(result_to_check(&result, Utc::now()));
|
||||||
|
finished_job.pr()
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
let span = debug_span!("job", pr = ?pr.number);
|
||||||
|
let _enter = span.enter();
|
||||||
|
|
||||||
for check in checks {
|
for check in checks {
|
||||||
info!(":{:?}", check);
|
info!(
|
||||||
|
"check {:?} {} {}",
|
||||||
|
check.status,
|
||||||
|
check.name,
|
||||||
|
check.details_url.as_ref().unwrap_or(&String::from("-"))
|
||||||
|
);
|
||||||
|
debug!("{:?}", check);
|
||||||
|
|
||||||
let check_create_attempt = self
|
let check_create_attempt = self
|
||||||
.github_vend
|
.github_vend
|
||||||
|
|
Loading…
Reference in a new issue