diff --git a/apps/desktop/src/lib/branch/BranchPreviewHeader.svelte b/apps/desktop/src/lib/branch/BranchPreviewHeader.svelte index e4e9b7e0f2..4c181458af 100644 --- a/apps/desktop/src/lib/branch/BranchPreviewHeader.svelte +++ b/apps/desktop/src/lib/branch/BranchPreviewHeader.svelte @@ -12,7 +12,7 @@ import Modal from '@gitbutler/ui/Modal.svelte'; import Tooltip from '@gitbutler/ui/Tooltip.svelte'; import type { PullRequest } from '$lib/forge/interface/types'; - import type { Branch, ForgeIdentifier } from '$lib/vbranches/types'; + import type { Branch } from '$lib/vbranches/types'; import { goto } from '$app/navigation'; export let localBranch: Branch | undefined; @@ -105,13 +105,10 @@ remoteBranch?.name ); } else { - let forgeId: ForgeIdentifier | undefined = pr - ? { type: 'GitHub', subject: { prNumber: pr.number } } - : undefined; await branchController.createvBranchFromBranch( remoteBranch!.name, undefined, - forgeId + pr?.number ); } goto(`/${project.id}/board`); diff --git a/apps/desktop/src/lib/branch/SeriesHeader.svelte b/apps/desktop/src/lib/branch/SeriesHeader.svelte index c1bd268490..f9b1cbf3e5 100644 --- a/apps/desktop/src/lib/branch/SeriesHeader.svelte +++ b/apps/desktop/src/lib/branch/SeriesHeader.svelte @@ -79,7 +79,7 @@ const prs = $derived(prStore ? $prStore : undefined); const listedPr = $derived(prs?.find((pr) => pr.sourceBranch === upstreamName)); - const prNumber = $derived(currentSeries.forgeId?.subject.prNumber || listedPr?.number); + const prNumber = $derived(currentSeries.prNumber || listedPr?.number); const prMonitor = $derived(prNumber ? $prService?.prMonitor(prNumber) : undefined); const pr = $derived(prMonitor?.pr); diff --git a/apps/desktop/src/lib/components/PullRequestPreview.svelte b/apps/desktop/src/lib/components/PullRequestPreview.svelte index 2af08f2d44..e76274b40e 100644 --- a/apps/desktop/src/lib/components/PullRequestPreview.svelte +++ b/apps/desktop/src/lib/components/PullRequestPreview.svelte @@ -69,7 +69,7 @@ await branchController.createvBranchFromBranch( `refs/remotes/${remoteName}/${pullrequest.sourceBranch}`, undefined, - { type: 'GitHub', subject: { prNumber: pullrequest.number } } + pullrequest.number ); await virtualBranchService.refresh(); diff --git a/apps/desktop/src/lib/pr/PrDetailsModal.svelte b/apps/desktop/src/lib/pr/PrDetailsModal.svelte index 26cdcd2e18..f0ed92979a 100644 --- a/apps/desktop/src/lib/pr/PrDetailsModal.svelte +++ b/apps/desktop/src/lib/pr/PrDetailsModal.svelte @@ -211,10 +211,11 @@ upstreamName: upstreamBranchName }); if (props.type === 'preview-series') { - await branchController.updateSeriesForgeId(props.stackId, props.currentSeries.name, { - type: 'GitHub', - subject: { prNumber: pr.number } - }); + await branchController.updateSeriesPrNumber( + props.stackId, + props.currentSeries.name, + pr.number + ); } } catch (err: any) { console.error(err); diff --git a/apps/desktop/src/lib/vbranches/branchController.ts b/apps/desktop/src/lib/vbranches/branchController.ts index 12f8450c0a..6d86767a41 100644 --- a/apps/desktop/src/lib/vbranches/branchController.ts +++ b/apps/desktop/src/lib/vbranches/branchController.ts @@ -5,7 +5,7 @@ import posthog from 'posthog-js'; import type { BaseBranchService } from '$lib/baseBranch/baseBranchService'; import type { BranchListingService } from '$lib/branches/branchListing'; import type { RemoteBranchService } from '$lib/stores/remoteBranches'; -import type { BranchPushResult, ForgeIdentifier, Hunk, LocalFile, StackOrder } from './types'; +import type { BranchPushResult, Hunk, LocalFile, StackOrder } from './types'; import type { VirtualBranchService } from './virtualBranch'; export type CommitIdOrChangeId = { CommitId: string } | { ChangeId: string }; @@ -166,19 +166,15 @@ export class BranchController { * This is useful for storing for example the Pull Request Number for a branch. * @param stackId The stack ID to update. * @param headName The branch name to update. - * @param forgeId New forge id to be set for the branch (overrides current state). Setting to undefined will remove the forge id. + * @param prNumber New pull request number to be set for the branch. */ - async updateSeriesForgeId( - stackId: string, - headName: string, - forgeId: ForgeIdentifier | undefined - ) { + async updateSeriesPrNumber(stackId: string, headName: string, prNumber: number | undefined) { try { - await invoke('update_series_forge_id', { + await invoke('update_series_pr_number', { projectId: this.projectId, stackId, headName, - forgeId + prNumber }); } catch (err) { showError('Failed to update branch forge ids', err); @@ -454,14 +450,14 @@ export class BranchController { async createvBranchFromBranch( branch: string, remote: string | undefined = undefined, - forgeId: ForgeIdentifier | undefined = undefined + prNumber: number | undefined = undefined ) { try { await invoke('create_virtual_branch_from_branch', { projectId: this.projectId, branch, remote, - forgeId + prNumber }); } catch (err) { showError('Failed to create virtual branch', err); diff --git a/apps/desktop/src/lib/vbranches/types.ts b/apps/desktop/src/lib/vbranches/types.ts index c8dcf7bfd7..c58a07a4ce 100644 --- a/apps/desktop/src/lib/vbranches/types.ts +++ b/apps/desktop/src/lib/vbranches/types.ts @@ -437,7 +437,7 @@ export class PatchSeries { * A list of identifiers for the review unit at possible forges (eg. Pull Request). * The list is empty if there is no review units, eg. no Pull Request has been created. */ - forgeId?: ForgeIdentifier | undefined; + prNumber?: number | undefined; /** * Archived represents the state when series/branch has been integrated and is below the merge base of the branch. * This would occur when the branch has been merged at the remote and the workspace has been updated with that change. @@ -473,13 +473,6 @@ export interface GitHubIdentifier { prNumber: number; } -/** - * @desc Represents identifiers for the series at possible forges, eg. GitHub PR numbers. - * @property type - The forge identifier string. - * @property subject - The selected for forges subject information. - */ -export type ForgeIdentifier = { type: 'GitHub'; subject: GitHubIdentifier }; - /** * @desc Represents the order of series (branches) and changes (commits) in a stack. * @property series - The series are ordered from newest to oldest (most recent stacks go first). diff --git a/crates/gitbutler-branch-actions/src/actions.rs b/crates/gitbutler-branch-actions/src/actions.rs index ae1f7f59b4..8f67b08553 100644 --- a/crates/gitbutler-branch-actions/src/actions.rs +++ b/crates/gitbutler-branch-actions/src/actions.rs @@ -28,7 +28,6 @@ use gitbutler_project::{FetchResult, Project}; use gitbutler_reference::{ReferenceName, Refname, RemoteRefname}; use gitbutler_repo::RepositoryExt; use gitbutler_repo_actions::RepoActionsExt; -use gitbutler_stack::ForgeIdentifier; use gitbutler_stack::{BranchOwnershipClaims, StackId}; use std::path::PathBuf; use tracing::instrument; @@ -516,7 +515,7 @@ pub fn create_virtual_branch_from_branch( project: &Project, branch: &Refname, remote: Option, - forge_id: Option, + pr_number: Option, ) -> Result { let ctx = open_with_verify(project)?; assure_open_workspace_mode(&ctx) @@ -524,7 +523,7 @@ pub fn create_virtual_branch_from_branch( let branch_manager = ctx.branch_manager(); let mut guard = project.exclusive_worktree_access(); branch_manager - .create_virtual_branch_from_branch(branch, remote, forge_id, guard.write_permission()) + .create_virtual_branch_from_branch(branch, remote, pr_number, guard.write_permission()) .map_err(Into::into) } diff --git a/crates/gitbutler-branch-actions/src/branch_manager/branch_creation.rs b/crates/gitbutler-branch-actions/src/branch_manager/branch_creation.rs index 047f137983..1e01f4ff26 100644 --- a/crates/gitbutler-branch-actions/src/branch_manager/branch_creation.rs +++ b/crates/gitbutler-branch-actions/src/branch_manager/branch_creation.rs @@ -14,7 +14,7 @@ use gitbutler_repo::{ LogUntil, RepositoryExt, }; use gitbutler_repo_actions::RepoActionsExt; -use gitbutler_stack::{BranchOwnershipClaims, ForgeIdentifier, Stack, StackId}; +use gitbutler_stack::{BranchOwnershipClaims, Stack, StackId}; use gitbutler_time::time::now_since_unix_epoch_ms; use tracing::instrument; @@ -124,7 +124,7 @@ impl BranchManager<'_> { &self, target: &Refname, upstream_branch: Option, - forge_id: Option, + pr_number: Option, perm: &mut WorktreeWritePermission, ) -> Result { // only set upstream if it's not the default target @@ -252,8 +252,8 @@ impl BranchManager<'_> { ) }; - if let (Some(forge_id), Some(head)) = (forge_id, branch.heads().last()) { - branch.set_forge_id(self.ctx, head, Some(forge_id))?; + if let (Some(pr_number), Some(head)) = (pr_number, branch.heads().last()) { + branch.set_pr_number(self.ctx, head, Some(pr_number))?; } branch.set_stack_head(self.ctx, head_commit.id(), Some(head_commit_tree.id()))?; self.ctx.add_branch_reference(&branch)?; diff --git a/crates/gitbutler-branch-actions/src/stack.rs b/crates/gitbutler-branch-actions/src/stack.rs index 0cd5b1f3a4..775e892f8f 100644 --- a/crates/gitbutler-branch-actions/src/stack.rs +++ b/crates/gitbutler-branch-actions/src/stack.rs @@ -8,7 +8,7 @@ use gitbutler_oplog::{OplogExt, SnapshotExt}; use gitbutler_project::Project; use gitbutler_reference::normalize_branch_name; use gitbutler_repo_actions::RepoActionsExt; -use gitbutler_stack::{Branch, CommitOrChangeId, ForgeIdentifier, PatchReferenceUpdate, Series}; +use gitbutler_stack::{Branch, CommitOrChangeId, PatchReferenceUpdate, Series}; use gitbutler_stack::{Stack, StackId, Target}; use serde::{Deserialize, Serialize}; @@ -52,7 +52,7 @@ pub fn create_series( target: target_patch, name: normalized_head_name, description: req.description, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }, req.preceding_head, @@ -91,7 +91,7 @@ pub fn remove_series(project: &Project, branch_id: StackId, head_name: String) - stack.remove_series(ctx, head_name) } -/// Updates the name an existing series in the stack and resets the forge_id to None. +/// Updates the name an existing series in the stack and resets the pr_number to None. /// Same invariants as `create_series` apply. /// If the series have been pushed to a remote, the name can not be changed as it corresponds to a remote ref. pub fn update_series_name( @@ -153,21 +153,21 @@ pub fn update_series_description( /// - The stack has not been initialized /// - The project is not in workspace mode /// - Persisting the changes failed -pub fn update_series_forge_id( +pub fn update_series_pr_number( project: &Project, stack_id: StackId, head_name: String, - forge_id: Option, + pr_number: Option, ) -> Result<()> { let ctx = &open_with_verify(project)?; let mut guard = project.exclusive_worktree_access(); let _ = ctx.project().create_snapshot( - SnapshotDetails::new(OperationKind::UpdateDependentBranchDescription), + SnapshotDetails::new(OperationKind::UpdateDependentBranchPrNumber), guard.write_permission(), ); assure_open_workspace_mode(ctx).context("Requires an open workspace mode")?; let mut stack = ctx.project().virtual_branches().get_branch(stack_id)?; - stack.set_forge_id(ctx, &head_name, forge_id) + stack.set_pr_number(ctx, &head_name, pr_number) } /// Pushes all series in the stack to the remote. @@ -320,7 +320,7 @@ pub(crate) fn stack_series( upstream_reference, patches, upstream_patches, - forge_id: series.head.forge_id, + pr_number: series.head.pr_number, archived: series.head.archived, }); } diff --git a/crates/gitbutler-branch-actions/src/virtual.rs b/crates/gitbutler-branch-actions/src/virtual.rs index 2e11a2c9e5..976ea8fb13 100644 --- a/crates/gitbutler-branch-actions/src/virtual.rs +++ b/crates/gitbutler-branch-actions/src/virtual.rs @@ -29,8 +29,7 @@ use gitbutler_repo::{ }; use gitbutler_repo_actions::RepoActionsExt; use gitbutler_stack::{ - reconcile_claims, BranchOwnershipClaims, ForgeIdentifier, Stack, StackId, Target, - VirtualBranchesHandle, + reconcile_claims, BranchOwnershipClaims, Stack, StackId, Target, VirtualBranchesHandle, }; use gitbutler_time::time::now_since_unix_epoch_ms; use serde::Serialize; @@ -97,9 +96,8 @@ pub struct PatchSeries { pub patches: Vec, /// List of patches that only exist on the upstream branch pub upstream_patches: Vec, - /// A list of identifiers for the review unit at possible forges (eg. Pull Request). - /// The list is empty if there is no review units, eg. no Pull Request has been created. - pub forge_id: Option, + /// The pull request associated with the branch, or None if a pull request has not been created. + pub pr_number: Option, /// Archived represents the state when series/branch has been integrated and is below the merge base of the branch. /// This would occur when the branch has been merged at the remote and the workspace has been updated with that change. pub archived: bool, diff --git a/crates/gitbutler-branch-actions/tests/virtual_branches/create_virtual_branch_from_branch.rs b/crates/gitbutler-branch-actions/tests/virtual_branches/create_virtual_branch_from_branch.rs index 8a92fc1109..a9321285ef 100644 --- a/crates/gitbutler-branch-actions/tests/virtual_branches/create_virtual_branch_from_branch.rs +++ b/crates/gitbutler-branch-actions/tests/virtual_branches/create_virtual_branch_from_branch.rs @@ -1,6 +1,5 @@ use gitbutler_branch::BranchCreateRequest; use gitbutler_reference::LocalRefname; -use gitbutler_stack::{ForgeIdentifier, GitHubIdentifier}; use super::*; @@ -51,7 +50,7 @@ fn integration() { project, &branch_name, None, - Some(ForgeIdentifier::GitHub(GitHubIdentifier { pr_number: 123 })), + Some(123), ) .unwrap(); @@ -101,10 +100,7 @@ fn integration() { .find(|branch| branch.id == branch_id) .unwrap(); - assert_eq!( - branch.series.first().unwrap().forge_id, - Some(ForgeIdentifier::GitHub(GitHubIdentifier { pr_number: 123 })) - ); + assert_eq!(branch.series.first().unwrap().pr_number, Some(123)); assert!(branch.commits[0].is_remote); assert!(branch.commits[0].is_integrated); diff --git a/crates/gitbutler-oplog/src/entry.rs b/crates/gitbutler-oplog/src/entry.rs index 3180253cc1..5a1ea66b64 100644 --- a/crates/gitbutler-oplog/src/entry.rs +++ b/crates/gitbutler-oplog/src/entry.rs @@ -161,7 +161,7 @@ pub enum OperationKind { RemoveDependentBranch, UpdateDependentBranchName, UpdateDependentBranchDescription, - UpdateDependentBranchForgeId, + UpdateDependentBranchPrNumber, #[default] Unknown, } diff --git a/crates/gitbutler-stack/src/heads.rs b/crates/gitbutler-stack/src/heads.rs index b0255b3162..1598f1764f 100644 --- a/crates/gitbutler-stack/src/heads.rs +++ b/crates/gitbutler-stack/src/heads.rs @@ -145,14 +145,14 @@ mod test { target: CommitOrChangeId::ChangeId("328447a2-08aa-4c4d-a1bc-08d5cd82bcd4".to_string()), name: "kv-branch-3".to_string(), description: None, - forge_id: None, + pr_number: None, archived: true, }; let head_2 = Branch { target: CommitOrChangeId::ChangeId("11609175-039d-44ee-9d4a-6baa9ad2a750".to_string()), name: "more-on-top".to_string(), description: None, - forge_id: None, + pr_number: None, archived: false, }; let existing_heads = vec![head_1_archived.clone(), head_2.clone()]; @@ -160,7 +160,7 @@ mod test { target: CommitOrChangeId::ChangeId("11609175-039d-44ee-9d4a-6baa9ad2a750".to_string()), name: "abcd".to_string(), description: None, - forge_id: None, + pr_number: None, archived: false, }; let patches = vec![ diff --git a/crates/gitbutler-stack/src/lib.rs b/crates/gitbutler-stack/src/lib.rs index 3ad0ff55af..54111ea560 100644 --- a/crates/gitbutler-stack/src/lib.rs +++ b/crates/gitbutler-stack/src/lib.rs @@ -17,4 +17,4 @@ pub use series::Series; pub use stack::{commit_by_oid_or_change_id, CommitsForId, PatchReferenceUpdate, TargetUpdate}; mod patch_reference; -pub use patch_reference::{Branch, CommitOrChangeId, ForgeIdentifier, GitHubIdentifier}; +pub use patch_reference::{Branch, CommitOrChangeId}; diff --git a/crates/gitbutler-stack/src/patch_reference.rs b/crates/gitbutler-stack/src/patch_reference.rs index dbfdcf2813..9dd04121af 100644 --- a/crates/gitbutler-stack/src/patch_reference.rs +++ b/crates/gitbutler-stack/src/patch_reference.rs @@ -22,31 +22,15 @@ pub struct Branch { pub name: String, /// Optional description of the series. This could be markdown or anything our hearts desire. pub description: Option, - /// An identifier for a review unit at a forge (eg. GitHub Pull Request number). - /// None if is no review unit, eg. no Pull Request has been created. + /// The pull request associated with the branch, or None if a pull request has not been created. #[serde(default)] - pub forge_id: Option, + pub pr_number: Option, /// Archived represents the state when series/branch has been integrated and is below the merge base of the branch. /// This would occur when the branch has been merged at the remote and the workspace has been updated with that change. #[serde(default)] pub archived: bool, } -/// Represents identifiers for the series at possible forges, eg. GitHub PR numbers. -#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] -#[serde(tag = "type", content = "subject")] -pub enum ForgeIdentifier { - GitHub(GitHubIdentifier), -} - -/// Represents a GitHub Pull Request identifier. -#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct GitHubIdentifier { - /// Pull Request number. - pub pr_number: usize, -} - /// A patch identifier which is either `CommitId` or a `ChangeId`. /// ChangeId should always be used if available. #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] diff --git a/crates/gitbutler-stack/src/stack.rs b/crates/gitbutler-stack/src/stack.rs index c55f733ac0..6723f76054 100644 --- a/crates/gitbutler-stack/src/stack.rs +++ b/crates/gitbutler-stack/src/stack.rs @@ -23,7 +23,6 @@ use crate::heads::get_head; use crate::heads::remove_head; use crate::Branch; use crate::CommitOrChangeId; -use crate::ForgeIdentifier; use crate::Series; use crate::{ownership::BranchOwnershipClaims, VirtualBranchesHandle}; @@ -284,7 +283,7 @@ impl Stack { generate_branch_name(author)? }, description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; let state = branch_state(ctx); @@ -365,7 +364,7 @@ impl Stack { target: current_top_head.target.clone(), name, description, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; self.add_series(ctx, new_head, Some(current_top_head.name.clone())) @@ -386,7 +385,7 @@ impl Stack { /// Updates an existing branch in the stack. /// The same invariants as `add_branch` apply. - /// If the branch name is updated, the forge_id will be reset to None. + /// If the branch name is updated, the pr_number will be reset to None. /// /// This operation mutates the gitbutler::Branch.heads list and updates the state in `virtual_branches.toml` pub fn update_series( @@ -447,7 +446,7 @@ impl Stack { if let Some(head) = head { head.name = name; validate_name(head, &state)?; - head.forge_id = None; // reset forge_id + head.pr_number = None; // reset pr_number } } @@ -739,16 +738,16 @@ impl Stack { /// # Errors /// If the series does not exist, this method will return an error. /// If the stack has not been initialized, this method will return an error. - pub fn set_forge_id( + pub fn set_pr_number( &mut self, ctx: &CommandContext, series_name: &str, - new_forge_id: Option, + new_pr_number: Option, ) -> Result<()> { self.initialized()?; match self.heads.iter_mut().find(|r| r.name == series_name) { Some(head) => { - head.forge_id = new_forge_id; + head.pr_number = new_pr_number; branch_state(ctx).set_branch(self.clone()) } None => bail!( diff --git a/crates/gitbutler-stack/tests/mod.rs b/crates/gitbutler-stack/tests/mod.rs index f3a2d7fc4b..1ec7df25a0 100644 --- a/crates/gitbutler-stack/tests/mod.rs +++ b/crates/gitbutler-stack/tests/mod.rs @@ -7,9 +7,7 @@ use gitbutler_commit::commit_ext::CommitExt; use gitbutler_reference::RemoteRefname; use gitbutler_repo::{LogUntil, RepositoryExt as _}; use gitbutler_repo_actions::RepoActionsExt; -use gitbutler_stack::{ - Branch, CommitOrChangeId, ForgeIdentifier, GitHubIdentifier, VirtualBranchesHandle, -}; +use gitbutler_stack::{Branch, CommitOrChangeId, VirtualBranchesHandle}; use gitbutler_stack::{PatchReferenceUpdate, TargetUpdate}; use itertools::Itertools; use tempfile::TempDir; @@ -22,7 +20,7 @@ fn add_series_success() -> Result<()> { name: "asdf".into(), target: CommitOrChangeId::ChangeId(test_ctx.commits[1].change_id().unwrap()), description: Some("my description".into()), - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; let result = test_ctx.branch.add_series(&ctx, reference, None); @@ -76,7 +74,7 @@ fn add_series_top_base() -> Result<()> { name: "asdf".into(), target: CommitOrChangeId::CommitId(merge_base.id().to_string()), description: Some("my description".into()), - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; let result = test_ctx.branch.add_series(&ctx, reference, None); @@ -102,7 +100,7 @@ fn add_multiple_series() -> Result<()> { name: "head_4".into(), target: CommitOrChangeId::ChangeId(test_ctx.commits.last().unwrap().change_id().unwrap()), description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; let result = test_ctx @@ -115,7 +113,7 @@ fn add_multiple_series() -> Result<()> { name: "head_2".into(), target: CommitOrChangeId::ChangeId(test_ctx.commits.last().unwrap().change_id().unwrap()), description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; let result = test_ctx.branch.add_series(&ctx, head_2, None); @@ -129,7 +127,7 @@ fn add_multiple_series() -> Result<()> { name: "head_1".into(), target: CommitOrChangeId::ChangeId(test_ctx.commits.first().unwrap().change_id().unwrap()), description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; @@ -155,7 +153,7 @@ fn add_series_commit_id_when_change_id_available() -> Result<()> { name: "asdf".into(), target: CommitOrChangeId::CommitId(test_ctx.commits[1].id().to_string()), description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; let result = test_ctx.branch.add_series(&ctx, reference, None); @@ -177,7 +175,7 @@ fn add_series_invalid_name_fails() -> Result<()> { name: "name with spaces".into(), target: CommitOrChangeId::CommitId(test_ctx.commits[0].id().to_string()), description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; let result = test_ctx.branch.add_series(&ctx, reference, None); @@ -193,7 +191,7 @@ fn add_series_duplicate_name_fails() -> Result<()> { name: "asdf".into(), target: CommitOrChangeId::ChangeId(test_ctx.commits[1].change_id().unwrap()), description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; let result = test_ctx.branch.add_series(&ctx, reference.clone(), None); @@ -214,7 +212,7 @@ fn add_series_matching_git_ref_is_ok() -> Result<()> { name: "existing-branch".into(), target: test_ctx.commits[0].clone().into(), description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; let result = test_ctx.branch.add_series(&ctx, reference.clone(), None); @@ -230,7 +228,7 @@ fn add_series_including_refs_head_fails() -> Result<()> { name: "refs/heads/my-branch".into(), target: CommitOrChangeId::CommitId(test_ctx.commits[0].id().to_string()), description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; let result = test_ctx.branch.add_series(&ctx, reference.clone(), None); @@ -249,7 +247,7 @@ fn add_series_target_commit_doesnt_exist() -> Result<()> { name: "my-branch".into(), target: CommitOrChangeId::CommitId("30696678319e0fa3a20e54f22d47fc8cf1ceaade".into()), // does not exist description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; let result = test_ctx.branch.add_series(&ctx, reference.clone(), None); @@ -269,7 +267,7 @@ fn add_series_target_change_id_doesnt_exist() -> Result<()> { name: "my-branch".into(), target: CommitOrChangeId::ChangeId("does-not-exist".into()), // does not exist description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; let result = test_ctx.branch.add_series(&ctx, reference.clone(), None); @@ -289,7 +287,7 @@ fn add_series_target_commit_not_in_stack() -> Result<()> { name: "my-branch".into(), target: CommitOrChangeId::CommitId(other_commit_id.clone()), // does not exist description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; let result = test_ctx.branch.add_series(&ctx, reference.clone(), None); @@ -344,7 +342,7 @@ fn remove_series_with_multiple_last_heads() -> Result<()> { name: "to_stay".into(), target: CommitOrChangeId::ChangeId(test_ctx.commits.last().unwrap().change_id().unwrap()), description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; let result = test_ctx.branch.add_series(&ctx, to_stay.clone(), None); @@ -376,7 +374,7 @@ fn remove_series_no_orphan_commits() -> Result<()> { name: "to_stay".into(), target: CommitOrChangeId::ChangeId(test_ctx.commits.first().unwrap().change_id().unwrap()), description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; // references the oldest commit let result = test_ctx.branch.add_series(&ctx, to_stay.clone(), None); @@ -448,14 +446,14 @@ fn update_series_name_success() -> Result<()> { } #[test] -fn update_series_name_resets_forge_id() -> Result<()> { +fn update_series_name_resets_pr_number() -> Result<()> { let (ctx, _temp_dir) = command_ctx("multiple-commits")?; let mut test_ctx = test_ctx(&ctx)?; - let forge_id = ForgeIdentifier::GitHub(GitHubIdentifier { pr_number: 123 }); + let pr_number = 123; test_ctx .branch - .set_forge_id(&ctx, "a-branch-2", Some(forge_id.clone()))?; - assert_eq!(test_ctx.branch.heads[0].forge_id, Some(forge_id.clone())); + .set_pr_number(&ctx, "a-branch-2", Some(pr_number))?; + assert_eq!(test_ctx.branch.heads[0].pr_number, Some(pr_number)); let update = PatchReferenceUpdate { name: Some("new-name".into()), target_update: None, @@ -464,7 +462,7 @@ fn update_series_name_resets_forge_id() -> Result<()> { test_ctx .branch .update_series(&ctx, "a-branch-2".into(), &update)?; - assert_eq!(test_ctx.branch.heads[0].forge_id, None); + assert_eq!(test_ctx.branch.heads[0].pr_number, None); assert_eq!( test_ctx.branch, test_ctx.handle.get_branch(test_ctx.branch.id)? @@ -558,7 +556,7 @@ fn update_series_target_success() -> Result<()> { name: "series_1".into(), target: commit_0_change_id.clone(), description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; let result = test_ctx.branch.add_series(&ctx, series_1, None); @@ -657,7 +655,7 @@ fn list_series_two_heads_same_commit() -> Result<()> { name: "head_before".into(), target: CommitOrChangeId::ChangeId(test_ctx.commits.last().unwrap().change_id().unwrap()), description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; // add `head_before` before the initial head @@ -693,7 +691,7 @@ fn list_series_two_heads_different_commit() -> Result<()> { // point to the first commit target: CommitOrChangeId::ChangeId(test_ctx.commits.first().unwrap().change_id().unwrap()), description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; // add `head_before` before the initial head @@ -759,7 +757,7 @@ fn replace_head_single() -> Result<()> { name: "from_head".into(), target: CommitOrChangeId::ChangeId(test_ctx.commits[1].change_id().unwrap()), description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; test_ctx.branch.add_series(&ctx, from_head, None)?; @@ -792,7 +790,7 @@ fn replace_head_single_with_merge_base() -> Result<()> { name: "from_head".into(), target: CommitOrChangeId::ChangeId(test_ctx.commits[1].change_id().unwrap()), description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; test_ctx.branch.add_series(&ctx, from_head, None)?; @@ -829,7 +827,7 @@ fn replace_head_with_invalid_commit_error() -> Result<()> { name: "from_head".into(), target: CommitOrChangeId::ChangeId(test_ctx.commits[1].change_id().unwrap()), description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; test_ctx.branch.add_series(&ctx, from_head, None)?; @@ -857,7 +855,7 @@ fn replace_head_with_same_noop() -> Result<()> { name: "from_head".into(), target: CommitOrChangeId::ChangeId(test_ctx.commits[1].change_id().unwrap()), description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; test_ctx.branch.add_series(&ctx, from_head, None)?; @@ -944,14 +942,14 @@ fn replace_head_multiple() -> Result<()> { name: "from_head_1".into(), target: CommitOrChangeId::ChangeId(test_ctx.commits[1].change_id().unwrap()), description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; let from_head_2 = Branch { name: "from_head_2".into(), target: CommitOrChangeId::ChangeId(test_ctx.commits[1].change_id().unwrap()), description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; // both references point to the same commit @@ -992,7 +990,7 @@ fn replace_head_top_of_stack_multiple() -> Result<()> { name: "extra_head".into(), target: CommitOrChangeId::ChangeId(test_ctx.commits[1].change_id().unwrap()), description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; // an extra head just beneath the top of the stack @@ -1059,7 +1057,7 @@ fn set_legacy_refname_multiple_heads() -> Result<()> { name: "extra_head".into(), target: CommitOrChangeId::ChangeId(test_ctx.commits[1].change_id().unwrap()), description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }; // an extra head just beneath the top of the stack @@ -1128,7 +1126,7 @@ fn archive_heads_success() -> Result<()> { target: test_ctx.other_commits.first().cloned().unwrap().into(), name: "foo".to_string(), description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }, ); @@ -1159,7 +1157,7 @@ fn does_not_archive_head_on_merge_base() -> Result<()> { target: merge_base.into(), name: "bottom".to_string(), description: None, - forge_id: Default::default(), + pr_number: Default::default(), archived: Default::default(), }, None, @@ -1176,19 +1174,12 @@ fn does_not_archive_head_on_merge_base() -> Result<()> { } #[test] -fn set_forge_identifiers_success() -> Result<()> { +fn set_pr_numberentifiers_success() -> Result<()> { let (ctx, _temp_dir) = command_ctx("multiple-commits")?; let mut test_ctx = test_ctx(&ctx)?; - let result = test_ctx.branch.set_forge_id( - &ctx, - "a-branch-2", - Some(ForgeIdentifier::GitHub(GitHubIdentifier { pr_number: 123 })), - ); + let result = test_ctx.branch.set_pr_number(&ctx, "a-branch-2", Some(123)); assert!(result.is_ok()); - assert_eq!( - test_ctx.branch.heads[0].forge_id, - Some(ForgeIdentifier::GitHub(GitHubIdentifier { pr_number: 123 })) - ); + assert_eq!(test_ctx.branch.heads[0].pr_number, Some(123)); // Assert persisted assert_eq!( test_ctx.branch, @@ -1198,14 +1189,12 @@ fn set_forge_identifiers_success() -> Result<()> { } #[test] -fn set_forge_identifiers_series_not_found_fails() -> Result<()> { +fn set_pr_numberentifiers_series_not_found_fails() -> Result<()> { let (ctx, _temp_dir) = command_ctx("multiple-commits")?; let mut test_ctx = test_ctx(&ctx)?; - let result = test_ctx.branch.set_forge_id( - &ctx, - "does-not-exist", - Some(ForgeIdentifier::GitHub(GitHubIdentifier { pr_number: 123 })), - ); + let result = test_ctx + .branch + .set_pr_number(&ctx, "does-not-exist", Some(123)); assert_eq!( result.err().unwrap().to_string(), format!( diff --git a/crates/gitbutler-tauri/src/main.rs b/crates/gitbutler-tauri/src/main.rs index 0352c58ea2..5e7465ce4f 100644 --- a/crates/gitbutler-tauri/src/main.rs +++ b/crates/gitbutler-tauri/src/main.rs @@ -202,7 +202,7 @@ fn main() { stack::remove_series, stack::update_series_name, stack::update_series_description, - stack::update_series_forge_id, + stack::update_series_pr_number, stack::push_stack, secret::secret_get_global, secret::secret_set_global, diff --git a/crates/gitbutler-tauri/src/stack.rs b/crates/gitbutler-tauri/src/stack.rs index eb58912442..122de49c11 100644 --- a/crates/gitbutler-tauri/src/stack.rs +++ b/crates/gitbutler-tauri/src/stack.rs @@ -1,7 +1,7 @@ use gitbutler_branch_actions::stack::CreateSeriesRequest; use gitbutler_project as projects; use gitbutler_project::ProjectId; -use gitbutler_stack::{ForgeIdentifier, StackId}; +use gitbutler_stack::StackId; use tauri::State; use tracing::instrument; @@ -82,17 +82,20 @@ pub fn update_series_description( #[tauri::command(async)] #[instrument(skip(projects, windows), err(Debug))] -pub fn update_series_forge_id( +pub fn update_series_pr_number( windows: State<'_, WindowState>, projects: State<'_, projects::Controller>, project_id: ProjectId, stack_id: StackId, head_name: String, - forge_id: Option, + pr_number: Option, ) -> Result<(), Error> { let project = projects.get(project_id)?; - gitbutler_branch_actions::stack::update_series_forge_id( - &project, stack_id, head_name, forge_id, + gitbutler_branch_actions::stack::update_series_pr_number( + &project, + stack_id, + head_name, + pr_number, )?; emit_vbranches(&windows, project_id); Ok(()) diff --git a/crates/gitbutler-tauri/src/virtual_branches.rs b/crates/gitbutler-tauri/src/virtual_branches.rs index 8044a3d271..e3bda06b6d 100644 --- a/crates/gitbutler-tauri/src/virtual_branches.rs +++ b/crates/gitbutler-tauri/src/virtual_branches.rs @@ -13,7 +13,7 @@ pub mod commands { use gitbutler_project as projects; use gitbutler_project::{FetchResult, ProjectId}; use gitbutler_reference::{normalize_branch_name as normalize_name, Refname, RemoteRefname}; - use gitbutler_stack::{BranchOwnershipClaims, ForgeIdentifier, StackId}; + use gitbutler_stack::{BranchOwnershipClaims, StackId}; use std::path::PathBuf; use tauri::State; use tracing::instrument; @@ -101,11 +101,14 @@ pub mod commands { project_id: ProjectId, branch: Refname, remote: Option, - forge_id: Option, + pr_number: Option, ) -> Result { let project = projects.get(project_id)?; let branch_id = gitbutler_branch_actions::create_virtual_branch_from_branch( - &project, &branch, remote, forge_id, + &project, + &branch, + remote, + pr_number, )?; emit_vbranches(&windows, project_id); Ok(branch_id)