g1t/services/webhooks/src/rename.rs
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.
| Agents and memory, checks and conflicts, profiles, slug renames, custom domains | 1 | //! A workspace renamed: rows kept under its old slug move to the one it |
| 2 | //! has now. See `g1t_kit::rename`. | |
| 3 | ||
| 4 | /// `?1` is the current slug, `?2` a stale one. | |
| 5 | pub const STATEMENTS: &[&str] = &[ | |
| 6 | "UPDATE hooks SET workspace = ?1 WHERE workspace = ?2", | |
| 7 | "UPDATE hooks SET repo = ?1 || substr(repo, length(?2) + 1) WHERE substr(repo, 1, length(?2) + 1) = ?2 || '/'", | |
| 8 | "UPDATE repo_names SET namespace = ?1 WHERE namespace = ?2", | |
| 9 | ]; | |
| 10 | ||
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 11 | /// A repository renamed or transferred (see `g1t_kit::transfer`): its own |
| 12 | /// webhooks go with it, and its payloads name it by its new path. After a | |
| 13 | /// transfer the old workspace's webhooks stop hearing about it; the new | |
| 14 | /// one's start. | |
| 15 | pub const TRANSFERRED: &[&str] = &[ | |
| 16 | "UPDATE hooks SET workspace = ?3, repo = ?1 WHERE scope = 'repo' AND repo_id = ?5", | |
| 17 | "UPDATE repo_names SET namespace = ?3, name = ?6 WHERE repo_id = ?5", | |
| 18 | ]; | |
| 19 | ||
| 20 | /// A repository purged (see `g1t_kit::lifecycle`), once its last event is | |
| 21 | /// delivered: its own webhooks and what was sent to them go. `?1` its id. | |
| 22 | /// What its workspace's webhooks were sent stays, as their history. | |
| 23 | pub const PURGED: &[&str] = &[ | |
| 24 | "DELETE FROM deliveries WHERE hook_id IN (SELECT id FROM hooks WHERE scope = 'repo' AND repo_id = ?1)", | |
| 25 | "DELETE FROM hooks WHERE scope = 'repo' AND repo_id = ?1", | |
| 26 | "DELETE FROM repo_names WHERE repo_id = ?1", | |
| 27 | ]; | |
| 28 | ||
| 29 | /// A workspace deleted: its own webhooks go. `?1` its slug. | |
| 30 | pub const DELETED: &[&str] = &["DELETE FROM hooks WHERE scope = 'workspace' AND workspace = ?1"]; | |
| 31 | ||
| Agents and memory, checks and conflicts, profiles, slug renames, custom domains | 32 | #[cfg(test)] |
| 33 | mod tests { | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 34 | use super::{DELETED, PURGED, STATEMENTS, TRANSFERRED}; |
| Agents and memory, checks and conflicts, profiles, slug renames, custom domains | 35 | |
| 36 | #[test] | |
| 37 | fn every_statement_takes_the_two_slugs() { | |
| 38 | for sql in STATEMENTS { | |
| 39 | assert_eq!(g1t_kit::rename::parameters(sql), 2, "{sql}"); | |
| 40 | } | |
| 41 | } | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 42 | |
| 43 | #[test] | |
| 44 | fn transfer_and_deletion_statements_take_what_they_name() { | |
| 45 | for sql in TRANSFERRED { | |
| 46 | assert!((1..=7).contains(&g1t_kit::transfer::parameters(sql)), "{sql}"); | |
| 47 | } | |
| 48 | for sql in PURGED { | |
| 49 | assert_eq!(g1t_kit::transfer::parameters(sql), 1, "{sql}"); | |
| 50 | } | |
| 51 | for sql in DELETED { | |
| 52 | assert_eq!(g1t_kit::rename::parameters(sql), 1, "{sql}"); | |
| 53 | } | |
| 54 | } | |
| Agents and memory, checks and conflicts, profiles, slug renames, custom domains | 55 | } |