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

Function listCommits

packages/web/src/features/git/listCommitsApi.ts:49–182  ·  view source on GitHub ↗
({
    repo: repoName,
    query,
    since,
    until,
    author,
    ref = 'HEAD',
    path,
    maxCount = 50,
    skip = 0,
}: ListCommitsRequest)

Source from the content-addressed store, hash-verified

47 * these formats in the --since and --until flags.
48 */
49export const listCommits = async ({
50 repo: repoName,
51 query,
52 since,
53 until,
54 author,
55 ref = 'HEAD',
56 path,
57 maxCount = 50,
58 skip = 0,
59}: ListCommitsRequest): Promise<ListCommitsResponse | ServiceError> => sew(() =>
60 withOptionalAuth(async ({ org, prisma }) => {
61 const repo = await prisma.repo.findFirst({
62 where: {
63 name: repoName,
64 orgId: org.id,
65 },
66 });
67
68 if (!repo) {
69 return notFound(`Repository "${repoName}" not found.`);
70 }
71
72 if (!isGitRefValid(ref)) {
73 return invalidGitRef(ref);
74 }
75
76 const { path: repoPath } = getRepoPath(repo);
77
78 // Validate date range if both since and until are provided
79 const dateRangeError = validateDateRange(since, until);
80 if (dateRangeError) {
81 return unexpectedError(dateRangeError);
82 }
83
84 // Parse dates to git-compatible format
85 const gitSince = toGitDate(since);
86 const gitUntil = toGitDate(until);
87
88 const git = simpleGit().cwd(repoPath);
89
90 try {
91 // --author and --grep are interpreted as git's default regex (POSIX BRE
92 // with GNU extensions). Callers are responsible for escaping metacharacters
93 // when they want literal matching.
94 const sharedOptions: Record<string, string | number | null> = {
95 ...(gitSince ? { '--since': gitSince } : {}),
96 ...(gitUntil ? { '--until': gitUntil } : {}),
97 ...(author ? {
98 '--author': author,
99 '--regexp-ignore-case': null /// Case insensitive
100 } : {}),
101 ...(query ? {
102 '--grep': query,
103 '--regexp-ignore-case': null /// Case insensitive
104 } : {}),
105 };
106

Callers 4

listCommits.tsFile · 0.90
CommitsPanelFunction · 0.90
route.tsFile · 0.90

Calls 9

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

Tested by

no test coverage detected