diff --git a/.github/workflows/test_pr.yml b/.github/workflows/test_pr.yml new file mode 100644 index 00000000..0017d206 --- /dev/null +++ b/.github/workflows/test_pr.yml @@ -0,0 +1,34 @@ +name: Test Pull Request Workflow + +on: + pull_request: + types: + - opened + - synchronize + pull_request_review: + types: + - submitted + issue_comment: + types: + - created + push: + +jobs: + extract-pr-number: + runs-on: ubuntu-latest + steps: + - name: Set PR Number as Environment Variable + run: echo "PR_NUMBER=${{ github.event.number }}" >> $GITHUB_ENV + - name: Set User Handle as Environment Variable + run: echo "USER_HANDLE=${{ github.actor }}" >> $GITHUB_ENV + + call-backend: + needs: extract-pr-number + runs-on: ubuntu-latest + steps: + - name: Call Backend with PR Number and User Handle + run: | + PR_NUMBER="13" + USER_HANDLE=${{ env.USER_HANDLE }} + BACKEND_URL="https://f01c-89-212-199-23.ngrok-free.app/pr" + curl -X POST -d "pr_number=$PR_NUMBER&user_handle=$USER_HANDLE" $BACKEND_URL diff --git a/fplus-http-server/src/main.rs b/fplus-http-server/src/main.rs index 68bfc0e4..e0917450 100644 --- a/fplus-http-server/src/main.rs +++ b/fplus-http-server/src/main.rs @@ -48,6 +48,7 @@ async fn main() -> std::io::Result<()> { .service(router::application::get_all_applications) .service(router::blockchain::address_allowance) .service(router::blockchain::verified_clients) + .service(router::rkh::receive_pr) }) .bind(("0.0.0.0", 8080))? .run() diff --git a/fplus-http-server/src/router/mod.rs b/fplus-http-server/src/router/mod.rs index e0aa77cb..4fd6b492 100644 --- a/fplus-http-server/src/router/mod.rs +++ b/fplus-http-server/src/router/mod.rs @@ -2,6 +2,7 @@ use actix_web::{get, HttpResponse, Responder}; pub mod application; pub mod blockchain; +pub mod rkh; /// Return server health status #[get("/health")] diff --git a/fplus-http-server/src/router/rkh.rs b/fplus-http-server/src/router/rkh.rs index 0bb11dea..cfd0ca31 100644 --- a/fplus-http-server/src/router/rkh.rs +++ b/fplus-http-server/src/router/rkh.rs @@ -1,13 +1,36 @@ -use actix_web::{get, http::header::ContentType, post, web, HttpResponse}; -use mongodb::Client; -use std::sync::Mutex; +use actix_web::{get, post, web, HttpResponse, Responder}; +use serde::Deserialize; +use fplus_lib::core::LDNApplication; + + +#[derive(Deserialize)] +pub struct PullRequestData { + pr_number: String, + user_handle: String, +} #[get("/rkh")] pub async fn get() -> HttpResponse { HttpResponse::InternalServerError().finish() } -#[post("/rkh")] -pub async fn post() -> HttpResponse { - HttpResponse::InternalServerError().finish() +#[post("/pr")] +pub async fn receive_pr(info: web::Json) -> impl Responder { + let pr_number = info.pr_number.trim_matches('"').parse::(); + + match pr_number { + Ok(pr_number) => { + match LDNApplication::get_by_pr_number(pr_number).await { + Ok(application_file) => { + println!("Received PR data - PR Number: {}, User Handle: {}", pr_number, info.user_handle); + HttpResponse::Ok().json(application_file) + }, + Err(error) => HttpResponse::InternalServerError().json(error.to_string()), + } + } + Err(_) => HttpResponse::BadRequest().json("Invalid PR Number"), + } } + + +