Prototype fetching just the Jankyfile from GitHub for execution

This commit is contained in:
R Tyler Croy 2023-01-28 19:55:58 -08:00
parent 6c9f7ab491
commit 909dbe587d
No known key found for this signature in database
GPG Key ID: E5C92681BEF6CEA2
3 changed files with 31 additions and 17 deletions

View File

@ -12,7 +12,7 @@ name = "janky-agent"
path = "src/agent/main.rs"
[dependencies]
async-std = { version = "1", features = ["attributes"] }
async-std = { version = "1", features = ["attributes", "tokio1"] }
chrono = "0.4"
dotenv = "~0.15"
driftwood = "0"
@ -21,6 +21,8 @@ gumdrop = "0.8"
handlebars = { version = "3", features = ["dir_source"] }
html-escape = "0.2"
log = "~0.4.8"
# Needed for GitHub API calls
octocrab = "0.18"
os_pipe = "1"
pretty_env_logger = "~0.3"
serde = { version = "1.0", features = ["derive"] }

View File

@ -2,12 +2,12 @@
agents:
- 'http://localhost:9000'
projects:
- type: 'git'
- type: 'github'
url: 'https://github.com/rtyler/janky'
ref: 'main'
filename: 'Jankyfile'
- type: 'git'
url: 'https://github.com/rtyler/jdp'
ref: 'main'
filename: 'ci/Jankyfile'
# The filetype Git is not yet supported
#- type: 'git'
# url: 'https://github.com/rtyler/jdp'
# ref: 'main'
# filename: 'ci/Jankyfile'

View File

@ -63,7 +63,7 @@ impl AppState<'_> {
*/
mod routes {
use crate::AppState;
use log::*;
use tide::{Body, Request};
/**
@ -73,6 +73,18 @@ mod routes {
let params = json!({
"page": "home"
});
let res = octocrab::instance()
.repos("rtyler", "janky")
.raw_file(
octocrab::params::repos::Commitish("main".into()),
"Jankyfile",
)
.await?;
debug!("jank: {:?}", res);
debug!("text: {:?}", res.text().await?);
let mut body = req.state().render("index", &params).await?;
body.set_mime("text/html");
Ok(body)
@ -82,17 +94,17 @@ mod routes {
}
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all="lowercase")]
#[serde(rename_all = "lowercase")]
enum Scm {
Git,
GitHub,
}
#[derive(Clone, Debug, Deserialize)]
struct Project {
#[serde(rename="type")]
#[serde(rename = "type")]
scm_type: Scm,
url: Url,
#[serde(rename="ref")]
#[serde(rename = "ref")]
scm_ref: String,
filename: PathBuf,
}
@ -112,15 +124,15 @@ impl Default for ServerConfig {
}
}
#[derive(Debug,Options)]
#[derive(Debug, Options)]
struct ServerOptions {
#[options(help = "print help message")]
help: bool,
#[options(help="host:port to bind the server to", default="0.0.0.0:8000")]
#[options(help = "host:port to bind the server to", default = "0.0.0.0:8000")]
listen: String,
#[options(help="Path to the configuration file")]
#[options(help = "Path to the configuration file")]
config: Option<PathBuf>,
#[options(help="Comma separated list of URLs for agents")]
#[options(help = "Comma separated list of URLs for agents")]
agents: Vec<Url>,
}
@ -135,7 +147,7 @@ async fn main() -> Result<(), tide::Error> {
Some(path) => {
let config_file = std::fs::File::open(path).expect("Failed to open config file");
serde_yaml::from_reader(config_file).expect("Failed to read config file")
},
}
None => ServerConfig::default(),
};