From 74be11bf428b5431196f77fb3a49ab1bcbc2292e Mon Sep 17 00:00:00 2001 From: Kenneth Date: Thu, 4 Jun 2026 23:21:39 +0100 Subject: [PATCH] shenanigans --- src/api/issues.rs | 268 +++++++++--------- src/main.rs | 30 +- .../dashboard/pull_request_change_view.rs | 29 +- src/screen/diffops_playground.rs | 13 + src/storage.rs | 22 +- 5 files changed, 186 insertions(+), 176 deletions(-) diff --git a/src/api/issues.rs b/src/api/issues.rs index 92f0ddb..5c5b1ec 100644 --- a/src/api/issues.rs +++ b/src/api/issues.rs @@ -318,8 +318,8 @@ impl query::QueryFn for ListPullRequests { } let query_string = match self.filter { - | Some(filter) => format!("is:pr archived:false sort:updated-desc {}", filter), - | None => "is:pr archived:false sort:updated-desc".into(), + | Some(filter) => format!("is:pr archived:false sort:updated-desc {}", filter), + | None => "is:pr archived:false sort:updated-desc".into(), }; let gql = @@ -341,20 +341,20 @@ impl query::QueryFn for ListPullRequests { .flatten() .filter_map(|edge| { edge.node.and_then(|n| match n { - | PullRequestPaginationQuerySearchEdgesNode::PullRequest(p) => { - Some(PullRequest { - id: p.id.into(), - title: p.title.into(), - state: p.state, - is_draft: p.is_draft, - repo_slug: format!( - "{}/{}", - p.repository.owner.login, p.repository.name - ) - .into(), - }) - } - | _ => None, + | PullRequestPaginationQuerySearchEdgesNode::PullRequest(p) => { + Some(PullRequest { + id: p.id.into(), + title: p.title.into(), + state: p.state, + is_draft: p.is_draft, + repo_slug: format!( + "{}/{}", + p.repository.owner.login, p.repository.name + ) + .into(), + }) + } + | _ => None, }) }) .collect::>() @@ -399,43 +399,43 @@ impl query::QueryFn for FetchPullRequest { "missing 'node' field on PullRequestQuery response".into(), )) .and_then(|n| match n { - | PullRequestQueryNode::PullRequest(p) => { - let created_at = - chrono::DateTime::parse_from_rfc3339(&p.created_at).map_err(|err| { - api::Error::MalformedResponse(format!( - "invalid pull request createdAt {:?}: {err}", - p.created_at - )) - })?; + | PullRequestQueryNode::PullRequest(p) => { + let created_at = + chrono::DateTime::parse_from_rfc3339(&p.created_at).map_err(|err| { + api::Error::MalformedResponse(format!( + "invalid pull request createdAt {:?}: {err}", + p.created_at + )) + })?; - Ok(DetailedPullRequest { - id: Id(p.id.into()), - title: p.title.into(), - state: p.state, - is_draft: p.is_draft, - body: p.body.into(), - author: p.author.map(|it| api::user::Actor { - login: it.login.into(), - avatar_url: it.avatar_url.into(), - }), - base_repo_slug: p - .base_repository - .map(|it| it.name_with_owner.into()) - .unwrap_or_default(), - base_branch_name: p.base_ref_name.into(), - base_ref: p.base_ref_oid.into(), - head_repo_slug: p - .head_repository - .map(|it| it.name_with_owner.into()) - .unwrap_or_default(), - head_branch_name: p.head_ref_name.into(), - head_ref: p.head_ref_oid.into(), - created_at: Some(created_at), - }) - } - | _ => Err(api::Error::MalformedResponse( - "unexpected node type on PullRequestQuery".into(), - )), + Ok(DetailedPullRequest { + id: Id(p.id.into()), + title: p.title.into(), + state: p.state, + is_draft: p.is_draft, + body: p.body.into(), + author: p.author.map(|it| api::user::Actor { + login: it.login.into(), + avatar_url: it.avatar_url.into(), + }), + base_repo_slug: p + .base_repository + .map(|it| it.name_with_owner.into()) + .unwrap_or_default(), + base_branch_name: p.base_ref_name.into(), + base_ref: p.base_ref_oid.into(), + head_repo_slug: p + .head_repository + .map(|it| it.name_with_owner.into()) + .unwrap_or_default(), + head_branch_name: p.head_ref_name.into(), + head_ref: p.head_ref_oid.into(), + created_at: Some(created_at), + }) + } + | _ => Err(api::Error::MalformedResponse( + "unexpected node type on PullRequestQuery".into(), + )), }) } } @@ -477,7 +477,7 @@ impl query::QueryFn for FetchPullRequestFileTree { let data = { let gql = PullRequestFileTreeQuery::build_query(pull_request_file_tree_query::Variables { - id: self.id.clone().into(), + id: self.id.to_string(), first: self.first, }); @@ -494,12 +494,12 @@ impl query::QueryFn for FetchPullRequestFileTree { "missing 'node' field on PullRequestFileTreeQuery response".into(), )) .and_then(|node| match node { - | pull_request_file_tree_query::PullRequestFileTreeQueryNode::PullRequest( - pull_request, - ) => Ok(pull_request), - | _ => Err(api::Error::MalformedResponse( - "unexpected node type on PullRequestFileTreeQuery".into(), - )), + | pull_request_file_tree_query::PullRequestFileTreeQueryNode::PullRequest( + pull_request, + ) => Ok(pull_request), + | _ => Err(api::Error::MalformedResponse( + "unexpected node type on PullRequestFileTreeQuery".into(), + )), })?; Ok(pull_request @@ -513,25 +513,23 @@ impl query::QueryFn for FetchPullRequestFileTree { edge.node.map(|node| ChangedFile { cursor, change_type: match node.change_type { - | pull_request_file_tree_query::PatchStatus::ADDED => { - ChangeType::Added - } - | pull_request_file_tree_query::PatchStatus::MODIFIED => { - ChangeType::Modified - } - | pull_request_file_tree_query::PatchStatus::DELETED => { - ChangeType::Deleted - } - | pull_request_file_tree_query::PatchStatus::RENAMED => { - ChangeType::Renamed - } - | pull_request_file_tree_query::PatchStatus::COPIED => { - ChangeType::Copied - } - | pull_request_file_tree_query::PatchStatus::CHANGED => { - ChangeType::Changed - } - | _ => ChangeType::Changed, + | pull_request_file_tree_query::PatchStatus::ADDED => ChangeType::Added, + | pull_request_file_tree_query::PatchStatus::MODIFIED => { + ChangeType::Modified + } + | pull_request_file_tree_query::PatchStatus::DELETED => { + ChangeType::Deleted + } + | pull_request_file_tree_query::PatchStatus::RENAMED => { + ChangeType::Renamed + } + | pull_request_file_tree_query::PatchStatus::COPIED => { + ChangeType::Copied + } + | pull_request_file_tree_query::PatchStatus::CHANGED => { + ChangeType::Changed + } + | _ => ChangeType::Changed, }, additions: node.additions, deletions: node.deletions, @@ -578,11 +576,11 @@ impl query::QueryFn for FetchPullRequestTimeline { TimelineActor { kind: match on { - | actorFieldsOn::Bot => "Bot", - | actorFieldsOn::EnterpriseUserAccount => "EnterpriseUserAccount", - | actorFieldsOn::Mannequin => "Mannequin", - | actorFieldsOn::Organization => "Organization", - | actorFieldsOn::User => "User", + | actorFieldsOn::Bot => "Bot", + | actorFieldsOn::EnterpriseUserAccount => "EnterpriseUserAccount", + | actorFieldsOn::Mannequin => "Mannequin", + | actorFieldsOn::Organization => "Organization", + | actorFieldsOn::User => "User", } .into(), name: login, @@ -592,62 +590,62 @@ impl query::QueryFn for FetchPullRequestTimeline { fn normalize_assignee(actor: assigneeFields) -> TimelineActor { match actor { - | assigneeFields::Bot(actor) => TimelineActor { - kind: "Bot".into(), - name: actor.login, - avatar_url: Some(actor.avatar_url), - }, - | assigneeFields::Mannequin(actor) => TimelineActor { - kind: "Mannequin".into(), - name: actor.login, - avatar_url: Some(actor.avatar_url), - }, - | assigneeFields::Organization(actor) => TimelineActor { - kind: "Organization".into(), - name: actor.login, - avatar_url: Some(actor.avatar_url), - }, - | assigneeFields::User(actor) => TimelineActor { - kind: "User".into(), - name: actor.login, - avatar_url: Some(actor.avatar_url), - }, + | assigneeFields::Bot(actor) => TimelineActor { + kind: "Bot".into(), + name: actor.login, + avatar_url: Some(actor.avatar_url), + }, + | assigneeFields::Mannequin(actor) => TimelineActor { + kind: "Mannequin".into(), + name: actor.login, + avatar_url: Some(actor.avatar_url), + }, + | assigneeFields::Organization(actor) => TimelineActor { + kind: "Organization".into(), + name: actor.login, + avatar_url: Some(actor.avatar_url), + }, + | assigneeFields::User(actor) => TimelineActor { + kind: "User".into(), + name: actor.login, + avatar_url: Some(actor.avatar_url), + }, } } fn normalize_requested_reviewer(actor: requestedReviewerFields) -> TimelineActor { match actor { - | requestedReviewerFields::Bot(actor) => TimelineActor { - kind: "Bot".into(), - name: actor.login, - avatar_url: Some(actor.avatar_url), - }, - | requestedReviewerFields::Mannequin(actor) => TimelineActor { - kind: "Mannequin".into(), - name: actor.login, - avatar_url: Some(actor.avatar_url), - }, - | requestedReviewerFields::Team(actor) => TimelineActor { - kind: "Team".into(), - name: actor.name, - avatar_url: None, - }, - | requestedReviewerFields::User(actor) => TimelineActor { - kind: "User".into(), - name: actor.login, - avatar_url: Some(actor.avatar_url), - }, + | requestedReviewerFields::Bot(actor) => TimelineActor { + kind: "Bot".into(), + name: actor.login, + avatar_url: Some(actor.avatar_url), + }, + | requestedReviewerFields::Mannequin(actor) => TimelineActor { + kind: "Mannequin".into(), + name: actor.login, + avatar_url: Some(actor.avatar_url), + }, + | requestedReviewerFields::Team(actor) => TimelineActor { + kind: "Team".into(), + name: actor.name, + avatar_url: None, + }, + | requestedReviewerFields::User(actor) => TimelineActor { + kind: "User".into(), + name: actor.login, + avatar_url: Some(actor.avatar_url), + }, } } fn normalize_review_state(state: PullRequestReviewState) -> String { match state { - | PullRequestReviewState::PENDING => "PENDING", - | PullRequestReviewState::COMMENTED => "COMMENTED", - | PullRequestReviewState::APPROVED => "APPROVED", - | PullRequestReviewState::CHANGES_REQUESTED => "CHANGES_REQUESTED", - | PullRequestReviewState::DISMISSED => "DISMISSED", - | _ => "OTHER", + | PullRequestReviewState::PENDING => "PENDING", + | PullRequestReviewState::COMMENTED => "COMMENTED", + | PullRequestReviewState::APPROVED => "APPROVED", + | PullRequestReviewState::CHANGES_REQUESTED => "CHANGES_REQUESTED", + | PullRequestReviewState::DISMISSED => "DISMISSED", + | _ => "OTHER", } .into() } @@ -849,9 +847,9 @@ impl query::QueryFn for FetchPullRequestTimeline { let data = { let gql = PullRequestTimelineQuery::build_query(pull_request_timeline_query::Variables { - id: self.id.clone().into(), + id: self.id.to_string(), first: self.first, - after: self.after.clone(), + after: self.after.as_ref().map(|it| it.to_string()), }); let res = c.github_graphql_request(&gql)?.send().await?; @@ -867,10 +865,10 @@ impl query::QueryFn for FetchPullRequestTimeline { "missing 'node' field on PullRequestTimelineQuery response".into(), )) .and_then(|node| match node { - | PullRequestTimelineQueryNode::PullRequest(pull_request) => Ok(pull_request), - | _ => Err(api::Error::MalformedResponse( - "unexpected node type on PullRequestTimelineQuery".into(), - )), + | PullRequestTimelineQueryNode::PullRequest(pull_request) => Ok(pull_request), + | _ => Err(api::Error::MalformedResponse( + "unexpected node type on PullRequestTimelineQuery".into(), + )), })?; let timeline = pull_request.timeline_items; diff --git a/src/main.rs b/src/main.rs index 144ef6f..2b18a8d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,19 +81,19 @@ fn setup_application(cx: &mut gpui::App) { let start = resume_application_state(cx); match start { - | Start::FromScratch => { - let screen = setup_wizard::new(); - _ = setup_wizard::open_window(screen, cx); - } + | Start::FromScratch => { + let screen = setup_wizard::new(); + _ = setup_wizard::open_window(screen, cx); + } - | Start::FromSetup(state) => { - let screen = setup_wizard::from_saved(state); - _ = setup_wizard::open_window(screen, cx); - } + | Start::FromSetup(state) => { + let screen = setup_wizard::from_saved(state); + _ = setup_wizard::open_window(screen, cx); + } - | Start::FromSaved(_) => { - _ = dashboard::open_window(cx); - } + | Start::FromSaved(_) => { + _ = dashboard::open_window(cx); + } }; } @@ -128,11 +128,9 @@ fn resume_application_state(cx: &mut gpui::App) -> Start { let setup_status = setup_wizard::read_setup_status(); - println!("[main] setup status: {:?}", setup_status); - match setup_status { - | setup_wizard::SetupStatus::NotStarted => Start::FromScratch, - | setup_wizard::SetupStatus::InProgress(state) => Start::FromSetup(state), - | setup_wizard::SetupStatus::Completed => Start::FromSaved(state), + | setup_wizard::SetupStatus::NotStarted => Start::FromScratch, + | setup_wizard::SetupStatus::InProgress(state) => Start::FromSetup(state), + | setup_wizard::SetupStatus::Completed => Start::FromSaved(state), } } diff --git a/src/screen/dashboard/pull_request_change_view.rs b/src/screen/dashboard/pull_request_change_view.rs index 12c93ff..3abccc1 100644 --- a/src/screen/dashboard/pull_request_change_view.rs +++ b/src/screen/dashboard/pull_request_change_view.rs @@ -68,20 +68,20 @@ impl PullRequestChangeView { ) { let item = &self.file_tree_items[i]; match item.kind { - | FileTreeItemKind::Directory => { - self.file_tree_state - .toggle_directory(&item.full_path, &self.file_tree_items); - cx.notify(); - } - | FileTreeItemKind::File => { - self.selected_file_path = Some(Arc::clone(&item.full_path)); - self.file_tree_state.highlight_item(i); - self.diff_view.update(cx, |diff_view, cx| { - diff_view.show_diff_for_file(&item.full_path, cx); - }); - cx.focus_view(&self.diff_view, window); - cx.notify(); - } + | FileTreeItemKind::Directory => { + self.file_tree_state + .toggle_directory(&item.full_path, &self.file_tree_items); + cx.notify(); + } + | FileTreeItemKind::File => { + self.selected_file_path = Some(Arc::clone(&item.full_path)); + self.file_tree_state.highlight_item(i); + self.diff_view.update(cx, |diff_view, cx| { + diff_view.show_diff_for_file(&item.full_path, cx); + }); + cx.focus_view(&self.diff_view, window); + cx.notify(); + } } } } @@ -107,7 +107,6 @@ impl gpui::Render for PullRequestChangeView { .bg(theme.colors.surface_chrome) .border_r_1() .border_color(theme.colors.border_muted) - .p_1() .child( file_tree(self.file_tree_state.clone(), move |i, _, cx| { weak.read(cx).file_tree_items[i].clone() diff --git a/src/screen/diffops_playground.rs b/src/screen/diffops_playground.rs index 74241eb..c6f6128 100644 --- a/src/screen/diffops_playground.rs +++ b/src/screen/diffops_playground.rs @@ -15,6 +15,13 @@ use crate::{ util::diff::{ContentDiff, DiffLine, Op, diff_content}, }; +const PR_KWDONOVEM85_API_REPO_BASE: &str = include_str!( + "../../fixtures/github/repo.file_content/kennethnym/novem/5e8745bfcc0c90c226d3c6af84226d6d4a5ec2d1/src/api/repo.rs" +); +const PR_KWDONOVEM85_API_REPO_HEAD: &str = include_str!( + "../../fixtures/github/repo.file_content/kennethnym/novem/13af7d0b48a6ce0b22d48c9b6c1c78dfcd94e6a0/src/api/repo.rs" +); + pub(crate) fn is_enabled() -> bool { match std::env::var("NOVEM_DIFFOPS_PLAYGROUND") { | Ok(value) => matches!(value.as_str(), "1" | "true" | "TRUE" | "yes" | "on"), @@ -361,6 +368,12 @@ fn fetch() { } "#, ), + DiffCase::new( + "PR_kwDONovem85 src/api/repo.rs", + "Fixture diff for feat(repo): add cached repository query for titlebar picker. Base 5e8745bfcc0c90c226d3c6af84226d6d4a5ec2d1 to head 13af7d0b48a6ce0b22d48c9b6c1c78dfcd94e6a0.", + PR_KWDONOVEM85_API_REPO_BASE, + PR_KWDONOVEM85_API_REPO_HEAD, + ), ] } diff --git a/src/storage.rs b/src/storage.rs index 83b7c5d..857e3cc 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -16,15 +16,15 @@ pub(crate) struct PersistedState { pub(crate) fn data_dir_path() -> std::path::PathBuf { match std::env::consts::OS { - | "macos" => std::env::home_dir() - .unwrap() - .join("Library") - .join("Application Support") - .join("novem"), - | _ => unimplemented!( - "data_dir_path is unimplemented for OS: {}", - std::env::consts::OS - ), + | "macos" => std::env::home_dir() + .unwrap() + .join("Library") + .join("Application Support") + .join("novem"), + | _ => unimplemented!( + "data_dir_path is unimplemented for OS: {}", + std::env::consts::OS + ), } } @@ -67,7 +67,9 @@ pub(crate) async fn load_auth_tokens( .await .ok()? .and_then(|(_, password)| String::from_utf8(password).ok()) - .map(|access_token| api::AuthTokens { access_token }) + .map(|access_token| api::AuthTokens { + access_token: access_token.into(), + }) } }