Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t.sh
73 linesCodeBlameRaw

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.

Merge account deletion: soft delete for 30 days, staff restore and purge, ghost for what remains (identity 0037)1//! An account purged (`user.deleted`, identity's `account_deletion.rs`):
2//! what it wrote stays where it is and shows as `ghost`, and it is taken
3//! off what it was asked to do.
4//!
5//! Its issues, pull requests, comments and reviews, plans and messages to
6//! agents keep their place and their words; their author becomes `ghost`
7//! (`usr_ghost`), and so does whoever asked g1t for an issue or pull
8//! request. It is no longer assigned to anything or asked to review, and
9//! review requests that reached it through a team are dropped. Stored
10//! rather than mapped when read, so every reader agrees.
11
12use g1t_contracts::account_deletion::{GHOST_ID, GHOST_USERNAME};
13
14/// Each statement takes the account's id as `?1` and its username as `?2`
15/// (`g1t_kit::user_deleted`). `ghost`'s id and name are written in.
16pub(crate) fn statements() -> Vec<String> {
17 let mut sql = Vec::new();
18 for table in ["issues", "pulls", "comments", "plans", "agent_messages"] {
19 sql.push(format!(
20 "UPDATE {table} SET author_id = '{GHOST_ID}', author_name = '{GHOST_USERNAME}' WHERE author_id = ?1"
21 ));
22 }
23 for table in ["issues", "pulls"] {
24 sql.push(format!(
25 "UPDATE {table} SET requested_by_id = '{GHOST_ID}', requested_by_name = '{GHOST_USERNAME}' WHERE requested_by_id = ?1"
26 ));
27 }
28 for (table, column) in [("issues", "assignees"), ("pulls", "assignees"), ("pulls", "reviewers")] {
29 sql.push(format!(
30 "UPDATE {table} SET {column} = (SELECT json_group_array(value) FROM json_each({table}.{column}) WHERE value <> ?2)
31 WHERE ?1 IS NOT NULL AND json_valid({column}) AND EXISTS (SELECT 1 FROM json_each({table}.{column}) WHERE value = ?2)"
32 ));
33 }
34 sql.push("DELETE FROM team_review_requests WHERE ?1 IS NOT NULL AND username = ?2".to_owned());
The work service coordinates work on a repository: sessions of people's own harnesses (start is idempotent on the harness's session id, every update or batch of entries is a heartbeat that renews the session's claims, a session reads as idle after 15 minutes and ends as timed_out after 2 hours), session entries recorded once per key and shown in the pull request's session when the session is on one (session_entries is rebuilt so an entry can belong to a session alone), advisory expiring claims on issues that are never locks (claiming tells you who else is on it and what the issue is blocked by; release, hand-off with a note, and expiry noticed on the next read), a writer for blocked_by on update_issue that refuses other repositories' numbers, the issue itself and cycles, and get_work, which gathers an issue's definition of done, claims, sessions, pull requests with their checks, mergeability, overlaps and queue place, blockers, the issues it blocks, decisions and recent coordination events. It publishes session.started, session.ended, work.claimed, work.released, work.claim_expired, work.handoff_requested, dependency.changed (when blocked_by changes, and when a blocker closes or has its pull request merged) and overlap.detected (once for each side when a push or a new pull request starts an overlap, again only after it cleared), and the contracts and the TypeScript mirror list them.35 // Its sessions and claims (coordination/) keep their place as ghost's,
36 // and a hand-off to it is to anyone now.
37 // A session's harness id is unique per person, so it goes.
38 sql.push(format!(
39 "UPDATE sessions SET actor_id = '{GHOST_ID}', actor_name = '{GHOST_USERNAME}', harness_session_id = NULL WHERE actor_id = ?1"
40 ));
41 sql.push(format!("UPDATE claims SET actor_id = '{GHOST_ID}', actor_name = '{GHOST_USERNAME}' WHERE actor_id = ?1"));
42 sql.push("UPDATE claims SET handoff_to = NULL WHERE ?1 IS NOT NULL AND handoff_to = ?2".to_owned());
Merge account deletion: soft delete for 30 days, staff restore and purge, ghost for what remains (identity 0037)43 sql
44}
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn everything_it_wrote_becomes_ghosts() {
52 let sql = statements();
53 for table in ["issues", "pulls", "comments", "plans", "agent_messages"] {
54 assert!(
55 sql.iter().any(|s| s.starts_with(&format!("UPDATE {table} SET author_id = 'usr_ghost', author_name = 'ghost'"))),
56 "{table}"
57 );
58 }
59 assert!(sql.iter().any(|s| s.contains("UPDATE pulls SET requested_by_id = 'usr_ghost'")));
60 assert!(sql.iter().any(|s| s.contains("UPDATE pulls SET reviewers")));
61 assert!(sql.iter().any(|s| s.contains("team_review_requests")));
62 }
63
64 #[test]
65 fn every_statement_takes_both_binds() {
66 // D1 refuses a bind a statement does not name: each names ?1, and
67 // the ones that need the username name ?2 as well.
68 for s in statements() {
69 assert!(s.contains("?1"), "{s}");
70 assert_eq!(g1t_kit::user_deleted::binds(&s, "usr_1", "ada").len(), if s.contains("?2") { 2 } else { 1 });
71 }
72 }
73}

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