Scrape email from feedback editor

Joseph Lyons created

Change summary

Cargo.lock                                |  1 +
crates/feedback/Cargo.toml                |  1 +
crates/feedback/src/feedback_editor.rs    | 12 ++++++++++++
crates/feedback/src/feedback_info_text.rs |  4 ++--
4 files changed, 16 insertions(+), 2 deletions(-)

Detailed changes

Cargo.lock 🔗

@@ -2236,6 +2236,7 @@ dependencies = [
  "log",
  "postage",
  "project",
+ "regex",
  "search",
  "serde",
  "serde_derive",

crates/feedback/Cargo.toml 🔗

@@ -16,6 +16,7 @@ editor = { path = "../editor" }
 language = { path = "../language" }
 gpui = { path = "../gpui" }
 project = { path = "../project" }
+regex.workspace = true
 search = { path = "../search" }
 settings = { path = "../settings" }
 theme = { path = "../theme" }

crates/feedback/src/feedback_editor.rs 🔗

@@ -14,6 +14,7 @@ use isahc::Request;
 use language::Buffer;
 use postage::prelude::Stream;
 use project::Project;
+use regex::Regex;
 use serde::Serialize;
 use smallvec::SmallVec;
 use std::{
@@ -46,6 +47,7 @@ pub fn init(cx: &mut AppContext) {
 #[derive(Serialize)]
 struct FeedbackRequestBody<'a> {
     feedback_text: &'a str,
+    email: Option<String>,
     metrics_id: Option<Arc<str>>,
     installation_id: Option<Arc<str>>,
     system_specs: SystemSpecs,
@@ -157,8 +159,18 @@ impl FeedbackEditor {
         let is_staff = telemetry.is_staff();
         let http_client = zed_client.http_client();
 
+        let re = Regex::new(r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b").unwrap();
+
+        let emails: Vec<&str> = re
+            .captures_iter(feedback_text)
+            .map(|capture| capture.get(0).unwrap().as_str())
+            .collect();
+
+        let email = emails.first().map(|e| e.to_string());
+
         let request = FeedbackRequestBody {
             feedback_text: &feedback_text,
+            email,
             metrics_id,
             installation_id,
             system_specs,

crates/feedback/src/feedback_info_text.rs 🔗

@@ -34,7 +34,7 @@ impl View for FeedbackInfoText {
         Flex::row()
             .with_child(
                 Text::new(
-                    "We read whatever you submit here. For issues and discussions, visit the ",
+                    "Share your feedback. Include your email for replies. For issues and discussions, visit the ",
                     theme.feedback.info_text_default.text.clone(),
                 )
                 .with_soft_wrap(false)
@@ -60,7 +60,7 @@ impl View for FeedbackInfoText {
                 }),
             )
             .with_child(
-                Text::new(" on GitHub.", theme.feedback.info_text_default.text.clone())
+                Text::new(".", theme.feedback.info_text_default.text.clone())
                     .with_soft_wrap(false)
                     .aligned(),
             )