Skip to content

g1t/services/identity/src/email.rs

610 lines24,841 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Email verification, password reset, and Git for AI scale positioning1//! Transactional email through Cloudflare Email Sending.
2
3use g1t_kit::js;
4use serde::Serialize;
5use worker::{Env, Result};
6
7const FROM: &str = "g1t <noreply@g1t.sh>";
8const SITE: &str = "https://g1t.sh";
9
Merge branch 'worktree-agent-aaf03bdceac799c89'10/// Where links in mail point: SITE_URL, or g1t.sh when it is not set (a
11/// self-hosted installation sets it from its PUBLIC_URL).
12pub fn site(env: &Env) -> String {
13 let value = env.var("SITE_URL").map(|value| value.to_string()).unwrap_or_default();
14 let value = value.trim().trim_end_matches('/');
15 if value.is_empty() { SITE.to_owned() } else { value.to_owned() }
16}
17
18/// Who mail is from: MAIL_FROM, or g1t.sh's address when it is not set.
19fn from(env: &Env) -> String {
20 let value = env.var("MAIL_FROM").map(|value| value.to_string()).unwrap_or_default();
21 if value.trim().is_empty() { FROM.to_owned() } else { value.trim().to_owned() }
22}
23
24/// A site's address without its scheme, as mail names it in a sentence.
25fn bare(site: &str) -> &str {
26 site.split_once("://").map_or(site, |(_, rest)| rest)
27}
28
Email verification, password reset, and Git for AI scale positioning29#[derive(Serialize)]
30struct Message<'a> {
31 to: &'a str,
32 from: &'a str,
33 subject: &'a str,
34 text: String,
35 html: String,
36}
37
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas38/// What one email says, before it is laid out as text and HTML.
39#[derive(Debug, Default)]
40pub struct Letter {
41 pub paragraphs: Vec<String>,
42 /// Quoted passages, each with who or what it is from: a note from the
43 /// person who sent an invite, or what someone asking for access said.
44 pub quotes: Vec<(String, String)>,
45 /// The button: what it says, and where it goes.
46 pub action: Option<(String, String)>,
47 pub footer: String,
48}
49
50/// The plain text and HTML of a letter. Everything in it is escaped:
51/// names, notes and requests people wrote can reach every line.
Merge branch 'worktree-agent-aaf03bdceac799c89'52pub fn render(letter: &Letter, site: &str) -> (String, String) {
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas53 let mut text = String::new();
54 let mut html = format!(
55 "<div style=\"font-family:system-ui,sans-serif;max-width:480px;margin:0 auto;padding:32px 16px;color:#16150f\">\
Merge branch 'worktree-agent-aaf03bdceac799c89'56 <p style=\"margin:0 0 20px\"><img src=\"{site}/brand/g1t-logo.png\" width=\"60\" height=\"28\" alt=\"g1t\" style=\"display:block;border:0\"></p>"
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas57 );
58 for paragraph in &letter.paragraphs {
59 text.push_str(paragraph);
60 text.push_str("\n\n");
61 html.push_str(&format!("<p style=\"font-size:15px;line-height:1.6\">{}</p>", escape(paragraph)));
62 }
63 for (from, quote) in &letter.quotes {
64 text.push_str(&format!("{from}:\n"));
65 for line in quote.lines() {
66 text.push_str(&format!("> {line}\n"));
67 }
68 text.push('\n');
69 html.push_str(&format!(
70 "<p style=\"margin:20px 0 6px;font-size:13px;color:#6e6a5e\">{}</p>\
71 <blockquote style=\"margin:0;padding:2px 0 2px 14px;border-left:3px solid #b9a6f2;font-size:15px;line-height:1.6;white-space:pre-line\">{}</blockquote>",
72 escape(from),
73 escape(quote)
74 ));
75 }
76 if let Some((label, link)) = &letter.action {
77 text.push_str(&format!("{label}: {link}\n\n"));
78 html.push_str(&format!(
79 "<p style=\"margin:24px 0\"><a href=\"{}\" style=\"background:#16150f;color:#fff;text-decoration:none;padding:10px 18px;border-radius:6px;font-size:15px\">{}</a></p>",
80 escape(link),
81 escape(label)
82 ));
83 }
84 text.push_str(&letter.footer);
85 text.push('\n');
86 html.push_str(&format!(
87 "<p style=\"font-size:13px;line-height:1.6;color:#6e6a5e\">{}</p></div>",
88 escape(&letter.footer)
89 ));
90 (text, html)
91}
92
93/// Sends a letter.
94pub async fn send(env: &Env, to: &str, subject: &str, letter: &Letter) -> Result<()> {
Merge branch 'worktree-agent-aaf03bdceac799c89'95 let (text, html) = render(letter, &site(env));
96 let from = from(env);
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas97 let message = Message {
98 to,
Merge branch 'worktree-agent-aaf03bdceac799c89'99 from: &from,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas100 subject,
101 text,
102 html,
103 };
104 let binding = js::binding(env, "EMAIL")?;
105 js::call(&binding, "send", &[js::to_js(&message)?]).await?;
106 Ok(())
107}
108
Email verification, password reset, and Git for AI scale positioning109/// A short message with one link to follow.
Billing on Stripe's pages, month-end charges, warnings; sudo by workspace110pub async fn send_link(
Email verification, password reset, and Git for AI scale positioning111 env: &Env,
112 to: &str,
113 subject: &str,
114 intro: &str,
115 action: &str,
116 link: &str,
117 footer: &str,
118) -> Result<()> {
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas119 let letter = Letter {
120 paragraphs: vec![intro.to_owned()],
121 quotes: Vec::new(),
122 action: Some((action.to_owned(), link.to_owned())),
123 footer: footer.to_owned(),
Email verification, password reset, and Git for AI scale positioning124 };
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas125 send(env, to, subject, &letter).await
Email verification, password reset, and Git for AI scale positioning126}
127
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look128/// Text made safe to put in HTML, in an element or a quoted attribute.
129fn escape(text: &str) -> String {
130 let mut escaped = String::with_capacity(text.len());
131 for c in text.chars() {
132 match c {
133 '&' => escaped.push_str("&amp;"),
134 '<' => escaped.push_str("&lt;"),
135 '>' => escaped.push_str("&gt;"),
136 '"' => escaped.push_str("&quot;"),
137 '\'' => escaped.push_str("&#39;"),
138 c => escaped.push(c),
139 }
140 }
141 escaped
142}
143
Email verification, password reset, and Git for AI scale positioning144pub async fn send_verification(env: &Env, to: &str, username: &str, token: &str) -> Result<()> {
145 send_link(
146 env,
147 to,
148 "Confirm your email for g1t",
149 &format!("Welcome to g1t, {username}. Confirm this address to finish creating your account."),
150 "Confirm email",
Merge branch 'worktree-agent-aaf03bdceac799c89'151 &format!("{}/verify?token={token}", site(env)),
Email verification, password reset, and Git for AI scale positioning152 "This link works for 24 hours. If you did not create a g1t account, you can ignore this message.",
153 )
154 .await
155}
156
157pub async fn send_password_reset(env: &Env, to: &str, username: &str, token: &str) -> Result<()> {
158 send_link(
159 env,
160 to,
161 "Reset your g1t password",
162 &format!("Someone asked to reset the password for the g1t account {username}."),
163 "Choose a new password",
Merge branch 'worktree-agent-aaf03bdceac799c89'164 &format!("{}/reset?token={token}", site(env)),
Email verification, password reset, and Git for AI scale positioning165 "This link works for 1 hour. If this was not you, ignore this message and your password stays the same.",
166 )
167 .await
168}
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look169
170/// Confirms an address added to an existing account.
171pub async fn send_added_address(env: &Env, to: &str, username: &str, token: &str) -> Result<()> {
172 send_link(
173 env,
174 to,
175 "Confirm your email for g1t",
176 &format!("Confirm this address to add it to the g1t account {username}."),
177 "Confirm email",
Merge branch 'worktree-agent-aaf03bdceac799c89'178 &format!("{}/verify?token={token}", site(env)),
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look179 "This link works for 24 hours. If you did not add this address to a g1t account, you can ignore this message.",
180 )
181 .await
182}
183
184/// What a security notice says: one sentence about what changed.
185pub fn security_wording(username: &str, change: &str) -> (String, String) {
186 (
187 format!("Security notice for your g1t account {username}"),
188 format!("{change}. This is about your g1t account {username}."),
189 )
190}
191
192/// Tells an account's addresses that something about its security changed.
193pub async fn send_security_notice(env: &Env, to: &str, username: &str, change: &str) -> Result<()> {
194 let (subject, intro) = security_wording(username, change);
195 send_link(
196 env,
197 to,
198 &subject,
199 &intro,
200 "Review your email settings",
Merge branch 'worktree-agent-aaf03bdceac799c89'201 &format!("{}/settings/emails", site(env)),
202 &format!(
203 "If this was you, there is nothing to do. If it was not, reset your password at {}/forgot straight away and remove any address you do not recognise.",
204 bare(&site(env))
205 ),
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look206 )
207 .await
208}
209
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas210/// An invite email: to make an account, or for an existing one to join a
211/// workspace.
212pub struct InviteEmail<'a> {
213 pub to: &'a str,
214 /// Who sent it (a name, or a username); None when g1t staff did.
215 pub from: Option<&'a str>,
216 /// The workspace it joins, by name.
217 pub workspace: Option<&'a str>,
218 pub joins_existing_account: bool,
219 pub code: &'a str,
220 pub days: u64,
221 /// A line from whoever sent it, such as staff approving a request.
222 pub note: Option<&'a str>,
223}
224
225/// The subject and letter of an invite email.
Merge branch 'worktree-agent-aaf03bdceac799c89'226pub fn invite_letter(invite: &InviteEmail, site: &str) -> (String, Letter) {
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas227 let (subject, intro) = invite_wording(invite.from, invite.workspace, invite.joins_existing_account);
228 let action = match invite.workspace {
229 Some(workspace) if invite.joins_existing_account => format!("Join {workspace}"),
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look230 _ => "Accept invite".to_owned(),
231 };
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas232 let quotes = match invite.note.map(str::trim).filter(|note| !note.is_empty()) {
233 Some(note) => vec![(
234 match invite.from {
235 Some(from) => format!("A note from {from}"),
236 None => "A note from the g1t team".to_owned(),
237 },
238 note.to_owned(),
239 )],
240 None => Vec::new(),
241 };
242 let letter = Letter {
243 paragraphs: vec![intro],
244 quotes,
Merge branch 'worktree-agent-aaf03bdceac799c89'245 action: Some((action, format!("{site}/invite/{}", invite.code))),
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas246 footer: format!(
247 "This invite works for {} days, only for this address. If you were not expecting it, you can ignore this message.",
248 invite.days
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look249 ),
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas250 };
251 (subject, letter)
252}
253
254pub async fn send_invite(env: &Env, invite: &InviteEmail<'_>) -> Result<()> {
Merge branch 'worktree-agent-aaf03bdceac799c89'255 let (subject, letter) = invite_letter(invite, &site(env));
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas256 send(env, invite.to, &subject, &letter).await
257}
258
259/// Where staff decide on access requests.
260pub const SUDO_WAITLIST: &str = "https://sudo.g1t.sh/invites?tab=waitlist";
261
262/// The one confirmation someone gets after asking for access.
Merge branch 'worktree-agent-aaf03bdceac799c89'263pub fn waitlist_confirmation(site: &str) -> (String, Letter) {
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas264 (
265 "You're on the list for g1t".to_owned(),
266 Letter {
267 paragraphs: vec![
268 "Thanks for asking to try g1t. You're on the list, and we'll email you an invite at this address when there's a place for you.".to_owned(),
269 "g1t is invite-only while we open it up a few people at a time, so we can't say exactly when that will be. Someone already on g1t can also invite you sooner.".to_owned(),
270 ],
271 quotes: Vec::new(),
272 action: None,
Merge branch 'worktree-agent-aaf03bdceac799c89'273 footer: format!("You're getting this because this address asked for access at {}/register. If that wasn't you, ignore this message; nothing more is sent unless you're invited.", bare(site)),
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas274 },
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look275 )
276}
277
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas278pub async fn send_waitlist_confirmation(env: &Env, to: &str) -> Result<()> {
Merge branch 'worktree-agent-aaf03bdceac799c89'279 let (subject, letter) = waitlist_confirmation(&site(env));
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas280 send(env, to, &subject, &letter).await
281}
282
283/// One access request, as a staff summary lists it.
284pub struct Requested {
285 pub email: String,
286 pub about: Option<String>,
287}
288
289/// The most requests one summary lists; the rest are counted.
290pub const SUMMARY_LISTS: usize = 20;
291
292/// The summary staff get of new access requests: every one since the last
293/// summary, and how many are waiting in all.
294pub fn waitlist_summary(new: &[Requested], waiting: u32) -> (String, Letter) {
295 let subject = match new {
296 [one] => format!("g1t access request from {}", one.email),
297 _ => format!("{} new g1t access requests", new.len()),
298 };
299 let asked = match new.len() {
300 1 => "Someone asked for access to g1t.".to_owned(),
301 n => format!("{n} people asked for access to g1t since the last summary."),
302 };
303 let in_all = if waiting as usize > new.len() {
304 format!(" {waiting} requests are waiting in all.")
305 } else {
306 String::new()
307 };
308 let mut quotes: Vec<(String, String)> = new
309 .iter()
310 .take(SUMMARY_LISTS)
311 .map(|request| {
312 (
313 request.email.clone(),
314 request
315 .about
316 .as_deref()
317 .map(str::trim)
318 .filter(|about| !about.is_empty())
319 .unwrap_or("(They did not say what they will build.)")
320 .to_owned(),
321 )
322 })
323 .collect();
324 if new.len() > SUMMARY_LISTS {
325 quotes.push(("And more".to_owned(), format!("{} more requests are on the waitlist.", new.len() - SUMMARY_LISTS)));
326 }
327 let letter = Letter {
328 paragraphs: vec![format!("{asked}{in_all}")],
329 quotes,
330 action: Some(("Review the waitlist".to_owned(), SUDO_WAITLIST.to_owned())),
331 footer: "Sent to WAITLIST_NOTIFY_EMAIL at most once every 15 minutes. A request that arrives in between is in the next summary, and every request is in sudo straight away.".to_owned(),
332 };
333 (subject, letter)
334}
335
336pub async fn send_waitlist_summary(env: &Env, to: &str, new: &[Requested], waiting: u32) -> Result<()> {
337 let (subject, letter) = waitlist_summary(new, waiting);
338 send(env, to, &subject, &letter).await
339}
340
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look341/// An invitation to collaborate on one repository. `code` is set when the
342/// address has no account yet: the link then makes one and accepts; without
343/// it, the link opens the invitation to accept or decline.
344pub async fn send_repo_invite(
345 env: &Env,
346 to: &str,
347 from: &str,
348 repo: &str,
349 role: &str,
350 code: Option<&str>,
351 days: u64,
352) -> Result<()> {
353 let (subject, intro) = repo_invite_wording(from, repo, role, code.is_some());
354 let link = match code {
Merge branch 'worktree-agent-aaf03bdceac799c89'355 Some(code) => format!("{}/invite/{code}", site(env)),
356 None => format!("{}/{repo}/invitations", site(env)),
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look357 };
358 send_link(
359 env,
360 to,
361 &subject,
362 &intro,
363 "View invitation",
364 &link,
365 &format!("This invitation works for {days} days. If you were not expecting it, you can ignore this message."),
366 )
367 .await
368}
369
Inbox: threads, reasons, subscriptions and watching370/// Why a person is emailed about an inbox item, as the end of a sentence.
371fn notified_because(reason: g1t_contracts::inbox::Reason) -> &'static str {
372 use g1t_contracts::inbox::Reason;
373 match reason {
374 Reason::Agent => "an agent is waiting on you",
375 Reason::ReviewRequested => "you were asked to review",
376 Reason::Assign => "you were assigned",
377 Reason::Mention => "you were mentioned",
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar378 Reason::TeamMention => "a team you are in was mentioned",
Inbox: threads, reasons, subscriptions and watching379 Reason::CiActivity => "it is about your work",
380 Reason::SecurityAlert => "you look after this repository's security",
381 Reason::StateChange => "you are subscribed to it",
382 Reason::Author => "you opened it",
383 Reason::Comment => "you commented on it",
384 Reason::Manual => "you subscribed to it",
385 Reason::Subscribed => "you watch this repository",
386 }
387}
388
389/// An item from the inbox, by email: what happened, what it happened to,
390/// and a link to it.
391pub fn notification_letter(a: &g1t_contracts::inbox::NotifyByEmailArgs, site: &str) -> Letter {
392 let path = if a.path.starts_with('/') { a.path.clone() } else { format!("/{}", a.path) };
393 Letter {
394 paragraphs: [a.subject.trim(), a.intro.trim()]
395 .into_iter()
396 .filter(|line| !line.is_empty())
397 .map(str::to_owned)
398 .collect(),
399 quotes: a.quote.iter().cloned().collect(),
400 action: Some(("Open on g1t".to_owned(), format!("{site}{path}"))),
401 footer: format!(
402 "You are getting this because {}. Choose what you are emailed for at {site}/settings/notifications.",
403 notified_because(a.reason)
404 ),
405 }
406}
407
408pub async fn send_notification(env: &Env, to: &str, a: &g1t_contracts::inbox::NotifyByEmailArgs) -> Result<()> {
409 let letter = notification_letter(a, &site(env));
410 send(env, to, &a.subject, &letter).await
411}
412
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look413/// The subject and first line of a repository invitation.
414pub fn repo_invite_wording(from: &str, repo: &str, role: &str, new_account: bool) -> (String, String) {
415 let subject = format!("{from} invited you to {repo} on g1t");
416 let intro = if new_account {
417 format!(
418 "{from} invited you to collaborate on {repo} on g1t, with the {role} role. Accepting makes your g1t account and gives you access to {repo}."
419 )
420 } else {
421 format!("{from} invited you to collaborate on {repo} on g1t, with the {role} role.")
422 };
423 (subject, intro)
424}
425
426/// The subject and first line of an invite email.
427pub fn invite_wording(from: Option<&str>, workspace: Option<&str>, joins_existing_account: bool) -> (String, String) {
428 let who = from.unwrap_or("The g1t team");
429 match (workspace, joins_existing_account) {
430 (Some(workspace), true) => (
431 format!("{who} invited you to {workspace} on g1t"),
432 format!("{who} invited you to join the {workspace} workspace on g1t."),
433 ),
434 (Some(workspace), false) => (
435 format!("{who} invited you to {workspace} on g1t"),
436 format!(
437 "{who} invited you to join the {workspace} workspace on g1t, where people and agents ship software together. Accepting makes your account and joins you to {workspace}."
438 ),
439 ),
440 (None, _) => (
441 match from {
442 Some(from) => format!("{from} invited you to g1t"),
443 None => "Your invite to g1t".to_owned(),
444 },
445 format!("{who} invited you to g1t, where people and agents ship software together. g1t is invite-only for now; this invite lets you make your account."),
446 ),
447 }
448}
449
450#[cfg(test)]
451mod tests {
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas452 use super::*;
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look453
454 #[test]
455 fn html_is_escaped() {
456 assert_eq!(
457 escape("<a href=\"x\">Tom & Jerry's</a>"),
458 "&lt;a href=&quot;x&quot;&gt;Tom &amp; Jerry&#39;s&lt;/a&gt;"
459 );
460 assert_eq!(escape("https://g1t.sh/verify?token=ab12"), "https://g1t.sh/verify?token=ab12");
461 }
462
463 #[test]
Inbox: threads, reasons, subscriptions and watching464 fn an_inbox_item_says_what_happened_and_why_it_was_sent() {
465 let a = g1t_contracts::inbox::NotifyByEmailArgs {
466 username: "ana".into(),
467 repo_id: "rep_1".into(),
468 subject: "bo asked you to review acme/rocket#7".into(),
469 intro: "Add the inbox".into(),
470 quote: None,
471 path: "/acme/rocket/pull/7".into(),
472 reason: g1t_contracts::inbox::Reason::ReviewRequested,
473 };
474 let letter = notification_letter(&a, SITE);
475 assert_eq!(letter.paragraphs, vec!["bo asked you to review acme/rocket#7", "Add the inbox"]);
476 assert_eq!(letter.action.unwrap().1, "https://g1t.sh/acme/rocket/pull/7");
477 assert!(letter.footer.starts_with("You are getting this because you were asked to review."));
478 assert!(letter.footer.ends_with("https://g1t.sh/settings/notifications."));
479 }
480
481 #[test]
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look482 fn invites_say_who_sent_them_and_what_they_are_for() {
483 let (subject, intro) = invite_wording(Some("ada"), None, false);
484 assert_eq!(subject, "ada invited you to g1t");
485 assert!(intro.starts_with("ada invited you to g1t"));
486 let (subject, _) = invite_wording(None, None, false);
487 assert_eq!(subject, "Your invite to g1t");
488 let (subject, intro) = invite_wording(Some("ada"), Some("acme"), true);
489 assert_eq!(subject, "ada invited you to acme on g1t");
490 assert_eq!(intro, "ada invited you to join the acme workspace on g1t.");
491 let (_, intro) = invite_wording(Some("ada"), Some("acme"), false);
492 assert!(intro.contains("makes your account and joins you to acme"));
493 }
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas494
495 fn invite<'a>(note: Option<&'a str>, from: Option<&'a str>) -> InviteEmail<'a> {
496 InviteEmail {
497 to: "ada@example.com",
498 from,
499 workspace: Some("Flagon, Inc."),
500 joins_existing_account: false,
501 code: "g1t-abcd",
502 days: 30,
503 note,
504 }
505 }
506
507 #[test]
508 fn an_invite_links_to_its_page_and_carries_a_note() {
Merge branch 'worktree-agent-aaf03bdceac799c89'509 let (subject, letter) = invite_letter(&invite(Some("Welcome aboard <3"), None), SITE);
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas510 assert_eq!(subject, "The g1t team invited you to Flagon, Inc. on g1t");
511 assert_eq!(letter.action.as_ref().unwrap().1, "https://g1t.sh/invite/g1t-abcd");
512 assert_eq!(letter.quotes, vec![("A note from the g1t team".to_owned(), "Welcome aboard <3".to_owned())]);
Merge branch 'worktree-agent-aaf03bdceac799c89'513 let (text, html) = render(&letter, SITE);
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas514 assert!(text.contains("> Welcome aboard <3"));
515 assert!(html.contains("Welcome aboard &lt;3"));
516 assert!(!html.contains("<3"));
517 // No note, no quote; a blank note is no note.
Merge branch 'worktree-agent-aaf03bdceac799c89'518 assert!(invite_letter(&invite(None, Some("Chase Pierce")), SITE).1.quotes.is_empty());
519 assert!(invite_letter(&invite(Some(" "), Some("Chase Pierce")), SITE).1.quotes.is_empty());
520 assert_eq!(invite_letter(&invite(Some("hi"), Some("Chase Pierce")), SITE).1.quotes[0].0, "A note from Chase Pierce");
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas521 }
522
523 #[test]
Merge branch 'worktree-agent-aaf03bdceac799c89'524 fn links_point_at_the_site_they_are_given() {
525 let (_, letter) = invite_letter(&invite(None, None), "http://localhost:8787");
526 assert_eq!(letter.action.as_ref().unwrap().1, "http://localhost:8787/invite/g1t-abcd");
527 let (text, html) = render(&letter, "http://localhost:8787");
528 assert!(html.contains("http://localhost:8787/brand/g1t-logo.png"));
529 assert!(!text.contains("g1t.sh/") && !html.contains("https://g1t.sh"));
530 let (_, letter) = waitlist_confirmation("http://localhost:8787");
531 assert!(letter.footer.contains("localhost:8787/register"));
532 assert_eq!(bare("https://git.example.com"), "git.example.com");
533 }
534
535 #[test]
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas536 fn the_waitlist_confirmation_promises_no_date() {
Merge branch 'worktree-agent-aaf03bdceac799c89'537 let (subject, letter) = waitlist_confirmation(SITE);
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas538 assert_eq!(subject, "You're on the list for g1t");
Merge branch 'worktree-agent-aaf03bdceac799c89'539 let (text, _) = render(&letter, SITE);
540 assert!(text.contains("g1t.sh/register"));
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas541 assert!(text.contains("we'll email you an invite"));
542 assert!(text.contains("can't say exactly when"));
543 assert!(letter.action.is_none());
544 }
545
546 #[test]
547 fn staff_summaries_list_each_request_and_link_to_sudo() {
548 let one = [Requested { email: "ada@example.com".into(), about: Some("A compiler <for> fun".into()) }];
549 let (subject, letter) = waitlist_summary(&one, 1);
550 assert_eq!(subject, "g1t access request from ada@example.com");
551 assert_eq!(letter.paragraphs, vec!["Someone asked for access to g1t."]);
552 assert_eq!(letter.action.as_ref().unwrap().1, SUDO_WAITLIST);
Merge branch 'worktree-agent-aaf03bdceac799c89'553 let (_, html) = render(&letter, SITE);
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas554 assert!(html.contains("A compiler &lt;for&gt; fun"));
555
556 let many: Vec<Requested> = (0..25).map(|n| Requested { email: format!("p{n}@example.com"), about: None }).collect();
557 let (subject, letter) = waitlist_summary(&many, 40);
558 assert_eq!(subject, "25 new g1t access requests");
559 assert_eq!(
560 letter.paragraphs[0],
561 "25 people asked for access to g1t since the last summary. 40 requests are waiting in all."
562 );
563 assert_eq!(letter.quotes.len(), SUMMARY_LISTS + 1);
564 assert_eq!(letter.quotes[0].1, "(They did not say what they will build.)");
565 assert!(letter.quotes.last().unwrap().1.starts_with("5 more"));
566 }
567
568 /// Writes each email as HTML for a look in a browser:
569 /// `G1T_WRITE_EMAILS=<dir> cargo test -p g1t-identity write_emails`.
570 #[test]
571 fn write_emails() {
572 let Ok(dir) = std::env::var("G1T_WRITE_EMAILS") else { return };
573 let page = |name: &str, subject: &str, letter: &Letter| {
Merge branch 'worktree-agent-aaf03bdceac799c89'574 let (_, html) = render(letter, SITE);
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas575 std::fs::write(
576 format!("{dir}/{name}.html"),
577 format!("<!doctype html><meta charset=utf-8><title>{}</title><body style=\"margin:0;background:#fff\">{html}", escape(subject)),
578 )
579 .unwrap();
580 };
Merge branch 'worktree-agent-aaf03bdceac799c89'581 let (subject, letter) = waitlist_confirmation(SITE);
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas582 page("waitlist-confirmation", &subject, &letter);
583 let requests = [
584 Requested { email: "ada@example.com".into(), about: Some("A compiler for a teaching language, with agents writing the test suite.".into()) },
585 Requested { email: "linus@example.com".into(), about: None },
586 ];
587 let (subject, letter) = waitlist_summary(&requests, 7);
588 page("waitlist-summary", &subject, &letter);
589 let (subject, letter) = invite_letter(&InviteEmail {
590 to: "margaret@example.com",
591 from: Some("Chase Pierce"),
592 workspace: Some("Flagon, Inc."),
593 joins_existing_account: false,
594 code: "g1t-k7m2-q9xd-4hpw-abcd-0123-4567-89ef-ghjk",
595 days: 30,
596 note: None,
Merge branch 'worktree-agent-aaf03bdceac799c89'597 }, SITE);
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas598 page("workspace-invite", &subject, &letter);
599 let (subject, letter) = invite_letter(&InviteEmail {
600 to: "ada@example.com",
601 from: None,
602 workspace: None,
603 joins_existing_account: false,
604 code: "g1t-k7m2-q9xd-4hpw-abcd-0123-4567-89ef-ghjk",
605 days: 30,
606 note: Some("Thanks for waiting. We would love to see the compiler."),
Merge branch 'worktree-agent-aaf03bdceac799c89'607 }, SITE);
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas608 page("waitlist-approved", &subject, &letter);
609 }
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look610}

This file's history is long; its oldest lines are credited to the oldest commit read.