this repo has no description
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

Listen to events

+38 -4
+38 -4
src/main.rs
··· 1 + use std::process::Command; 2 + 1 3 use websocket::sync::client::ClientBuilder; 2 4 3 5 mod args; ··· 51 53 println!(" Connected successfully."); 52 54 53 55 // on event: 54 - // parse json 55 - // validate meets expected schema (allow unknown vals) 56 - // filter by did and reponame 57 - // exec shell command in user shell (/bin/sh as fallback) 56 + for message in client.incoming_messages() { 57 + if let Ok(ref val) = message 58 + && let websocket::OwnedMessage::Text(body) = val 59 + { 60 + // parse json 61 + let body = match json::parse(&body) { 62 + Ok(val) => val, 63 + Err(_) => { 64 + println!(" Invalid body. Skipping message"); 65 + continue; 66 + } 67 + }; 68 + 69 + // filter by did and reponame 70 + if let Some(repo_did) = body["event"]["repoDid"].as_str() 71 + && let Some(repo) = body["event"]["repoName"].as_str() 72 + && repo_did != &did_doc.did 73 + && repo != &config.repo_name 74 + { 75 + // repo doesnt match so skip 76 + continue; 77 + } 78 + 79 + // exec shell command in /bin/sh 80 + match Command::new("/bin/sh") 81 + .arg("-c") 82 + .arg(&config.shell) 83 + .output() 84 + { 85 + Ok(val) => val, 86 + Err(_) => continue, 87 + }; 88 + } else if let Err(err) = message { 89 + println!(" Got websocket error: {}", err) 90 + } 91 + } 58 92 59 93 return Ok(()); 60 94 }