Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3767773
D2806.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D2806.diff
View Options
diff --git a/.arcconfig b/.arcconfig
new file mode 100644
--- /dev/null
+++ b/.arcconfig
@@ -0,0 +1,4 @@
+{
+ "phabricator.uri": "https://devcentral.nasqueron.org/",
+ "repository.callsign": "NPUSH"
+}
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
new file mode 100644
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+/target
+Cargo.lock
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,16 @@
+[package]
+name = "notification-push"
+version = "0.1.0"
+edition = "2021"
+authors = ["Nidal Iguer <hello@inidal.dev>"]
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+clap = { version = "4.1.1", features = ["derive"] }
+serde = { version = "1.0.152", features = ["derive"] }
+serde_json = "1.0.91"
+reqwest = { version = "0.11.14", features = ["json"] }
+openssl-sys = "0.9.80"
+openssl = "0.10.45"
+tokio = { version = "1.12.0", features = ["full"] }
\ No newline at end of file
diff --git a/src/clap_args.rs b/src/clap_args.rs
new file mode 100644
--- /dev/null
+++ b/src/clap_args.rs
@@ -0,0 +1,24 @@
+use clap::Parser;
+
+#[derive(Debug, Parser)]
+#[clap(author, version, about)]
+pub struct ClapArgs {
+ /// The notification's source service (e.g. GitHub, Phabricator, Jenkins)
+ pub clap_service: String,
+
+ /// The notification's target project (e.g. Wikimedia, Nasqueron, Wolfplex)
+ pub clap_project: String,
+
+ /// The notification's target group (e.g. Tasacora, Operations)
+ pub clap_group: String,
+
+ /// The notification's type (e.g. "commits", "task")
+ pub clap_type: String,
+
+ /// The notification's text
+ pub clap_text: Option<String>,
+
+ /// The notification's URL, to be used as the main link for widgets
+ pub clap_link: Option<String>,
+
+}
\ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,59 @@
+mod clap_args;
+
+use clap_args::ClapArgs;
+use clap::Parser;
+use serde::{Serialize};
+use reqwest;
+use std::process::exit;
+
+#[derive(Serialize)]
+struct Notification {
+ service: String,
+ project: String,
+ group: String,
+ #[serde(rename = "type")]
+ _type: String,
+ text: String,
+ link: String,
+}
+
+#[tokio::main]
+async fn main() {
+
+ // Environment variables
+ let api_endpoint = "https://eo4a3aeazbbb14z.m.pipedream.net";
+
+ // ========================================================
+ // 1. Validating user's arguments while parsing (clap)
+ let _args:ClapArgs = ClapArgs::parse();
+
+ // 2. Converting user's arguments to ready-to-post JSON (serde)
+ let populated_notification = Notification {
+ service: _args.clap_service,
+ project: _args.clap_project,
+ group: _args.clap_group,
+ _type: _args.clap_type,
+ text: _args.clap_text.unwrap_or("".to_string()),
+ link: _args.clap_link.unwrap_or("".to_string()),
+ };
+
+ // 3. Sending JSON as HTTP request (reqwest)
+ let client = reqwest::Client::new();
+ let res = client.post(api_endpoint)
+ .json(&populated_notification)
+ .send()
+ .await;
+
+ if let Err(error) = res {
+ eprintln!("{}", &error);
+ exit(1);
+ }
+ // ========================================================
+
+ // Print error if there's any (provided by Dereckson)
+ if !res.unwrap().status().is_success() {
+ eprintln!("The notifications server can't process the notification.");
+ exit(2); // Let's use another code so a script can know at what step it failed.
+ }
+
+}
\ No newline at end of file
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 03:26 (47 m, 35 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2256342
Default Alt Text
D2806.diff (3 KB)
Attached To
Mode
D2806: Recreating the 1st commit
Attached
Detach File
Event Timeline
Log In to Comment