diff --git a/src/core/application/mod.rs b/src/core/application/mod.rs index 2093c4aa..105b2787 100644 --- a/src/core/application/mod.rs +++ b/src/core/application/mod.rs @@ -20,6 +20,7 @@ pub struct ApplicationFile { pub id: String, pub _type: ApplicationType, pub info: ApplicationInfo, + pub version: u64, } impl ApplicationFile { @@ -28,6 +29,7 @@ impl ApplicationFile { id: application_id, _type: ApplicationType::LDN, info: app_info, + version: 1, } } @@ -46,6 +48,7 @@ impl ApplicationFile { id: self.id.clone(), _type: self._type.clone(), info, + version: 1, } } @@ -67,6 +70,7 @@ impl ApplicationFile { id: self.id.clone(), _type: self._type.clone(), info, + version: 1, }; } ApplicationAllocationTypes::Removal => { @@ -98,6 +102,7 @@ impl ApplicationFile { id: self.id.clone(), _type: self._type.clone(), info, + version: 1, } } } diff --git a/src/core/mod.rs b/src/core/mod.rs index 67baadcb..a467dfc1 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -10,8 +10,11 @@ use actix_web::{ web::Bytes, }; use chrono::Utc; -use octocrab::models::{pulls::{PullRequest, FileDiff}, repos::ContentItems}; use futures::future; +use octocrab::models::{ + pulls::{FileDiff, PullRequest}, + repos::ContentItems, +}; use reqwest::Response; use self::application::{ @@ -134,37 +137,53 @@ impl LDNApplication { let gh: GithubWrapper = GithubWrapper::new(); let mut apps: Vec = Vec::new(); let pull_requests = gh.list_pull_requests().await.unwrap(); - let pull_requests = future::try_join_all(pull_requests - .into_iter() - .map(|pr: PullRequest| { - let number = pr.number; - gh.get_pull_request_files(number) - }) - .collect::>()).await.unwrap().into_iter().flatten(); - let pull_requests: Vec = match future::try_join_all(pull_requests - .into_iter() - .map(|fd: FileDiff| { - reqwest::Client::new() - .get(&fd.raw_url.to_string()) - .send() - }) - .collect::>()).await { - Ok(res) => res, - Err(_) => return Err(LDNApplicationError::LoadApplicationError("Failed to get pull request files".to_string())) + let pull_requests = future::try_join_all( + pull_requests + .into_iter() + .map(|pr: PullRequest| { + let number = pr.number; + gh.get_pull_request_files(number) + }) + .collect::>(), + ) + .await + .unwrap() + .into_iter() + .flatten(); + let pull_requests: Vec = match future::try_join_all( + pull_requests + .into_iter() + .map(|fd: FileDiff| reqwest::Client::new().get(&fd.raw_url.to_string()).send()) + .collect::>(), + ) + .await + { + Ok(res) => res, + Err(_) => { + return Err(LDNApplicationError::LoadApplicationError( + "Failed to get pull request files".to_string(), + )) + } }; - let pull_requests = match future::try_join_all(pull_requests - .into_iter() - .map(|r: Response| { - r.text() - }) - .collect::>()).await { + let pull_requests = match future::try_join_all( + pull_requests + .into_iter() + .map(|r: Response| r.text()) + .collect::>(), + ) + .await + { Ok(res) => res, - Err(_) => return Err(LDNApplicationError::LoadApplicationError("Failed to get pull request files".to_string())) + Err(_) => { + return Err(LDNApplicationError::LoadApplicationError( + "Failed to get pull request files".to_string(), + )) + } }; for r in pull_requests { match serde_json::from_str::(&r) { Ok(app) => apps.push(app), - Err(_) => continue + Err(_) => continue, } } Ok(apps) diff --git a/src/db/collections/logs.rs b/src/db/collections/logs.rs index e69de29b..8b137891 100644 --- a/src/db/collections/logs.rs +++ b/src/db/collections/logs.rs @@ -0,0 +1 @@ + diff --git a/src/external_services/github.rs b/src/external_services/github.rs index eacd3015..2c7e50d2 100644 --- a/src/external_services/github.rs +++ b/src/external_services/github.rs @@ -154,7 +154,7 @@ impl GithubWrapper<'static> { pub async fn get_pull_request_files( &self, - pr_number: u64 + pr_number: u64, ) -> Result, OctocrabError> { let iid: Page = self .inner diff --git a/src/main.rs b/src/main.rs index d03f7a1c..2cb97353 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ extern crate markdown; use std::sync::Mutex; use actix_web::middleware::Logger; -use actix_web::{App, HttpServer, web}; +use actix_web::{web, App, HttpServer}; use env_logger; pub(crate) mod base64; @@ -29,7 +29,7 @@ pub(crate) mod router; #[tokio::main] async fn main() -> std::io::Result<()> { env_logger::init_from_env(env_logger::Env::new().default_filter_or("debug")); - let client =match db::setup::setup().await { + let client = match db::setup::setup().await { Ok(client) => client, Err(e) => panic!("Error setting up database: {}", e), }; diff --git a/src/router/application.rs b/src/router/application.rs index bb36cfef..3f7b5d2c 100644 --- a/src/router/application.rs +++ b/src/router/application.rs @@ -11,9 +11,9 @@ use actix_web::{get, post, web, HttpResponse, Responder}; /// /// # Example /// ```plaintext -/// curl --header "Content-Type: application/json" -/// --request POST -/// --data '{"application_id": "0x1234"}' +/// curl --header "Content-Type: application/json" +/// --request POST +/// --data '{"application_id": "0x1234"}' /// http://localhost:8080/application /// ``` /// @@ -39,9 +39,9 @@ pub async fn create_application(info: web::Json) -> impl /// /// # Example /// ```plaintext -/// curl --header "Content-Type: application/json" -/// --request POST -/// --data '{"actor": "JohnDoe"}' +/// curl --header "Content-Type: application/json" +/// --request POST +/// --data '{"actor": "JohnDoe"}' /// http://localhost:8080/application/0x1234/trigger /// ``` /// @@ -82,8 +82,8 @@ pub async fn trigger_application( /// /// # Example /// ```plaintext -/// curl --header "Content-Type: application/json" -/// --request POST +/// curl --header "Content-Type: application/json" +/// --request POST /// --data '{ /// "signer": { /// "signing_address": "0x1234567890abcdef1234567890abcdef12345678", @@ -91,7 +91,7 @@ pub async fn trigger_application( /// "message_cid": "QmXYZ1234567890abcdef1234567890abcdef12345678" /// }, /// "request_id": "exampleRequestId123" -/// }' +/// }' /// http://localhost:8080/application/0x1234/propose /// ``` /// @@ -131,8 +131,8 @@ pub async fn propose_application( /// /// # Example /// ```plaintext -/// curl --header "Content-Type: application/json" -/// --request POST +/// curl --header "Content-Type: application/json" +/// --request POST /// --data '{ /// "signer": { /// "signing_address": "0x1234567890abcdef1234567890abcdef12345678", @@ -140,7 +140,7 @@ pub async fn propose_application( /// "message_cid": "QmXYZ1234567890abcdef1234567890abcdef12345678" /// }, /// "request_id": "exampleRequestId123" -/// }' +/// }' /// http://localhost:8080/application/0x1234/approve /// ``` /// @@ -179,8 +179,8 @@ pub async fn approve_application( /// /// # Example /// ```plaintext -/// curl --header "Content-Type: application/json" -/// --request POST +/// curl --header "Content-Type: application/json" +/// --request POST /// http://localhost:8080/application/0x1234/merge /// ``` /// diff --git a/src/router/blockchain.rs b/src/router/blockchain.rs index c8c6675c..644b3ea5 100644 --- a/src/router/blockchain.rs +++ b/src/router/blockchain.rs @@ -28,7 +28,8 @@ pub async fn address_allowance(address: web::Path) -> impl Responder { { Ok(res) => return HttpResponse::Ok().body(res), Err(_) => { - return HttpResponse::InternalServerError().body("SOMETHING IS WRONG WITH DEMOB SETUP!"); + return HttpResponse::InternalServerError() + .body("SOMETHING IS WRONG WITH DEMOB SETUP!"); } } } @@ -57,7 +58,8 @@ pub async fn verified_clients() -> impl Responder { match blockchain.get_verified_clients().await { Ok(res) => return HttpResponse::Ok().body(res), Err(_) => { - return HttpResponse::InternalServerError().body("SOMETHING IS WRONG WITH DEMOB SETUP!"); + return HttpResponse::InternalServerError() + .body("SOMETHING IS WRONG WITH DEMOB SETUP!"); } } }