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.

Commit

CLI: work list and view name a deleted origin repository

A work item whose origin repository was deleted before work items kept no path, so its repos column was blank. It now says "deleted repository", as the web does.

G1T-Session:
ses_01m56vafhge7ttrgs5288dpxvb
syntaqxcommitted Parent3a83e91Browse files
1 file+23−30/1 viewed
+23−3
180180 print_list(&ctx.out, &items)
181181 }
182182
183+/// What a linked repository that is gone, with no path kept, is called (the web's `DELETED_REPO`).
184+const DELETED_REPO: &str = "deleted repository";
185+
186+/// A linked repository's path, or "deleted repository" when it was deleted before work items and kept none.
187+fn repo_path(repo: &Value) -> &str {
188+ repo["path"].as_str().filter(|path| !path.is_empty()).unwrap_or(DELETED_REPO)
189+}
190+
183191 /// A work item's repositories, short: the first, and `+2` for the rest.
184192 fn repos_cell(item: &Value) -> String {
185− let paths: Vec<&str> = item["repos"].as_array().into_iter().flatten().filter_map(|r| r["path"].as_str()).collect();
193+ let paths: Vec<&str> = item["repos"].as_array().into_iter().flatten().map(repo_path).collect();
186194 match paths.as_slice() {
187195 [] => String::new(),
188196 [one] => (*one).to_owned(),
349357 .into_iter()
350358 .flatten()
351359 .filter(|r| r["role"] == "target" && r["landed"] != true)
352− .filter_map(|r| r["path"].as_str().map(str::to_owned))
360+ .map(|r| repo_path(r).to_owned())
353361 .collect()
354362 }
355363
541549 for repo in repos {
542550 let landed = if repo["landed"] == true { format!(" {}", out.green("landed")) } else { String::new() };
543551 let legacy = repo["legacy_number"].as_u64().map(|n| out.dim(&format!(" (was #{n} there)"))).unwrap_or_default();
544− println!(" {} {}{landed}{legacy}", s(repo, "path"), out.dim(s(repo, "role")));
552+ let path = repo_path(repo);
553+ let path = if path == DELETED_REPO { out.dim(path) } else { path.to_owned() };
554+ println!(" {path} {}{landed}{legacy}", out.dim(s(repo, "role")));
545555 for pull in list_of(repo, "pulls") {
546556 println!(" {}", pull_line(out, pull));
547557 for overlap in list_of(pull, "overlaps") {
12031213 }
12041214
12051215 #[test]
1216+ fn a_repository_deleted_before_work_items_is_named_so() {
1217+ // Its link kept no path: the column says what it was, not nothing.
1218+ let item = json!({ "repos": [{ "path": "", "role": "origin" }] });
1219+ assert_eq!(repos_cell(&item), "deleted repository");
1220+ let item = json!({ "repos": [{ "path": null, "role": "origin" }, { "path": "acme/api", "role": "target" }] });
1221+ assert_eq!(repos_cell(&item), "deleted repository +1");
1222+ assert_eq!(repo_path(&json!({ "path": "acme/web" })), "acme/web");
1223+ }
1224+
1225+ #[test]
12061226 fn blocking_adds_and_unblocking_removes() {
12071227 assert_eq!(blocked_set(12, &[9], &[10, 9], true).unwrap(), vec![9, 10]);
12081228 assert_eq!(blocked_set(12, &[9, 10], &[9], false).unwrap(), vec![10]);

Comments

Sign in to comment.