Skip to content

Commit

Permalink
Basic support for cloning public projects (#10)
Browse files Browse the repository at this point in the history
- Clone a project given its id, namespace/slug or full url
- Write a `.renku/config.toml` file containing the identifying information
  • Loading branch information
eikek authored Jul 19, 2024
1 parent 3b355e8 commit e7badcc
Show file tree
Hide file tree
Showing 25 changed files with 960 additions and 79 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @SwissDataScienceCenter/renku-python-maintainers @SwissDataScienceCenter/renku-graph-maintainers
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ jobs:
command: run
args: --release --features user-doc -- user-doc ./docs

# check installer on main only, as we reach the github api limit too
# quickly
check-installer:
name: "check installer"
runs-on: ${{ matrix.os }}
if: github.ref == 'refs/heads/main'
strategy:
matrix:
os: [macos-latest, ubuntu-latest]
Expand Down
155 changes: 153 additions & 2 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ snafu = { version = "0.8.4" }
tokio = { version = "1", features = ["full"] }
futures = { version = "0.3" }
regex = { version = "1.10.5" }
iso8601-timestamp = { version = "0.2.17" }
toml = { version = "0.8.12" }
git2 = "0.19.0"
url = { version = "2.5.1" }
comrak = { version = "0.24.1", optional = true }

[features]
Expand Down
4 changes: 3 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@

# Additional dev-shell environment variables can be set directly
# MY_CUSTOM_DEVELOPMENT_VAR = "something else";
RENKU_CLI_RENKU_URL = "https://ci-renku-3668.dev.renku.ch";
RENKU_CLI_RENKU_URL = "https://ci-renku-3689.dev.renku.ch";

# Enable mold https://github.com/rui314/mold
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER = "${pkgs.clang}/bin/clang";
Expand All @@ -186,6 +186,8 @@
# Extra inputs can be added here; cargo and rustc are provided by default.
packages = with pkgs; [
cargo-edit
cargo-expand
tokio-console
fenixToolChain.rust-analyzer
fenixToolChain.rustfmt
];
Expand Down
9 changes: 7 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod cmd;
pub mod opts;
pub mod sink;

use self::cmd::project::Error as ProjectError;
use self::cmd::{CmdError, Context};
use self::opts::{MainOpts, SubCommand};
use clap::CommandFactory;
Expand All @@ -18,10 +19,14 @@ pub async fn execute_cmd(opts: MainOpts) -> Result<(), CmdError> {
let mut app = MainOpts::command();
input.print_completions(&mut app).await;
}
SubCommand::Project(input) => input.exec(&ctx).await?,
SubCommand::Project(input) => input.exec(ctx).await?,
SubCommand::Clone(input) => input
.exec(ctx)
.await
.map_err(|source| ProjectError::Clone { source })?,

#[cfg(feature = "user-doc")]
SubCommand::UserDoc(input) => input.exec(&ctx).await?,
SubCommand::UserDoc(input) => input.exec(ctx).await?,
};
Ok(())
}
Expand Down
43 changes: 28 additions & 15 deletions src/cli/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,64 @@ pub mod version;

use super::sink::{Error as SinkError, Sink};
use crate::cli::opts::{CommonOpts, ProxySetting};
use crate::data::renku_url::RenkuUrl;
use crate::httpclient::{self, proxy, Client};
use serde::Serialize;
use snafu::{ResultExt, Snafu};

const RENKULAB_IO: &str = "https://renkulab.io";

pub struct Context<'a> {
pub opts: &'a CommonOpts,
pub struct Context {
pub opts: CommonOpts,
pub client: Client,
pub renku_url: String,
}

impl Context<'_> {
impl Context {
pub fn new(opts: &CommonOpts) -> Result<Context, CmdError> {
let base_url = get_renku_url(opts);
let client = Client::new(&base_url, proxy_settings(opts), &None, false)
.context(ContextCreateSnafu)?;
let base_url = get_renku_url(opts)?;
let client =
Client::new(base_url, proxy_settings(opts), None, false).context(ContextCreateSnafu)?;
Ok(Context {
opts,
opts: opts.clone(),
client,
renku_url: base_url,
})
}

/// A short hand for `Sink::write(self.format(), value)`
pub fn renku_url(&self) -> &RenkuUrl {
self.client.base_url()
}

/// A short hand for `Sink::write_out(self.format(), value)`
async fn write_result<A: Sink + Serialize>(&self, value: &A) -> Result<(), SinkError> {
let fmt = self.opts.format;
Sink::write(&fmt, value)
Sink::write_out(&fmt, value)
}

/// A short hand for `Sink::write_err(self.format(), value)`
async fn write_err<A: Sink + Serialize>(&self, value: &A) -> Result<(), SinkError> {
let fmt = self.opts.format;
Sink::write_err(&fmt, value)
}
}

fn get_renku_url(opts: &CommonOpts) -> String {
fn get_renku_url(opts: &CommonOpts) -> Result<RenkuUrl, CmdError> {
match &opts.renku_url {
Some(u) => {
log::debug!("Use renku url from arguments: {}", u);
u.clone()
Ok(u.clone())
}
None => match std::env::var("RENKU_CLI_RENKU_URL").ok() {
Some(u) => {
log::debug!("Use renku url from env RENKU_CLI_RENKU_URL: {}", u);
u
RenkuUrl::parse(&u).map_err(|e| CmdError::ContextCreate {
source: httpclient::Error::UrlParse { source: e },
})
}
None => {
log::debug!("Use renku url: https://renkulab.io");
RENKULAB_IO.to_string()
RenkuUrl::parse(RENKULAB_IO).map_err(|e| CmdError::ContextCreate {
source: httpclient::Error::UrlParse { source: e },
})
}
},
}
Expand Down
Loading

0 comments on commit e7badcc

Please sign in to comment.