MCPcopy Index your code
hub / github.com/sourcebot-dev/sourcebot / getCommit

Function getCommit

packages/web/src/features/git/getCommitApi.ts:30–103  ·  view source on GitHub ↗
({
    repo: repoName,
    ref,
}: GetCommitRequest)

Source from the content-addressed store, hash-verified

28].join(FIELD_SEP);
29
30export const getCommit = async ({
31 repo: repoName,
32 ref,
33}: GetCommitRequest): Promise<CommitDetail | ServiceError> => sew(() =>
34 withOptionalAuth(async ({ org, prisma }) => {
35 const repo = await prisma.repo.findFirst({
36 where: {
37 name: repoName,
38 orgId: org.id,
39 },
40 });
41
42 if (!repo) {
43 return notFound(`Repository "${repoName}" not found.`);
44 }
45
46 if (!isGitRefValid(ref)) {
47 return invalidGitRef(ref);
48 }
49
50 const { path: repoPath } = getRepoPath(repo);
51 const git = simpleGit().cwd(repoPath);
52
53 try {
54 const output = (await git.raw([
55 'log',
56 '-1',
57 `--format=${FORMAT}`,
58 ref,
59 ])).trim();
60
61 const fields = output.split(FIELD_SEP);
62 if (fields.length < 8) {
63 return unexpectedError(`Failed to parse commit data for revision "${ref}".`);
64 }
65
66 const [hash, date, message, refs, body, authorName, authorEmail, parentStr] = fields;
67 const parents = parentStr.trim() === '' ? [] : parentStr.trim().split(' ');
68
69 return {
70 hash,
71 date,
72 message,
73 refs,
74 body,
75 authorName,
76 authorEmail,
77 parents,
78 };
79 } catch (error: unknown) {
80 const errorMessage = error instanceof Error ? error.message : String(error);
81
82 if (errorMessage.includes('not a git repository')) {
83 return unexpectedError(
84 `Invalid git repository at ${repoPath}. ` +
85 `The directory exists but is not a valid git repository.`
86 );
87 }

Callers 3

FocusedCommitDiffPanelFunction · 0.90
FullCommitDiffPanelFunction · 0.90
route.tsFile · 0.90

Calls 7

sewFunction · 0.90
withOptionalAuthFunction · 0.90
notFoundFunction · 0.90
isGitRefValidFunction · 0.90
invalidGitRefFunction · 0.90
getRepoPathFunction · 0.90
unexpectedErrorFunction · 0.90

Tested by

no test coverage detected