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

fix: make http call async #14

Merged
merged 1 commit into from
Jan 23, 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
8 changes: 4 additions & 4 deletions src/cli/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ pub enum InitError {
FailedToGenerateKeypair,
}

pub fn init() {
let config = match generate_config() {
pub async fn init() {
let config = match generate_config().await {
Ok(config) => config,
Err(err) => {
panic!("Failed to get input: {}", err);
Expand All @@ -44,7 +44,7 @@ pub fn init() {
log::info!("✅ New app chain initialised.");
}

fn generate_config() -> Result<AppChainConfig, InitError> {
async fn generate_config() -> Result<AppChainConfig, InitError> {
let app_chain = get_text_input("Enter you app chain name:", Some("madara"))?;

let app_chains_home = get_app_chains_home()?;
Expand All @@ -53,7 +53,7 @@ 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)?;
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/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async fn main() {
let cli = Cli::parse();

match &cli.command {
Some(Commands::Init) => cli::init::init(),
Some(Commands::Init) => cli::init::init().await,
Some(Commands::List) => cli::list::list(),
Some(Commands::Run) => cli::run::run().await,
Some(Commands::Explorer) => cli::explorer::explorer().await,
Expand Down
8 changes: 4 additions & 4 deletions src/utils/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::PathBuf;
use std::process::{Command, Stdio};

use git2::Repository;
use reqwest::blocking::Client;
use reqwest::Client;
use serde::Deserialize;

use crate::utils::errors::GithubError;
Expand All @@ -14,14 +14,14 @@ struct Commit {
sha: String,
}

pub fn get_latest_commit_hash(org: &str, repo: &str) -> Result<String, GithubError> {
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();
let response = client.get(github_api_url).header("User-Agent", "reqwest").send().await;

return match response {
Ok(response) => match response.json::<Vec<Commit>>() {
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),
Expand Down