Skip to content

Commit

Permalink
feat: add debug logging to github hook
Browse files Browse the repository at this point in the history
  • Loading branch information
zleyyij committed Aug 18, 2024
1 parent 076a599 commit 6614144
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
8 changes: 6 additions & 2 deletions backend/src/gh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,13 @@ async fn get_installation_id(req_client: &Client) -> Result<String> {
.send()
.await?;
// Validate that there's only one repo the app is installed on
let repo_list = &serde_json::from_slice::<Vec<InstallationIdResponse>>(&response.bytes().await?)?;
let repo_list =
&serde_json::from_slice::<Vec<InstallationIdResponse>>(&response.bytes().await?)?;
if repo_list.len() != 1 {
bail!("Hyde must only be installed on one repo, Github currently reports {} repos", repo_list.len());
bail!(
"Hyde must only be installed on one repo, Github currently reports {} repos",
repo_list.len()
);
}
Ok(repo_list[0].id.to_string())
}
Expand Down
22 changes: 10 additions & 12 deletions backend/src/handlers_prelude/github_hook.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
//! Github Webhook events are sent here
use axum::{extract::State, http::HeaderMap};
use tracing::{error, info};
use tracing::{debug, error, info};

use crate::AppState;


pub async fn github_hook_handler(State(state): State<AppState>, headers: HeaderMap) {
let event_type = headers.get("x-github-event").unwrap().to_str().unwrap();
if event_type == "push" {
info!("New changes pushed to Github, pulling changes...");
match state.git.pull() {
Ok(_) => {
},
Err(e) => {
error!("Failed to auto-pull changes with error: {e:?}");
},
debug!("Received Github webhook event of type {event_type:?}");
if event_type == "push" {
info!("New changes pushed to Github, pulling changes...");
match state.git.pull() {
Ok(_) => {}
Err(e) => {
error!("Failed to auto-pull changes with error: {e:?}");
}

}
}
}
}
2 changes: 1 addition & 1 deletion backend/src/handlers_prelude/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async fn find_user(state: &AppState, headers: HeaderMap) -> color_eyre::Result<O
}

/// This function is used to add permissions to endpoints.
///
///
/// When placed at the top of an Axum handler, you can specify permission(s)
/// to require. If they are missing from the user, it will return an error,
/// which you can propagate through the handler with `?`.
Expand Down
5 changes: 4 additions & 1 deletion backend/src/handlers_prelude/reclone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use crate::{perms::Permission, AppState};

use super::{eyre_to_axum_err, require_perms};

pub async fn post_reclone_handler(State(state): State<AppState>, headers: HeaderMap) -> Result<(), (StatusCode, String)> {
pub async fn post_reclone_handler(
State(state): State<AppState>,
headers: HeaderMap,
) -> Result<(), (StatusCode, String)> {
require_perms(State(&state), headers, &[Permission::ManageUsers]).await?;
state.git.reclone().map_err(eyre_to_axum_err)?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ use reqwest::{
header::{ACCEPT, ALLOW, CONTENT_TYPE},
Client, Method,
};
use tracing_subscriber::fmt::format::FmtSpan;
use std::env::{self, current_exe};
use std::time::Duration;
#[cfg(target_family = "unix")]
use tokio::signal::unix::{signal, SignalKind};
use tracing::{Level, Span};
use tracing_subscriber::fmt::format::FmtSpan;

use tokio::task;
use tower_http::cors::CorsLayer;
Expand Down

0 comments on commit 6614144

Please sign in to comment.