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

Revert "Auto branch update" #24

Merged
merged 1 commit into from
Jan 29, 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
4 changes: 2 additions & 2 deletions src/cli/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use thiserror::Error;
use super::prompt::{get_option, get_text_input};
use crate::app::config::{AppChainConfig, ConfigVersion, RollupMode};
use crate::da::da_layers::{DAFactory, DALayer};
use crate::utils::constants::{APP_CONFIG_NAME, MADARA_BRANCH_NAME, MADARA_REPO_NAME, MADARA_REPO_ORG};
use crate::utils::constants::{APP_CONFIG_NAME, MADARA_REPO_NAME, MADARA_REPO_ORG};
use crate::utils::errors::GithubError;
use crate::utils::github::get_latest_commit_hash;
use crate::utils::paths::{get_app_chains_home, get_app_home};
Expand Down Expand Up @@ -53,7 +53,7 @@ async fn generate_config() -> Result<AppChainConfig, InitError> {

let mode = get_option("Select mode for your app chain:", RollupMode::iter().collect::<Vec<_>>())?;
let da_layer = get_option("Select DA layer for your app chain:", DALayer::iter().collect::<Vec<_>>())?;
let madara_version = get_latest_commit_hash(MADARA_REPO_ORG, MADARA_REPO_NAME, MADARA_BRANCH_NAME).await?;
let madara_version = get_latest_commit_hash(MADARA_REPO_ORG, MADARA_REPO_NAME).await?;
let config_version = ConfigVersion::Version1;

log::info!("\n");
Expand Down
2 changes: 1 addition & 1 deletion src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async fn start_app_chain() -> Result<(), RunError> {
}
};

madara::clone_madara_and_build_repo(&config)?;
madara::clone_madara_and_build_repo()?;

let da_factory = DAFactory::new_da(&config.da_layer);
da_factory.confirm_minimum_balance(&config)?;
Expand Down
5 changes: 3 additions & 2 deletions src/utils/constants.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
pub const MADARA_REPO_ORG: &str = "keep-starknet-strange";
pub const MADARA_REPO_NAME: &str = "madara";

pub const MADARA_REPO_ORG: &str = "karnotxyz";
pub const KARNOT_REPO_ORG: &str = "karnotxyz";

pub const MADARA_BRANCH_NAME: &str = "cli_branch";
pub const BRANCH_NAME: &str = "custom_events_page";

pub const APP_CONFIG_NAME: &str = "config.toml";
pub const APP_DA_CONFIG_NAME: &str = "da-config.json";
Expand Down
31 changes: 9 additions & 22 deletions src/utils/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@ struct Commit {
sha: String,
}

pub async fn get_latest_commit_hash(org: &str, repo: &str, branch: &str) -> Result<String, GithubError> {
let github_api_url = format!("{}/repos/{}/{}/commits/{}", GITHUB_API_BASE_URL, org, repo, branch);
pub async fn get_latest_commit_hash(org: &str, repo: &str) -> Result<String, GithubError> {
let github_api_url = format!("{}/repos/{}/{}/commits", GITHUB_API_BASE_URL, org, repo);

let client = Client::new();
let response = client.get(github_api_url).header("User-Agent", "reqwest").send().await;

match response {
Ok(response) => match response.json::<Commit>().await {
Ok(latest_commit) => Ok(latest_commit.sha.clone()),
return match response {
Ok(response) => match response.json::<Vec<Commit>>().await {
Ok(commits) => match commits.first() {
Some(latest_commit) => Ok(latest_commit.sha.clone()),
None => Err(GithubError::NoCommitsFound),
},
Err(err) => Err(GithubError::FailedToGetCommits(err)),
},
Err(err) => Err(GithubError::FailedToGetCommits(err)),
}
};
}

pub fn git_clone(url: &str, path: &PathBuf, branch: Option<&str>) -> Result<(), GithubError> {
Expand All @@ -36,22 +39,6 @@ pub fn git_clone(url: &str, path: &PathBuf, branch: Option<&str>) -> Result<(),
let remote = repo.find_remote("origin")?;
if let Some(remote_url) = remote.url() {
if remote_url == url {
if let Some(branch) = branch {
Command::new("git")
.arg("fetch")
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.current_dir(path)
.output()?;
Command::new("git")
.arg("checkout")
.arg(branch)
.current_dir(path)
.stdout(Stdio::null())
.stderr(Stdio::null())
.output()?;
Command::new("git").arg("pull").stdout(Stdio::inherit()).stderr(Stdio::inherit()).output()?;
}
return Ok(());
}
}
Expand Down
16 changes: 4 additions & 12 deletions src/utils/madara.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
use crate::app::config::AppChainConfig;
use crate::da::da_layers::DALayer;
use crate::utils::cmd::execute_cmd;
use crate::utils::constants::{APP_DA_CONFIG_NAME, MADARA_REPO_NAME, MADARA_REPO_ORG};
use crate::utils::constants::{APP_DA_CONFIG_NAME, BRANCH_NAME, KARNOT_REPO_ORG, MADARA_REPO_NAME};
use crate::utils::errors::MadaraError;
use crate::utils::github::git_clone;
use crate::utils::paths::{get_app_home, get_madara_home};

pub const GITHUB_BASE_URL: &str = "https://github.com";

pub fn clone_madara_and_build_repo(config: &AppChainConfig) -> Result<(), MadaraError> {
let repo_url = format!("{}/{}/{}", GITHUB_BASE_URL, MADARA_REPO_ORG, MADARA_REPO_NAME);
pub fn clone_madara_and_build_repo() -> Result<(), MadaraError> {
let repo_url = format!("{}/{}/{}", GITHUB_BASE_URL, KARNOT_REPO_ORG, MADARA_REPO_NAME);
let madara_path = get_madara_home()?.join("madara");

let madara_version = match config.madara_version.as_str() {
// there was a bug initially where the wrong commit version was being set
// in the config
"523ceedc8afe7a4f58abfdbb915aff3c36e817fe" | "8b49fecfe6f420a1dede1e691d50cd59a326bbc0" => {
"5de416aeb2d9e4297e58f7f2dff99aeae521855e"
}
_ => config.madara_version.as_str(),
};
match git_clone(&repo_url, &madara_path, Some(madara_version)) {
match git_clone(&repo_url, &madara_path, Some(BRANCH_NAME)) {
Ok(_) => {
log::info!("Successfully cloned Madara repo");
}
Expand Down
Loading