mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-09-11 12:25:42 +03:00
introduce last commiter field, use jsdoc, add type transforms
This commit is contained in:
parent
32868092ed
commit
e53c11a477
@ -1,5 +1,5 @@
|
||||
import { invoke } from '$lib/backend/ipc';
|
||||
import { Transform } from 'class-transformer';
|
||||
import { Transform, Type } from 'class-transformer';
|
||||
import { plainToInstance } from 'class-transformer';
|
||||
|
||||
export class BranchListingService {
|
||||
@ -31,83 +31,110 @@ export class BranchListingService {
|
||||
}
|
||||
}
|
||||
|
||||
/// A filter that can be applied to the branch listing
|
||||
/** A filter that can be applied to the branch listing */
|
||||
export class BranchListingFilter {
|
||||
/// If the value is true, the listing will only include branches that have the same author as the current user.
|
||||
/// If the value is false, the listing will include only branches that are not created by the user.
|
||||
/**
|
||||
* If the value is true, the listing will only include branches that have the same author as the current user.
|
||||
* If the value is false, the listing will include only branches that are not created by the user.
|
||||
*/
|
||||
ownBranches?: boolean;
|
||||
/// If the value is true, the listing will only include branches that are applied in the workspace.
|
||||
/// If the value is false, the listing will only include branches that are not applied in the workspace.
|
||||
/**
|
||||
* If the value is true, the listing will only include branches that are applied in the workspace.
|
||||
* If the value is false, the listing will only include branches that are not applied in the workspace.
|
||||
*/
|
||||
applied?: boolean;
|
||||
}
|
||||
|
||||
/// Represents a branch that exists for the repository
|
||||
/// This also combines the concept of a remote, local and virtual branch in order to provide a unified interface for the UI
|
||||
/// Branch entry is not meant to contain all of the data a branch can have (e.g. full commit history, all files and diffs, etc.).
|
||||
/// It is intended a summary that can be quickly retrieved and displayed in the UI.
|
||||
/// For more detailed information, each branch can be queried individually for it's `BranchData`.
|
||||
/**
|
||||
* Represents a branch that exists for the repository
|
||||
* This also combines the concept of a remote, local and virtual branch in order to provide a unified interface for the UI
|
||||
* Branch entry is not meant to contain all of the data a branch can have (e.g. full commit history, all files and diffs, etc.).
|
||||
* It is intended a summary that can be quickly retrieved and displayed in the UI.
|
||||
* For more detailed information, each branch can be queried individually for it's `BranchData`.
|
||||
*/
|
||||
export class BranchListing {
|
||||
/// The name of the branch (e.g. `main`, `feature/branch`), excluding the remote name
|
||||
/** The name of the branch (e.g. `main`, `feature/branch`), excluding the remote name */
|
||||
name!: string;
|
||||
/// This is a list of remote that this branch can be found on (e.g. `origin`, `upstream` etc.).
|
||||
/// If this branch is a local branch, this list will be empty.
|
||||
/**
|
||||
* This is a list of remote that this branch can be found on (e.g. `origin`, `upstream` etc.).
|
||||
* If this branch is a local branch, this list will be empty.
|
||||
*/
|
||||
remotes!: string[];
|
||||
/// The branch may or may not have a virtual branch associated with it
|
||||
/** The branch may or may not have a virtual branch associated with it */
|
||||
@Type(() => VirtualBranchReference)
|
||||
virtualBranch?: VirtualBranchReference | undefined;
|
||||
/// The number of commits associated with a branch
|
||||
/// Since the virtual branch, local branch and the remote one can have different number of commits,
|
||||
/// the value from the virtual branch (if present) takes the highest precedence,
|
||||
/// followed by the local branch and then the remote branches (taking the max if there are multiple)
|
||||
/**
|
||||
* The number of commits associated with a branch
|
||||
* Since the virtual branch, local branch and the remote one can have different number of commits,
|
||||
* the value from the virtual branch (if present) takes the highest precedence,
|
||||
* followed by the local branch and then the remote branches (taking the max if there are multiple)
|
||||
*/
|
||||
numberOfCommits!: number;
|
||||
/// Timestamp in milliseconds since the branch was last updated.
|
||||
/// This includes any commits, uncommited changes or even updates to the branch metadata (e.g. renaming).
|
||||
/**
|
||||
* Timestamp in milliseconds since the branch was last updated.
|
||||
* This includes any commits, uncommited changes or even updates to the branch metadata (e.g. renaming).
|
||||
*/
|
||||
@Transform((obj) => new Date(obj.value))
|
||||
updatedAt!: number;
|
||||
/// A list of authors that have contributes commits to this branch.
|
||||
/// In the case of multiple remote tracking branches, it takes the full list of unique authors.
|
||||
/** The person who commited the head commit */
|
||||
@Type(() => Author)
|
||||
lastCommiter!: Author;
|
||||
/**
|
||||
* A list of authors that have contributes commits to this branch.
|
||||
* In the case of multiple remote tracking branches, it takes the full list of unique authors.
|
||||
*/
|
||||
@Type(() => Author)
|
||||
authors!: Author[];
|
||||
/// Determines if the branch is considered one created by the user
|
||||
/// A branch is considered created by the user if they were the author of the first commit in the branch.
|
||||
/**
|
||||
* Determines if the branch is considered one created by the user
|
||||
* A branch is considered created by the user if they were the author of the first commit in the branch.
|
||||
*/
|
||||
ownBranch!: boolean;
|
||||
}
|
||||
|
||||
/// Represents a reference to an associated virtual branch
|
||||
/** Represents a reference to an associated virtual branch */
|
||||
export class VirtualBranchReference {
|
||||
/// A non-normalized name of the branch, set by the user
|
||||
/** A non-normalized name of the branch, set by the user */
|
||||
givenName!: string;
|
||||
/// Virtual Branch UUID identifier
|
||||
/** Virtual Branch UUID identifier */
|
||||
id!: string;
|
||||
/// Determines if the virtual branch is applied in the workspace
|
||||
/** Determines if the virtual branch is applied in the workspace */
|
||||
inWorkspace!: boolean;
|
||||
}
|
||||
|
||||
/// Represents a "commit author" or "signature", based on the data from ther git history
|
||||
/** Represents a "commit author" or "signature", based on the data from ther git history */
|
||||
export class Author {
|
||||
/// The name of the author as configured in the git config
|
||||
/** The name of the author as configured in the git config */
|
||||
name?: string | undefined;
|
||||
/// The email of the author as configured in the git config
|
||||
/** The email of the author as configured in the git config */
|
||||
email?: string | undefined;
|
||||
}
|
||||
|
||||
/// Represents a fat struct with all the data associated with a branch
|
||||
/** Represents a fat struct with all the data associated with a branch */
|
||||
export class BranchListingDetails {
|
||||
/// The name of the branch (e.g. `main`, `feature/branch`), excluding the remote name
|
||||
/** The name of the branch (e.g. `main`, `feature/branch`), excluding the remote name */
|
||||
name!: string;
|
||||
/// The number of lines added within the branch
|
||||
/// Since the virtual branch, local branch and the remote one can have different number of lines removed,
|
||||
/// the value from the virtual branch (if present) takes the highest precedence,
|
||||
/// followed by the local branch and then the remote branches (taking the max if there are multiple).
|
||||
/// If this branch has a virutal branch, lines_added does NOT include the uncommitted lines.
|
||||
lines_added!: number;
|
||||
/// The number of lines removed within the branch
|
||||
/// Since the virtual branch, local branch and the remote one can have different number of lines removed,
|
||||
/// the value from the virtual branch (if present) takes the highest precedence,
|
||||
/// followed by the local branch and then the remote branches (taking the max if there are multiple)
|
||||
/// If this branch has a virutal branch, lines_removed does NOT include the uncommitted lines.
|
||||
lines_removed!: number;
|
||||
/// The number of files that were modified within the branch
|
||||
/// Since the virtual branch, local branch and the remote one can have different number files modified,
|
||||
/// the value from the virtual branch (if present) takes the highest precedence,
|
||||
/// followed by the local branch and then the remote branches (taking the max if there are multiple)
|
||||
number_of_files!: number;
|
||||
/**
|
||||
* The number of lines added within the branch
|
||||
* Since the virtual branch, local branch and the remote one can have different number of lines removed,
|
||||
* the value from the virtual branch (if present) takes the highest precedence,
|
||||
* followed by the local branch and then the remote branches (taking the max if there are multiple).
|
||||
* If this branch has a virutal branch, lines_added does NOT include the uncommitted lines.
|
||||
*/
|
||||
linesAdded!: number;
|
||||
/**
|
||||
* The number of lines removed within the branch
|
||||
* Since the virtual branch, local branch and the remote one can have different number of lines removed,
|
||||
* the value from the virtual branch (if present) takes the highest precedence,
|
||||
* followed by the local branch and then the remote branches (taking the max if there are multiple)
|
||||
* If this branch has a virutal branch, lines_removed does NOT include the uncommitted lines.
|
||||
*/
|
||||
linesRemoved!: number;
|
||||
/**
|
||||
* The number of files that were modified within the branch
|
||||
* Since the virtual branch, local branch and the remote one can have different number files modified,
|
||||
* the value from the virtual branch (if present) takes the highest precedence,
|
||||
* followed by the local branch and then the remote branches (taking the max if there are multiple)
|
||||
*/
|
||||
numberOfFiles!: number;
|
||||
}
|
||||
|
@ -211,10 +211,14 @@ fn branch_group_to_branch(
|
||||
.map(|vb| normalize_branch_name(&vb.name))
|
||||
.unwrap_or_default(),
|
||||
);
|
||||
let head_commit = repo
|
||||
.find_commit(head)
|
||||
.context("Failed to find head commit")?;
|
||||
let last_modified_ms = max(
|
||||
(repo.find_commit(head)?.time().seconds() * 1000) as u128,
|
||||
(head_commit.time().seconds() * 1000) as u128,
|
||||
virtual_branch.map_or(0, |x| x.updated_timestamp_ms),
|
||||
);
|
||||
let last_commiter = head_commit.author().into();
|
||||
let repo_head = repo.head()?.peel_to_commit()?;
|
||||
// If no merge base can be found, return with zero stats
|
||||
let branch = if let Ok(base) = repo.merge_base(repo_head.id(), head) {
|
||||
@ -242,6 +246,7 @@ fn branch_group_to_branch(
|
||||
virtual_branch: virtual_branch_reference,
|
||||
number_of_commits: commits.len(),
|
||||
updated_at: last_modified_ms,
|
||||
last_commiter,
|
||||
authors: authors.into_iter().collect(),
|
||||
own_branch,
|
||||
head,
|
||||
@ -253,6 +258,7 @@ fn branch_group_to_branch(
|
||||
virtual_branch: virtual_branch_reference,
|
||||
number_of_commits: 0,
|
||||
updated_at: last_modified_ms,
|
||||
last_commiter,
|
||||
authors: Vec::new(),
|
||||
own_branch: false,
|
||||
head,
|
||||
@ -345,6 +351,8 @@ pub struct BranchListing {
|
||||
/// Timestamp in milliseconds since the branch was last updated.
|
||||
/// This includes any commits, uncommited changes or even updates to the branch metadata (e.g. renaming).
|
||||
pub updated_at: u128,
|
||||
/// The person who commited the head commit.
|
||||
pub last_commiter: Author,
|
||||
/// A list of authors that have contributes commits to this branch.
|
||||
/// In the case of multiple remote tracking branches, it takes the full list of unique authors.
|
||||
pub authors: Vec<Author>,
|
||||
|
Loading…
Reference in New Issue
Block a user