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 positioning | 1 | //! Transactional email through Cloudflare Email Sending. |
| 2 | ||
| 3 | use g1t_kit::js; | |
| 4 | use serde::Serialize; | |
| 5 | use worker::{Env, Result}; | |
| 6 | ||
| 7 | const FROM: &str = "g1t <noreply@g1t.sh>"; | |
| 8 | const SITE: &str = "https://g1t.sh"; | |
| 9 | ||
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 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). | |
| 12 | pub 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. | |
| 19 | fn 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. | |
| 25 | fn bare(site: &str) -> &str { | |
| 26 | site.split_once("://").map_or(site, |(_, rest)| rest) | |
| 27 | } | |
| 28 | ||
| Email verification, password reset, and Git for AI scale positioning | 29 | #[derive(Serialize)] |
| 30 | struct 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 quotas | 38 | /// What one email says, before it is laid out as text and HTML. |
| 39 | #[derive(Debug, Default)] | |
| 40 | pub 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. | |
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 52 | pub 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 quotas | 53 | 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\">\ | |
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 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 quotas | 57 | ); |
| 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. | |
| 94 | pub async fn send(env: &Env, to: &str, subject: &str, letter: &Letter) -> Result<()> { | |
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 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 quotas | 97 | let message = Message { |
| 98 | to, | |
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 99 | from: &from, |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 100 | 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 positioning | 109 | /// A short message with one link to follow. |
| Billing on Stripe's pages, month-end charges, warnings; sudo by workspace | 110 | pub async fn send_link( |
| Email verification, password reset, and Git for AI scale positioning | 111 | 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 quotas | 119 | 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 positioning | 124 | }; |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 125 | send(env, to, subject, &letter).await |
| Email verification, password reset, and Git for AI scale positioning | 126 | } |
| 127 | ||
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 128 | /// Text made safe to put in HTML, in an element or a quoted attribute. |
| 129 | fn 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("&"), | |
| 134 | '<' => escaped.push_str("<"), | |
| 135 | '>' => escaped.push_str(">"), | |
| 136 | '"' => escaped.push_str("""), | |
| 137 | '\'' => escaped.push_str("'"), | |
| 138 | c => escaped.push(c), | |
| 139 | } | |
| 140 | } | |
| 141 | escaped | |
| 142 | } | |
| 143 | ||
| Email verification, password reset, and Git for AI scale positioning | 144 | pub 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", | |
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 151 | &format!("{}/verify?token={token}", site(env)), |
| Email verification, password reset, and Git for AI scale positioning | 152 | "This link works for 24 hours. If you did not create a g1t account, you can ignore this message.", |
| 153 | ) | |
| 154 | .await | |
| 155 | } | |
| 156 | ||
| 157 | pub 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", | |
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 164 | &format!("{}/reset?token={token}", site(env)), |
| Email verification, password reset, and Git for AI scale positioning | 165 | "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 look | 169 | |
| 170 | /// Confirms an address added to an existing account. | |
| 171 | pub 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", | |
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 178 | &format!("{}/verify?token={token}", site(env)), |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 179 | "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. | |
| 185 | pub 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. | |
| 193 | pub 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", | |
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 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 look | 206 | ) |
| 207 | .await | |
| 208 | } | |
| 209 | ||
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 210 | /// An invite email: to make an account, or for an existing one to join a |
| 211 | /// workspace. | |
| 212 | pub 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. | |
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 226 | pub 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 quotas | 227 | 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 look | 230 | _ => "Accept invite".to_owned(), |
| 231 | }; | |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 232 | 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, | |
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 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 quotas | 246 | 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 look | 249 | ), |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 250 | }; |
| 251 | (subject, letter) | |
| 252 | } | |
| 253 | ||
| 254 | pub async fn send_invite(env: &Env, invite: &InviteEmail<'_>) -> Result<()> { | |
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 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 quotas | 256 | send(env, invite.to, &subject, &letter).await |
| 257 | } | |
| 258 | ||
| 259 | /// Where staff decide on access requests. | |
| 260 | pub const SUDO_WAITLIST: &str = "https://sudo.g1t.sh/invites?tab=waitlist"; | |
| 261 | ||
| 262 | /// The one confirmation someone gets after asking for access. | |
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 263 | pub 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 quotas | 264 | ( |
| 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, | |
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 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 quotas | 274 | }, |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 275 | ) |
| 276 | } | |
| 277 | ||
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 278 | pub async fn send_waitlist_confirmation(env: &Env, to: &str) -> Result<()> { |
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 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 quotas | 280 | send(env, to, &subject, &letter).await |
| 281 | } | |
| 282 | ||
| 283 | /// One access request, as a staff summary lists it. | |
| 284 | pub struct Requested { | |
| 285 | pub email: String, | |
| 286 | pub about: Option<String>, | |
| 287 | } | |
| 288 | ||
| 289 | /// The most requests one summary lists; the rest are counted. | |
| 290 | pub 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. | |
| 294 | pub 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 | ||
| 336 | pub 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 look | 341 | /// 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. | |
| 344 | pub 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 { | |
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 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 look | 357 | }; |
| 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 | ||
| 370 | /// The subject and first line of a repository invitation. | |
| 371 | pub fn repo_invite_wording(from: &str, repo: &str, role: &str, new_account: bool) -> (String, String) { | |
| 372 | let subject = format!("{from} invited you to {repo} on g1t"); | |
| 373 | let intro = if new_account { | |
| 374 | format!( | |
| 375 | "{from} invited you to collaborate on {repo} on g1t, with the {role} role. Accepting makes your g1t account and gives you access to {repo}." | |
| 376 | ) | |
| 377 | } else { | |
| 378 | format!("{from} invited you to collaborate on {repo} on g1t, with the {role} role.") | |
| 379 | }; | |
| 380 | (subject, intro) | |
| 381 | } | |
| 382 | ||
| 383 | /// The subject and first line of an invite email. | |
| 384 | pub fn invite_wording(from: Option<&str>, workspace: Option<&str>, joins_existing_account: bool) -> (String, String) { | |
| 385 | let who = from.unwrap_or("The g1t team"); | |
| 386 | match (workspace, joins_existing_account) { | |
| 387 | (Some(workspace), true) => ( | |
| 388 | format!("{who} invited you to {workspace} on g1t"), | |
| 389 | format!("{who} invited you to join the {workspace} workspace on g1t."), | |
| 390 | ), | |
| 391 | (Some(workspace), false) => ( | |
| 392 | format!("{who} invited you to {workspace} on g1t"), | |
| 393 | format!( | |
| 394 | "{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}." | |
| 395 | ), | |
| 396 | ), | |
| 397 | (None, _) => ( | |
| 398 | match from { | |
| 399 | Some(from) => format!("{from} invited you to g1t"), | |
| 400 | None => "Your invite to g1t".to_owned(), | |
| 401 | }, | |
| 402 | 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."), | |
| 403 | ), | |
| 404 | } | |
| 405 | } | |
| 406 | ||
| 407 | #[cfg(test)] | |
| 408 | mod tests { | |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 409 | use super::*; |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 410 | |
| 411 | #[test] | |
| 412 | fn html_is_escaped() { | |
| 413 | assert_eq!( | |
| 414 | escape("<a href=\"x\">Tom & Jerry's</a>"), | |
| 415 | "<a href="x">Tom & Jerry's</a>" | |
| 416 | ); | |
| 417 | assert_eq!(escape("https://g1t.sh/verify?token=ab12"), "https://g1t.sh/verify?token=ab12"); | |
| 418 | } | |
| 419 | ||
| 420 | #[test] | |
| 421 | fn invites_say_who_sent_them_and_what_they_are_for() { | |
| 422 | let (subject, intro) = invite_wording(Some("ada"), None, false); | |
| 423 | assert_eq!(subject, "ada invited you to g1t"); | |
| 424 | assert!(intro.starts_with("ada invited you to g1t")); | |
| 425 | let (subject, _) = invite_wording(None, None, false); | |
| 426 | assert_eq!(subject, "Your invite to g1t"); | |
| 427 | let (subject, intro) = invite_wording(Some("ada"), Some("acme"), true); | |
| 428 | assert_eq!(subject, "ada invited you to acme on g1t"); | |
| 429 | assert_eq!(intro, "ada invited you to join the acme workspace on g1t."); | |
| 430 | let (_, intro) = invite_wording(Some("ada"), Some("acme"), false); | |
| 431 | assert!(intro.contains("makes your account and joins you to acme")); | |
| 432 | } | |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 433 | |
| 434 | fn invite<'a>(note: Option<&'a str>, from: Option<&'a str>) -> InviteEmail<'a> { | |
| 435 | InviteEmail { | |
| 436 | to: "ada@example.com", | |
| 437 | from, | |
| 438 | workspace: Some("Flagon, Inc."), | |
| 439 | joins_existing_account: false, | |
| 440 | code: "g1t-abcd", | |
| 441 | days: 30, | |
| 442 | note, | |
| 443 | } | |
| 444 | } | |
| 445 | ||
| 446 | #[test] | |
| 447 | fn an_invite_links_to_its_page_and_carries_a_note() { | |
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 448 | 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 quotas | 449 | assert_eq!(subject, "The g1t team invited you to Flagon, Inc. on g1t"); |
| 450 | assert_eq!(letter.action.as_ref().unwrap().1, "https://g1t.sh/invite/g1t-abcd"); | |
| 451 | assert_eq!(letter.quotes, vec![("A note from the g1t team".to_owned(), "Welcome aboard <3".to_owned())]); | |
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 452 | let (text, html) = render(&letter, SITE); |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 453 | assert!(text.contains("> Welcome aboard <3")); |
| 454 | assert!(html.contains("Welcome aboard <3")); | |
| 455 | assert!(!html.contains("<3")); | |
| 456 | // No note, no quote; a blank note is no note. | |
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 457 | assert!(invite_letter(&invite(None, Some("Chase Pierce")), SITE).1.quotes.is_empty()); |
| 458 | assert!(invite_letter(&invite(Some(" "), Some("Chase Pierce")), SITE).1.quotes.is_empty()); | |
| 459 | 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 quotas | 460 | } |
| 461 | ||
| 462 | #[test] | |
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 463 | fn links_point_at_the_site_they_are_given() { |
| 464 | let (_, letter) = invite_letter(&invite(None, None), "http://localhost:8787"); | |
| 465 | assert_eq!(letter.action.as_ref().unwrap().1, "http://localhost:8787/invite/g1t-abcd"); | |
| 466 | let (text, html) = render(&letter, "http://localhost:8787"); | |
| 467 | assert!(html.contains("http://localhost:8787/brand/g1t-logo.png")); | |
| 468 | assert!(!text.contains("g1t.sh/") && !html.contains("https://g1t.sh")); | |
| 469 | let (_, letter) = waitlist_confirmation("http://localhost:8787"); | |
| 470 | assert!(letter.footer.contains("localhost:8787/register")); | |
| 471 | assert_eq!(bare("https://git.example.com"), "git.example.com"); | |
| 472 | } | |
| 473 | ||
| 474 | #[test] | |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 475 | fn the_waitlist_confirmation_promises_no_date() { |
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 476 | let (subject, letter) = waitlist_confirmation(SITE); |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 477 | assert_eq!(subject, "You're on the list for g1t"); |
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 478 | let (text, _) = render(&letter, SITE); |
| 479 | assert!(text.contains("g1t.sh/register")); | |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 480 | assert!(text.contains("we'll email you an invite")); |
| 481 | assert!(text.contains("can't say exactly when")); | |
| 482 | assert!(letter.action.is_none()); | |
| 483 | } | |
| 484 | ||
| 485 | #[test] | |
| 486 | fn staff_summaries_list_each_request_and_link_to_sudo() { | |
| 487 | let one = [Requested { email: "ada@example.com".into(), about: Some("A compiler <for> fun".into()) }]; | |
| 488 | let (subject, letter) = waitlist_summary(&one, 1); | |
| 489 | assert_eq!(subject, "g1t access request from ada@example.com"); | |
| 490 | assert_eq!(letter.paragraphs, vec!["Someone asked for access to g1t."]); | |
| 491 | assert_eq!(letter.action.as_ref().unwrap().1, SUDO_WAITLIST); | |
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 492 | let (_, html) = render(&letter, SITE); |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 493 | assert!(html.contains("A compiler <for> fun")); |
| 494 | ||
| 495 | let many: Vec<Requested> = (0..25).map(|n| Requested { email: format!("p{n}@example.com"), about: None }).collect(); | |
| 496 | let (subject, letter) = waitlist_summary(&many, 40); | |
| 497 | assert_eq!(subject, "25 new g1t access requests"); | |
| 498 | assert_eq!( | |
| 499 | letter.paragraphs[0], | |
| 500 | "25 people asked for access to g1t since the last summary. 40 requests are waiting in all." | |
| 501 | ); | |
| 502 | assert_eq!(letter.quotes.len(), SUMMARY_LISTS + 1); | |
| 503 | assert_eq!(letter.quotes[0].1, "(They did not say what they will build.)"); | |
| 504 | assert!(letter.quotes.last().unwrap().1.starts_with("5 more")); | |
| 505 | } | |
| 506 | ||
| 507 | /// Writes each email as HTML for a look in a browser: | |
| 508 | /// `G1T_WRITE_EMAILS=<dir> cargo test -p g1t-identity write_emails`. | |
| 509 | #[test] | |
| 510 | fn write_emails() { | |
| 511 | let Ok(dir) = std::env::var("G1T_WRITE_EMAILS") else { return }; | |
| 512 | let page = |name: &str, subject: &str, letter: &Letter| { | |
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 513 | let (_, html) = render(letter, SITE); |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 514 | std::fs::write( |
| 515 | format!("{dir}/{name}.html"), | |
| 516 | format!("<!doctype html><meta charset=utf-8><title>{}</title><body style=\"margin:0;background:#fff\">{html}", escape(subject)), | |
| 517 | ) | |
| 518 | .unwrap(); | |
| 519 | }; | |
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 520 | let (subject, letter) = waitlist_confirmation(SITE); |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 521 | page("waitlist-confirmation", &subject, &letter); |
| 522 | let requests = [ | |
| 523 | Requested { email: "ada@example.com".into(), about: Some("A compiler for a teaching language, with agents writing the test suite.".into()) }, | |
| 524 | Requested { email: "linus@example.com".into(), about: None }, | |
| 525 | ]; | |
| 526 | let (subject, letter) = waitlist_summary(&requests, 7); | |
| 527 | page("waitlist-summary", &subject, &letter); | |
| 528 | let (subject, letter) = invite_letter(&InviteEmail { | |
| 529 | to: "margaret@example.com", | |
| 530 | from: Some("Chase Pierce"), | |
| 531 | workspace: Some("Flagon, Inc."), | |
| 532 | joins_existing_account: false, | |
| 533 | code: "g1t-k7m2-q9xd-4hpw-abcd-0123-4567-89ef-ghjk", | |
| 534 | days: 30, | |
| 535 | note: None, | |
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 536 | }, SITE); |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 537 | page("workspace-invite", &subject, &letter); |
| 538 | let (subject, letter) = invite_letter(&InviteEmail { | |
| 539 | to: "ada@example.com", | |
| 540 | from: None, | |
| 541 | workspace: None, | |
| 542 | joins_existing_account: false, | |
| 543 | code: "g1t-k7m2-q9xd-4hpw-abcd-0123-4567-89ef-ghjk", | |
| 544 | days: 30, | |
| 545 | note: Some("Thanks for waiting. We would love to see the compiler."), | |
| Self-hosting: the clone pack cache on S3 (MinIO, expiring), the API and MCP on their own port with PUBLIC_URL-derived addresses across the site, API and mail, scheduler --once, and smoke.sh covering pull requests from branches and forks and the merge queue | 546 | }, SITE); |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 547 | page("waitlist-approved", &subject, &letter); |
| 548 | } | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 549 | } |