Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split josh-graphql and josh-templates out of josh-core #1339

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
!josh-proxy
!josh-rpc
!josh-ssh-shell
!josh-templates
!josh-graphql
!josh-ui/*.json
!josh-ui/*.rs
!josh-ui/*.toml
Expand Down
41 changes: 35 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ members = [
"hyper_cgi",
"josh-core",
"josh-filter",
"josh-graphql",
"josh-proxy",
"josh-rpc",
"josh-ssh-shell",
"josh-templates",
"josh-ui",
]

Expand Down
10 changes: 0 additions & 10 deletions josh-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ bitvec = "1.0.1"
git-version = "0.3.9"
git2 = { workspace = true }
glob = "0.3.1"
handlebars = "5.1.2"
hex = "0.4.3"
indoc = "2.0.5"
itertools = "0.13.0"
Expand All @@ -31,13 +30,4 @@ serde = { workspace = true }
serde_json = { workspace = true }
serde_yaml = { workspace = true }
sled = "0.34.7"
strfmt = "0.2.4"
toml = { workspace = true }
tracing = { workspace = true }
juniper = { workspace = true }
form_urlencoded = "1.2.1"

[dependencies.chrono]
default-features = false
features = ["alloc", "std"]
version = "0.4.38"
2 changes: 1 addition & 1 deletion josh-core/src/filter/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,6 @@ pub fn get_comments(filter_spec: &str) -> JoshResult<String> {
)));
}

#[derive(Parser)]
#[derive(pest_derive::Parser)]
#[grammar = "filter/grammar.pest"]
struct Grammar;
17 changes: 3 additions & 14 deletions josh-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,10 @@ macro_rules! ok_or {
#[macro_use]
extern crate rs_tracing;

#[macro_use]
extern crate handlebars;

#[macro_use]
extern crate pest_derive;

#[macro_use]
extern crate serde_json;

pub mod cache;
pub mod filter;
pub mod graphql;
pub mod history;
pub mod housekeeping;
pub mod query;
pub mod shell;

pub struct Change {
Expand Down Expand Up @@ -190,7 +179,7 @@ macro_rules! regex_parsed {
impl $name {
fn from_str(path: &str) -> Option<$name> {

lazy_static! {
lazy_static::lazy_static! {
static ref REGEX: regex::Regex =
regex::Regex::new($re)
.expect("can't compile regex");
Expand Down Expand Up @@ -368,7 +357,7 @@ type Users = std::collections::HashMap<String, User>;

#[derive(Debug, serde::Deserialize)]
struct User {
pub groups: toml::value::Array,
pub groups: Vec<String>,
}

type Groups = std::collections::HashMap<String, std::collections::HashMap<String, Group>>;
Expand Down Expand Up @@ -400,7 +389,7 @@ pub fn get_acl(
let mut blacklist = filter::empty();
for g in &u.groups {
let lists = groups.get(repo).and_then(|repo| {
repo.get(g.as_str()?).map(|group| {
repo.get(g.as_str()).map(|group| {
let w = filter::parse(&group.whitelist);
let b = filter::parse(&group.blacklist);
(w, b)
Expand Down
2 changes: 2 additions & 0 deletions josh-filter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ version = "22.4.15"

[dependencies]
josh = { path = "../josh-core" }
josh-graphql = { path = "../josh-graphql" }
josh-templates = { path = "../josh-templates" }
env_logger = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
Expand Down
6 changes: 3 additions & 3 deletions josh-filter/src/bin/josh-filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,12 @@ fn run_filter(args: Vec<String>) -> josh::JoshResult<i32> {
}

if let Some(gql_query) = args.get_one::<String>("graphql") {
let context = josh::graphql::context(transaction.try_clone()?, transaction.try_clone()?);
let context = josh_graphql::context(transaction.try_clone()?, transaction.try_clone()?);
*context.allow_refs.lock()? = true;
let (res, _errors) = juniper::execute_sync(
gql_query,
None,
&josh::graphql::repo_schema(".".to_string(), true),
&josh_graphql::repo_schema(".".to_string(), true),
&std::collections::HashMap::new(),
&context,
)?;
Expand All @@ -420,7 +420,7 @@ fn run_filter(args: Vec<String>) -> josh::JoshResult<i32> {
let commit_id = transaction.repo().refname_to_id(update_target)?;
print!(
"{}",
josh::query::render(&transaction, "", commit_id, query, false)?
josh_templates::render(&transaction, "", commit_id, query, false)?
.map(|x| x.0)
.unwrap_or("File not found".to_string())
);
Expand Down
22 changes: 22 additions & 0 deletions josh-graphql/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "josh-graphql"
version = "0.1.0"
edition = "2021"

[dependencies]
josh = { path = "../josh-core" }
juniper = { workspace = true }
git2 = { workspace = true }
rs_tracing = { workspace = true }
regex = { workspace = true }
serde_json = { workspace = true }
serde_yaml = { workspace = true }
strfmt = "0.2.4"
toml = { workspace = true }
tracing = { workspace = true }
lazy_static = { workspace = true }

[dependencies.chrono]
default-features = false
features = ["alloc", "std"]
version = "0.4.38"
15 changes: 6 additions & 9 deletions josh-core/src/graphql.rs → josh-graphql/src/graphql.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(unused_variables)]

use super::*;
use josh::{cache, filter, history, josh_error, JoshResult};
use juniper::{graphql_object, EmptyMutation, EmptySubscription, FieldResult};

pub struct Revision {
Expand Down Expand Up @@ -674,7 +674,7 @@ impl Path {

fn dir(&self, relative: String) -> FieldResult<Path> {
Ok(Path {
path: normalize_path(&self.path.join(relative)),
path: josh::normalize_path(&self.path.join(relative)),
commit_id: self.commit_id,
filter: self.filter,
tree: self.tree,
Expand Down Expand Up @@ -955,10 +955,7 @@ impl RepositoryMut {
filter::nop()
};

Ok(RevMut {
at: at,
filter: filter,
})
Ok(RevMut { at, filter })
}
}

Expand All @@ -983,7 +980,7 @@ impl Repository {
pattern.unwrap_or_else(|| "refs/heads/*".to_string())
);

log::debug!("refname: {:?}", refname);
tracing::debug!(refname = refname, "refs");

let mut refs = vec![];

Expand Down Expand Up @@ -1029,7 +1026,7 @@ impl Repository {
}
}

regex_parsed!(
josh::regex_parsed!(
UpstreamRef,
r"refs/josh/upstream/.*[.]git/(?P<reference>refs/heads/.*)",
[reference]
Expand Down Expand Up @@ -1066,7 +1063,7 @@ pub fn repo_schema(name: String, local: bool) -> RepoSchema {
let ns = if local {
"".to_string()
} else {
format!("refs/josh/upstream/{}.git/", to_ns(&name))
format!("refs/josh/upstream/{}.git/", josh::to_ns(&name))
};
RepoSchema::new(
Repository { name, ns },
Expand Down
5 changes: 5 additions & 0 deletions josh-graphql/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub mod graphql;
pub use graphql::{commit_schema, context, repo_schema};

#[macro_use]
extern crate rs_tracing;
2 changes: 2 additions & 0 deletions josh-proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ hyper-tls = "0.5.0"
hyper_cgi = { path = "../hyper_cgi" }
indoc = "2.0.5"
josh = {path = "../josh-core" }
josh-templates = { path = "../josh-templates" }
josh-graphql = { path = "../josh-graphql" }
lazy_static = { workspace = true }
opentelemetry = "0.23.0"
opentelemetry-jaeger = "0.22.0"
Expand Down
6 changes: 3 additions & 3 deletions josh-proxy/src/bin/josh-proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,7 @@ async fn serve_query(
let commit_id =
josh::filter_commit(&transaction, filter, commit_id, josh::filter::empty())?;

josh::query::render(&transaction, "", commit_id, &q, true)
josh_templates::render(&transaction, "", commit_id, &q, true)
})
.in_current_span()
.await?;
Expand Down Expand Up @@ -1807,15 +1807,15 @@ async fn serve_graphql(
.to_string(),
)?;

Ok(Arc::new(josh::graphql::context(
Ok(Arc::new(josh_graphql::graphql::context(
transaction,
transaction_mirror,
)))
})
.await??
};

let root_node = Arc::new(josh::graphql::repo_schema(
let root_node = Arc::new(josh_graphql::graphql::repo_schema(
upstream_repo
.strip_suffix(".git")
.unwrap_or(&upstream_repo)
Expand Down
13 changes: 13 additions & 0 deletions josh-templates/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "josh-templates"
version = "0.1.0"
edition = "2021"

[dependencies]
git2 = { workspace = true }
josh = { path = "../josh-core" }
josh-graphql = { path = "../josh-graphql" }
juniper = { workspace = true }
serde_json = { workspace = true }
handlebars = "5.1.2"
form_urlencoded = "1.2.1"
2 changes: 2 additions & 0 deletions josh-templates/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod templates;
pub use templates::render;
Loading
Loading