-
Notifications
You must be signed in to change notification settings - Fork 492
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
base: master
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
9bbf5fe
to
878843b
Compare
878843b
to
a99d65b
Compare
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 |
There was a problem hiding this 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
a99d65b
to
662996f
Compare
662996f
to
ae85e80
Compare
ae85e80
to
bd74b26
Compare
There was a problem hiding this 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
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)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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))) | |
} |
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; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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.
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); | |
} | |
} |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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.
$effect(() => { | ||
remoteCommitService.find(project.id, editModeMetadata.commitOid).then((maybeCommit) => { | ||
commit = maybeCommit; | ||
}); | ||
}); | ||
|
There was a problem hiding this comment.
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
Display the title of the commit and the author name in the commit instead of the placeholders