({
repo: repoName,
query,
since,
until,
author,
ref = 'HEAD',
path,
maxCount = 50,
skip = 0,
}: ListCommitsRequest)
| 47 | * these formats in the --since and --until flags. |
| 48 | */ |
| 49 | export 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 |
no test coverage detected