Expose repo content hints to rumination
This commit is contained in:
parent
ffbe3eb77d
commit
8ce19260c2
4 changed files with 118 additions and 1 deletions
|
|
@ -392,16 +392,120 @@ function enrichCommit(repoPath, commit) {
|
|||
...commit,
|
||||
diffstat: parseDiffstat(summaryLine),
|
||||
changedPaths,
|
||||
contentHints: buildCommitContentHints(repoPath, commit.hash, changedPaths),
|
||||
};
|
||||
} catch {
|
||||
return {
|
||||
...commit,
|
||||
diffstat: null,
|
||||
changedPaths: [],
|
||||
contentHints: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function buildCommitContentHints(repoPath, commitHash, changedPaths) {
|
||||
return changedPaths
|
||||
.filter((path) => isHintableTextPath(path))
|
||||
.slice(0, 4)
|
||||
.map((path) => buildFileContentHint(repoPath, commitHash, path))
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
function isHintableTextPath(path) {
|
||||
return /\.(md|mdx|txt|json|jsonc|ya?ml|toml|ts|tsx|js|jsx|mjs|cjs|rs|cs|ps1|py|html|css|scss)$/i.test(path);
|
||||
}
|
||||
|
||||
function buildFileContentHint(repoPath, commitHash, path) {
|
||||
const currentText = readCommittedFile(repoPath, commitHash, path);
|
||||
const addedLines = readAddedLines(repoPath, commitHash, path);
|
||||
const frontmatter = parseFrontmatter(currentText);
|
||||
const headings = readMarkdownHeadings(currentText).slice(0, 4);
|
||||
const excerpts = addedLines
|
||||
.filter((line) => line.trim().length > 0 && !line.trim().startsWith("---"))
|
||||
.slice(0, 6);
|
||||
|
||||
if (!frontmatter && headings.length === 0 && excerpts.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
path,
|
||||
frontmatter,
|
||||
headings,
|
||||
addedExcerpts: excerpts,
|
||||
};
|
||||
}
|
||||
|
||||
function readCommittedFile(repoPath, commitHash, path) {
|
||||
try {
|
||||
return execGit(repoPath, ["show", `${commitHash}:${path}`]);
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
function readAddedLines(repoPath, commitHash, path) {
|
||||
try {
|
||||
return execGit(repoPath, ["show", commitHash, "--format=", "--unified=0", "--", path])
|
||||
.split(/\r?\n/)
|
||||
.filter((line) => line.startsWith("+") && !line.startsWith("+++"))
|
||||
.map((line) => line.slice(1).trim())
|
||||
.filter(Boolean)
|
||||
.slice(0, 12);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function parseFrontmatter(text) {
|
||||
const match = text.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
||||
if (!match) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const result = {};
|
||||
let activeListKey;
|
||||
for (const rawLine of match[1].split(/\r?\n/)) {
|
||||
const line = rawLine.trimEnd();
|
||||
const listItem = line.match(/^\s*-\s+(.*)$/);
|
||||
if (listItem && activeListKey) {
|
||||
result[activeListKey].push(stripWrappingQuotes(listItem[1].trim()));
|
||||
continue;
|
||||
}
|
||||
|
||||
activeListKey = undefined;
|
||||
const pair = line.match(/^([A-Za-z0-9_-]+):\s*(.*)$/);
|
||||
if (!pair) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const [, key, rawValue] = pair;
|
||||
if (rawValue.trim().length === 0) {
|
||||
result[key] = [];
|
||||
activeListKey = key;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (["title", "description", "author", "date", "socialDeck"].includes(key)) {
|
||||
result[key] = stripWrappingQuotes(rawValue.trim());
|
||||
}
|
||||
}
|
||||
|
||||
return Object.keys(result).length > 0 ? result : undefined;
|
||||
}
|
||||
|
||||
function readMarkdownHeadings(text) {
|
||||
return text
|
||||
.split(/\r?\n/)
|
||||
.map((line) => line.match(/^(#{1,3})\s+(.+)$/)?.[2]?.trim())
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
function stripWrappingQuotes(value) {
|
||||
return value.replace(/^"(.*)"$/, "$1").replace(/^'(.*)'$/, "$1");
|
||||
}
|
||||
|
||||
function parseDiffstat(summaryLine) {
|
||||
if (!summaryLine) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -151,7 +151,11 @@ function Project-OpenCasesForRumination {
|
|||
param($Cases, [DateTime] $Now)
|
||||
|
||||
return @(
|
||||
@(Convert-ToValueArray -Value $Cases) | ForEach-Object {
|
||||
@(Convert-ToValueArray -Value $Cases) |
|
||||
Where-Object {
|
||||
-not (Test-RuminationCaseTerminal -Status (Get-ObjectPropertyString -Value $_ -Name "status"))
|
||||
} |
|
||||
ForEach-Object {
|
||||
@{
|
||||
sourceMessageId = Get-ObjectPropertyString -Value $_ -Name "sourceMessageId"
|
||||
status = Get-ObjectPropertyString -Value $_ -Name "status"
|
||||
|
|
@ -169,6 +173,12 @@ function Project-OpenCasesForRumination {
|
|||
)
|
||||
}
|
||||
|
||||
function Test-RuminationCaseTerminal {
|
||||
param([string] $Status)
|
||||
|
||||
return @("answered", "resolved", "closed", "retired", "dropped").Contains($Status)
|
||||
}
|
||||
|
||||
function Project-SpeechReceiptsForRumination {
|
||||
param($Receipts, [DateTime] $Now)
|
||||
|
||||
|
|
@ -351,6 +361,7 @@ function Project-RepoCommitForRumination {
|
|||
subject = Get-ObjectPropertyString -Value $Commit -Name "subject"
|
||||
diffstat = Get-ObjectPropertyValue -Value $Commit -Name "diffstat"
|
||||
changedPaths = @(Convert-ToValueArray -Value (Get-ObjectPropertyValue -Value $Commit -Name "changedPaths"))
|
||||
contentHints = @(Convert-ToValueArray -Value (Get-ObjectPropertyValue -Value $Commit -Name "contentHints"))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue