fix env
This commit is contained in:
parent
0a677f2545
commit
bb69549dc8
2 changed files with 19 additions and 6 deletions
|
@ -1,5 +1,4 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::env;
|
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
@ -14,6 +13,8 @@ use sha1::Sha1;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
use toml::Value as TomlValue;
|
use toml::Value as TomlValue;
|
||||||
|
|
||||||
|
use handler::Environment;
|
||||||
|
|
||||||
#[derive(StructOpt)]
|
#[derive(StructOpt)]
|
||||||
struct Opt {
|
struct Opt {
|
||||||
/// JSON input
|
/// JSON input
|
||||||
|
@ -50,7 +51,11 @@ fn default_path() -> PathBuf {
|
||||||
PathBuf::from(".")
|
PathBuf::from(".")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main(config: &TomlValue, input: &JsonValue) -> Result<JsonValue, Error> {
|
pub(crate) fn main(
|
||||||
|
env: &Environment,
|
||||||
|
config: &TomlValue,
|
||||||
|
input: &JsonValue,
|
||||||
|
) -> Result<JsonValue, Error> {
|
||||||
let config_str = {
|
let config_str = {
|
||||||
let mut buf: Vec<u8> = Vec::new();
|
let mut buf: Vec<u8> = Vec::new();
|
||||||
{
|
{
|
||||||
|
@ -94,8 +99,7 @@ pub fn main(config: &TomlValue, input: &JsonValue) -> Result<JsonValue, Error> {
|
||||||
|
|
||||||
let payload: GithubPayload =
|
let payload: GithubPayload =
|
||||||
serde_json::from_str(&payload.body).expect("Could not parse Github input into json");
|
serde_json::from_str(&payload.body).expect("Could not parse Github input into json");
|
||||||
let mut target_path =
|
let mut target_path = env.workdir.clone();
|
||||||
PathBuf::from(env::var("DIP_WORKDIR").expect("Could not determine working directory"));
|
|
||||||
target_path.push(&config.path);
|
target_path.push(&config.path);
|
||||||
Command::new("git")
|
Command::new("git")
|
||||||
.arg("clone")
|
.arg("clone")
|
||||||
|
|
|
@ -26,13 +26,20 @@ pub struct Handler {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum Action {
|
pub enum Action {
|
||||||
/// A builtin function (for example, the Github handler).
|
/// A builtin function (for example, the Github handler).
|
||||||
Builtin(fn(&TomlValue, &JsonValue) -> Result<JsonValue, Error>),
|
Builtin(fn(&Environment, &TomlValue, &JsonValue) -> Result<JsonValue, Error>),
|
||||||
/// A command represents a string to be executed by `bash -c`.
|
/// A command represents a string to be executed by `bash -c`.
|
||||||
Command(String),
|
Command(String),
|
||||||
/// A program represents one of the handlers specified in the `handlers` directory.
|
/// A program represents one of the handlers specified in the `handlers` directory.
|
||||||
Program(String),
|
Program(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Describes the environment for running a builtin.
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct Environment {
|
||||||
|
/// The current working directory.
|
||||||
|
pub workdir: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Action {
|
impl fmt::Debug for Action {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match &self {
|
match &self {
|
||||||
|
@ -94,7 +101,9 @@ impl Handler {
|
||||||
|
|
||||||
let output: Box<Future<Item = JsonValue, Error = Error> + Send> = match action {
|
let output: Box<Future<Item = JsonValue, Error = Error> + Send> = match action {
|
||||||
Action::Builtin(ref func) => {
|
Action::Builtin(ref func) => {
|
||||||
let result = func(&config, &input);
|
let workdir = temp_path_cp.clone();
|
||||||
|
let env = Environment { workdir };
|
||||||
|
let result = func(&env, &config, &input);
|
||||||
Box::new(future::result(result))
|
Box::new(future::result(result))
|
||||||
}
|
}
|
||||||
Action::Command(ref cmd) => {
|
Action::Command(ref cmd) => {
|
||||||
|
|
Loading…
Reference in a new issue