Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display the author and commit title in the edit mode #4948

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

estib-vega
Copy link
Contributor

@estib-vega estib-vega commented Sep 18, 2024

Display the title of the commit and the author name in the commit instead of the placeholders

Screenshot 2024-09-18 at 15 59 14

Copy link

vercel bot commented Sep 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
gitbutler-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 19, 2024 0:09am

@Caleb-T-Owens
Copy link
Contributor

Hey, I'm really not keen on this approach as it means we're effectively introducing another structure that is playing the role of a Commit.

I was hoping to have a service which can return a struct RemoteCommit for any given commit, so we can look up the commit details from the client side via the Oid

Copy link
Contributor

@Caleb-T-Owens Caleb-T-Owens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment above

Find a commit in the repository by its ID
Create a service that enables searching for a commit information by its project ID and commit ID
Display information about the commit in the edit mode page
Copy link
Contributor

@Caleb-T-Owens Caleb-T-Owens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for iterating on this so quickly! Especially on a day when we're hosting a conference.

Very much in a good direction. I just think that we could represent error cases vs missing commits a little bit better

Comment on lines +113 to +120
pub(crate) fn get_commit_data(ctx: &CommandContext, sha: git2::Oid) -> Result<RemoteCommit> {
let commit = ctx
.repository()
.find_commit(sha)
.context("failed to find commit")?;

Ok(commit_to_remote_commit(&commit))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub(crate) fn get_commit_data(ctx: &CommandContext, sha: git2::Oid) -> Result<RemoteCommit> {
let commit = ctx
.repository()
.find_commit(sha)
.context("failed to find commit")?;
Ok(commit_to_remote_commit(&commit))
}
pub(crate) fn get_commit_data(
ctx: &CommandContext,
sha: git2::Oid,
) -> Result<Option<RemoteCommit>> {
let commit = match ctx.repository().find_commit(sha) {
Ok(commit) => commit,
Err(error) => {
if error.code() == git2::ErrorCode::NotFound {
return Ok(None);
} else {
bail!(error);
}
}
};
Ok(Some(commit_to_remote_commit(&commit)))
}

Comment on lines +1 to +15
import { invoke } from '$lib/backend/ipc';
import { Commit } from '$lib/vbranches/types';
import { plainToInstance } from 'class-transformer';

export class RemoteCommitService {
async find(projectId: string, commitOid: string): Promise<Commit | undefined> {
try {
const commit = await invoke<unknown>('find_commit', { projectId, commitOid });
return plainToInstance(Commit, commit);
} catch (error) {
console.error(error);
return undefined;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something in my mind here is that we want to move away from using console.error and silently consuming errors. I figure here your intention was to represent a commit not being found, but I think with a little bit of jiggery pokery we can make it a little nicer.

Suggested change
import { invoke } from '$lib/backend/ipc';
import { Commit } from '$lib/vbranches/types';
import { plainToInstance } from 'class-transformer';
export class RemoteCommitService {
async find(projectId: string, commitOid: string): Promise<Commit | undefined> {
try {
const commit = await invoke<unknown>('find_commit', { projectId, commitOid });
return plainToInstance(Commit, commit);
} catch (error) {
console.error(error);
return undefined;
}
}
}
import { invoke } from '$lib/backend/ipc';
import { Commit } from '$lib/vbranches/types';
import { plainToInstance } from 'class-transformer';
import type { Project } from '$lib/backend/projects';
export class CommitService {
constructor(private project: Project) {}
async find(commitOid: string): Promise<Commit> {
const commit = await this.findMaybe(commitOid);
if (!commit) {
throw new Error(`Commit ${commitOid} not found`);
}
return commit;
}
async findMaybe(commitOid: string): Promise<Commit | undefined> {
const commit = await invoke<unknown | undefined>('find_commit', { projectId: this.project.id, commitOid });
if (!commit) return;
return plainToInstance(Commit, commit);
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also know that the name "RemoteCommitSerice" is inaccurate, could we please call it "CommitService"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be keen to hear your thoughts on this, but in my mind it makes sense to try and pass as many dependencies in the constructor as possible. I would be keen to pass the project through the constructor until we had a good reason as to why that was a bad pattern, as it just adds more boilerplate to the consumers.

Comment on lines +40 to +45
$effect(() => {
remoteCommitService.find(project.id, editModeMetadata.commitOid).then((maybeCommit) => {
commit = maybeCommit;
});
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we should always have a commit so I'd stick with find over findMaybe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@gitbutler/desktop rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants