g1t/services/actions/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 settings SET owner = ?1 WHERE scope = 'workspace' AND owner = ?2", | |
| 7 | "UPDATE jobs SET namespace = ?1 WHERE namespace = ?2", | |
| 8 | "UPDATE workflows SET repo = ?1 || substr(repo, length(?2) + 1) WHERE substr(repo, 1, length(?2) + 1) = ?2 || '/'", | |
| 9 | "UPDATE runs SET repo = ?1 || substr(repo, length(?2) + 1) WHERE substr(repo, 1, length(?2) + 1) = ?2 || '/'", | |
| 10 | ]; | |
| 11 | ||
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 12 | /// A repository renamed or transferred (see `g1t_kit::transfer`): its |
| 13 | /// workflows, its runs and their jobs go with it. Its own secrets and | |
| 14 | /// variables are kept by its id (or its project's), so they go with it | |
| 15 | /// too; the old workspace's stop reaching it. A workspace's rows name the | |
| 16 | /// projects they reach by slug, not repositories, so a rename leaves them. | |
| 17 | pub const TRANSFERRED: &[&str] = &[ | |
| 18 | "UPDATE workflows SET repo = ?1 WHERE repo_id = ?5 AND repo = ?2", | |
| 19 | "UPDATE runs SET repo = ?1 WHERE repo_id = ?5 AND repo = ?2", | |
| 20 | "UPDATE jobs SET namespace = ?3 WHERE repo_id = ?5 AND namespace = ?4", | |
| 21 | ]; | |
| 22 | ||
| 23 | /// A repository purged (see `g1t_kit::lifecycle`): its workflows, runs, | |
| 24 | /// jobs and their logs go, and secrets and variables still kept under its | |
| 25 | /// id (from before projects held them). `?1` its id. A project's own rows | |
| 26 | /// stay with the project. | |
| 27 | pub const PURGED: &[&str] = &[ | |
| 28 | "DELETE FROM logs WHERE job_id IN (SELECT id FROM jobs WHERE repo_id = ?1)", | |
| 29 | "DELETE FROM jobs WHERE repo_id = ?1", | |
| 30 | "DELETE FROM runs WHERE repo_id = ?1", | |
| 31 | "DELETE FROM workflows WHERE repo_id = ?1", | |
| 32 | "DELETE FROM synced WHERE repo_id = ?1", | |
| 33 | "DELETE FROM settings WHERE scope <> 'workspace' AND owner = ?1", | |
| 34 | ]; | |
| 35 | ||
| 36 | /// A workspace deleted: its own secrets and variables go. `?1` its slug. | |
| 37 | pub const DELETED: &[&str] = &["DELETE FROM settings WHERE scope = 'workspace' AND owner = ?1"]; | |
| 38 | ||
| Agents and memory, checks and conflicts, profiles, slug renames, custom domains | 39 | #[cfg(test)] |
| 40 | mod tests { | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 41 | use super::{DELETED, PURGED, STATEMENTS, TRANSFERRED}; |
| Agents and memory, checks and conflicts, profiles, slug renames, custom domains | 42 | |
| 43 | #[test] | |
| 44 | fn every_statement_takes_the_two_slugs() { | |
| 45 | for sql in STATEMENTS { | |
| 46 | assert_eq!(g1t_kit::rename::parameters(sql), 2, "{sql}"); | |
| 47 | } | |
| 48 | } | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 49 | |
| 50 | #[test] | |
| 51 | fn transfer_and_deletion_statements_take_what_they_name() { | |
| 52 | for sql in TRANSFERRED { | |
| 53 | assert!((1..=5).contains(&g1t_kit::transfer::parameters(sql)), "{sql}"); | |
| 54 | } | |
| 55 | for sql in DELETED { | |
| 56 | assert_eq!(g1t_kit::rename::parameters(sql), 1, "{sql}"); | |
| 57 | } | |
| 58 | for sql in PURGED { | |
| 59 | assert_eq!(g1t_kit::transfer::parameters(sql), 1, "{sql}"); | |
| 60 | } | |
| 61 | } | |
| Agents and memory, checks and conflicts, profiles, slug renames, custom domains | 62 | } |