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::env;
|
||||
use std::iter::FromIterator;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
@ -14,6 +13,8 @@ use sha1::Sha1;
|
|||
use structopt::StructOpt;
|
||||
use toml::Value as TomlValue;
|
||||
|
||||
use handler::Environment;
|
||||
|
||||
#[derive(StructOpt)]
|
||||
struct Opt {
|
||||
/// JSON input
|
||||
|
@ -50,7 +51,11 @@ fn default_path() -> PathBuf {
|
|||
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 mut buf: Vec<u8> = Vec::new();
|
||||
{
|
||||
|
@ -94,8 +99,7 @@ pub fn main(config: &TomlValue, input: &JsonValue) -> Result<JsonValue, Error> {
|
|||
|
||||
let payload: GithubPayload =
|
||||
serde_json::from_str(&payload.body).expect("Could not parse Github input into json");
|
||||
let mut target_path =
|
||||
PathBuf::from(env::var("DIP_WORKDIR").expect("Could not determine working directory"));
|
||||
let mut target_path = env.workdir.clone();
|
||||
target_path.push(&config.path);
|
||||
Command::new("git")
|
||||
.arg("clone")
|
||||
|
|
|
@ -26,13 +26,20 @@ pub struct Handler {
|
|||
#[derive(Clone)]
|
||||
pub enum Action {
|
||||
/// 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`.
|
||||
Command(String),
|
||||
/// A program represents one of the handlers specified in the `handlers` directory.
|
||||
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 {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match &self {
|
||||
|
@ -94,7 +101,9 @@ impl Handler {
|
|||
|
||||
let output: Box<Future<Item = JsonValue, Error = Error> + Send> = match action {
|
||||
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))
|
||||
}
|
||||
Action::Command(ref cmd) => {
|
||||
|
|
Loading…
Reference in a new issue