forked from the-distro/ofborg
rust hackin'
This commit is contained in:
parent
05ca7f9ce7
commit
cb899fd322
|
@ -7,35 +7,16 @@ use amqp::protocol;
|
|||
use amqp::Session;
|
||||
use amqp::Table;
|
||||
use std::process;
|
||||
use std::io::Error;
|
||||
|
||||
use ofborg::checkout;
|
||||
use ofborg::worker;
|
||||
use ofborg::worker::{Actions,StdPr,StdRepo,BuildJob};
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
|
||||
|
||||
let cloner = checkout::cached_cloner(Path::new("/home/grahamc/.nix-test-rs"));
|
||||
let project = cloner.project("NixOS/nixpkgs".to_string(),
|
||||
"https://github.com/nixos/nixpkgs.git".to_string()
|
||||
);
|
||||
let co = project.clone_for("builder".to_string(),
|
||||
"1234".to_string()).unwrap();
|
||||
|
||||
let refpath = co.checkout_ref("origin/master".as_ref());
|
||||
co.fetch_pr(31228).unwrap();
|
||||
co.merge_commit("7214d0f6f7a6467205761f87973140727154e1b3".as_ref()).unwrap();
|
||||
|
||||
match refpath {
|
||||
Ok(path) => {
|
||||
println!("Got path: {:?}", path);
|
||||
}
|
||||
Err(wat) => {
|
||||
println!("Failed to do a checkout of ref : {:?}", wat);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if false {
|
||||
let mut session = Session::open_url("amqps://grahamc:cCbKQmwnRcd8kvPW9cjmMSkp@events.nix.gsc.io//").unwrap();
|
||||
let mut channel = session.open_channel(1).unwrap();
|
||||
|
@ -46,6 +27,21 @@ fn main() {
|
|||
process::exit(1);
|
||||
}
|
||||
|
||||
let cloner = checkout::cached_cloner(Path::new("/home/grahamc/.nix-test-rs"));
|
||||
|
||||
channel.basic_consume(
|
||||
worker::new(BuildWorker{
|
||||
cloner: cloner
|
||||
}),
|
||||
"my_queue_name",
|
||||
"lmao1",
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
Table::new()
|
||||
);
|
||||
|
||||
if let Err(result) = channel.basic_publish("", "my_queue_name", true, false,
|
||||
protocol::basic::BasicProperties{ content_type: Some("text".to_string()), ..Default::default()}, (b"Hello from rust!").to_vec()) {
|
||||
println!("Failed to publish: {:?}", result);
|
||||
|
@ -53,3 +49,30 @@ fn main() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct BuildWorker {
|
||||
cloner: checkout::CachedCloner,
|
||||
}
|
||||
|
||||
impl worker::SimpleWorker for BuildWorker {
|
||||
fn consumer(&self, job: BuildJob, resp: Actions) -> Result<(), Error> {
|
||||
let project = self.cloner.project(job.repo.full_name, job.repo.clone_url);
|
||||
let co = project.clone_for("builder".to_string(),
|
||||
job.pr.number.to_string())?;
|
||||
|
||||
let refpath = co.checkout_ref(job.pr.target_branch.as_ref());
|
||||
co.fetch_pr(job.pr.number).unwrap();
|
||||
co.merge_commit(job.pr.head_sha.as_ref()).unwrap();
|
||||
|
||||
match refpath {
|
||||
Ok(path) => {
|
||||
println!("Got path: {:?}", path);
|
||||
}
|
||||
Err(wat) => {
|
||||
println!("Failed to do a checkout of ref : {:?}", wat);
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
extern crate amqp;
|
||||
extern crate fs2;
|
||||
extern crate md5;
|
||||
|
||||
pub mod checkout;
|
||||
pub mod locks;
|
||||
pub mod clone;
|
||||
pub mod worker;
|
||||
|
||||
pub mod ofborg {
|
||||
pub use checkout;
|
||||
pub use locks;
|
||||
pub use clone;
|
||||
pub use worker;
|
||||
}
|
||||
|
|
49
ofborg/src/worker.rs
Normal file
49
ofborg/src/worker.rs
Normal file
|
@ -0,0 +1,49 @@
|
|||
|
||||
use amqp::{Consumer, Channel};
|
||||
use amqp::protocol::basic::{Deliver,BasicProperties};
|
||||
use std::marker::Send;
|
||||
use std::io::Error;
|
||||
|
||||
pub struct Worker<T: SimpleWorker> {
|
||||
internal: T
|
||||
}
|
||||
|
||||
pub struct StdRepo {
|
||||
pub full_name: String,
|
||||
pub clone_url: String,
|
||||
}
|
||||
|
||||
pub struct StdPr {
|
||||
pub target_branch: String,
|
||||
pub number: i64,
|
||||
pub head_sha: String,
|
||||
}
|
||||
|
||||
|
||||
pub struct BuildJob {
|
||||
pub repo: StdRepo,
|
||||
pub pr: StdPr,
|
||||
}
|
||||
|
||||
|
||||
pub struct Actions {
|
||||
}
|
||||
|
||||
pub trait SimpleWorker {
|
||||
fn consumer(&self, job: BuildJob, resp: Actions) -> Result<(), Error>;
|
||||
}
|
||||
|
||||
pub fn new<T: SimpleWorker>(worker: T) -> Worker<T> {
|
||||
return Worker{
|
||||
internal: worker,
|
||||
};
|
||||
}
|
||||
|
||||
impl <T: SimpleWorker + Send> Consumer for Worker<T> {
|
||||
fn handle_delivery(&mut self,
|
||||
channel: &mut Channel,
|
||||
method: Deliver,
|
||||
headers: BasicProperties,
|
||||
body: Vec<u8>) {
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue