UNPKG

@openinc/parse-server-opendash

Version:
30 lines (29 loc) 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MetadataEnricher = void 0; class MetadataEnricher { static async enrichCommits(files, githubClient, rootPath) { const normalizedRoot = rootPath?.replace(/^\/+/g, "").replace(/\/+$/g, ""); const fullPaths = files.map((f) => normalizedRoot ? `${normalizedRoot}/${f.path}` : f.path); try { const commitMap = await githubClient.getMultipleFileCommits(fullPaths); let enriched = 0; files.forEach((file, idx) => { const commit = commitMap.get(fullPaths[idx]); if (commit?.commit) { file.lastModified = new Date(commit.commit.author.date); file.lastModifiedBy = commit.commit.author.name; file.lastCommitSha = commit.sha; file.lastCommitMessage = commit.commit.message.split("\n")[0]; if (!file.fileLastModifiedAt) file.fileLastModifiedAt = file.lastModified; enriched++; } }); } catch (e) { console.warn("Failed to fetch commit information:", e); } } } exports.MetadataEnricher = MetadataEnricher;