feat(repository): improve support for getting/showing commit log information per path@@ -57,12 +57,21 @@ const getRepositoryBrowserView: ReqHandler = async (request, reply) => {
)
: null;
+ const commitLogs = await repoService.getRepositoryCommitLog(
+ repo,
+ path,
+ ref,
+ true
+ );
+ const lastCommit = commitLogs.length >= 1 ? commitLogs[0] : null;
+
return reqHandler<RepositoryDetailsViewProps>(RepositoryDetailsView.name, {
currentUser,
cloneUrl: {
http: await repoService.getRepositoryHTTPCloneUrl(repo),
ssh: await repoService.getRepositorySSHCloneUrl(repo),
},
+ lastCommit,
parentOrg,
path,
readmeFileContent,
@@ -45,7 +45,12 @@ const getRepositoryDetailsView: ReqHandler = async (request, reply) => {
? await repoService.getRepositoryFileContent(repo, readmeFiles[0])
: null;
- const commitLogs = await repoService.getRepositoryCommitLog(repo, ref, true);
+ const commitLogs = await repoService.getRepositoryCommitLog(
+ repo,
+ "",
+ ref,
+ true
+ );
const lastCommit = commitLogs.length >= 1 ? commitLogs[0] : null;
const reqHandler = reply.makeRequestHandler(request, reply);
@@ -13,10 +13,10 @@ import type { RepositoryServiceDeps } from "./types";
const makeGetRepositoryCommitLog: ServiceMethodFactory<
RepositoryServiceDeps,
- [Repository, string | undefined, boolean | undefined],
+ [Repository, string | undefined, string | undefined, boolean | undefined],
Promise<RepositoryLog[]>
> = ({ request }) => {
- return async (repo, ref = "HEAD", onlyLast = false) => {
+ return async (repo, path = undefined, ref = "HEAD", onlyLast = false) => {
const parentOrg = await request.prisma.organization.findUnique({
where: {
id: repo.organizationId,
@@ -37,13 +37,22 @@ const makeGetRepositoryCommitLog: ServiceMethodFactory<
var format =
"{%n ^@^commit^@^: ^@^%H^@^,%n ^@^abbreviated_commit^@^: ^@^%h^@^,%n ^@^tree^@^: ^@^%T^@^,%n ^@^abbreviated_tree^@^: ^@^%t^@^,%n ^@^parent^@^: ^@^%P^@^,%n ^@^abbreviated_parent^@^: ^@^%p^@^,%n ^@^refs^@^: ^@^%D^@^,%n ^@^encoding^@^: ^@^%e^@^,%n ^@^subject^@^: ^@^%s^@^,%n ^@^sanitized_subject_line^@^: ^@^%f^@^,%n ^@^body^@^: ^@^%b^@^,%n ^@^commit_notes^@^: ^@^%N^@^,%n ^@^verification_flag^@^: ^@^%G?^@^,%n ^@^signer^@^: ^@^%GS^@^,%n ^@^signer_key^@^: ^@^%GK^@^,%n ^@^author^@^: {%n ^@^name^@^: ^@^%aN^@^,%n ^@^email^@^: ^@^%aE^@^,%n ^@^date^@^: ^@^%aD^@^%n },%n ^@^commiter^@^: {%n ^@^name^@^: ^@^%cN^@^,%n ^@^email^@^: ^@^%cE^@^,%n ^@^date^@^: ^@^%cD^@^%n }%n},";
- const gitLogProcess = spawn(
- "git",
- ["log", `--pretty=format:${format}`, onlyLast ? "-1" : "", ref],
- {
- cwd: repoPath,
- }
- );
+ path;
+ const args = [
+ "log",
+ "--quiet",
+ `--pretty=format:${format}`,
+ onlyLast ? "-1" : "",
+ ref,
+ path != null && path.trim() !== "" ? "--" : null,
+ path != null && path.trim() !== "" ? "-p" : null,
+ path != null && path.trim() !== "" ? `${path}` : null,
+ ].filter((x): x is string => x != null);
+ const gitLogProcess = spawn("git", args, {
+ cwd: repoPath,
+ });
+
+ console.log(`$ git ${args.join(" ")}`);
const gitLogResult = await new Promise<RepositoryLog[]>(
(resolve, reject) => {
@@ -34,7 +34,8 @@ export interface RepositoryServiceAPI extends ServiceApiContract {
getRepository(orgSlug: string, repoSlug: string): Promise<Repository | null>;
getRepositoryCommitLog(
repository: Repository,
- ref?: string | undefined,
+ path?: string,
+ ref?: string,
onlyLast?: boolean
): Promise<RepositoryLog[]>;
getRepositoryExploreCollection(): Promise<