-
Notifications
You must be signed in to change notification settings - Fork 1
Add query title heading and matched token to output #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { buildSelectionSummary } from "./render.ts"; | ||
| import { isRegexQuery } from "./regex.ts"; | ||
| import type { OutputFormat, OutputType, RepoGroup } from "./types.ts"; | ||
|
|
||
| // ─── Short-form helpers ─────────────────────────────────────────────────────── | ||
|
|
@@ -150,6 +151,45 @@ export function buildReplayDetails( | |
| ].join("\n"); | ||
| } | ||
|
|
||
| // ─── Markdown inline-code helper ──────────────────────────────────────────── | ||
|
|
||
| /** | ||
| * Wraps `s` in a Markdown inline-code span using a backtick fence long enough | ||
| * to safely contain any backticks already present in `s` (CommonMark §6.1). | ||
| * Adds surrounding spaces when `s` starts or ends with a backtick character. | ||
| */ | ||
| function mdInlineCode(s: string): string { | ||
| const runs = [...s.matchAll(/`+/g)].map((m) => m[0].length); | ||
| const maxRun = runs.length > 0 ? Math.max(...runs) : 0; | ||
| const fence = "`".repeat(maxRun + 1); | ||
| const padded = s.startsWith("`") || s.endsWith("`") ? ` ${s} ` : s; | ||
| return `${fence}${padded}${fence}`; | ||
| } | ||
|
|
||
| // ─── Query title ───────────────────────────────────────────────────────────── | ||
|
|
||
| /** | ||
| * Builds a first-level heading that identifies the query and any active | ||
| * qualifiers (e.g. `--include-archived`, `--exclude-template-repositories`). | ||
| * | ||
| * Examples: | ||
| * # Results for "useFlag" | ||
| * # Results for `/useFlag/i` | ||
| * # Results for "axios" · including archived · excluding templates | ||
| */ | ||
| export function buildQueryTitle(query: string, options: ReplayOptions = {}): string { | ||
| // JSON.stringify handles embedded double quotes and converts newlines to \n | ||
| // so the heading always stays on a single line. | ||
| // mdInlineCode uses a variable-length backtick fence to safely display regex | ||
| // patterns that may themselves contain backtick characters. | ||
| const queryDisplay = isRegexQuery(query) ? mdInlineCode(query) : JSON.stringify(query); | ||
| const qualifiers: string[] = []; | ||
| if (options.includeArchived) qualifiers.push("including archived"); | ||
| if (options.excludeTemplates) qualifiers.push("excluding templates"); | ||
| const suffix = qualifiers.length > 0 ? ` · ${qualifiers.join(" · ")}` : ""; | ||
| return `# Results for ${queryDisplay}${suffix}`; | ||
| } | ||
|
|
||
| // ─── Selected matches helper ───────────────────────────────────────────────── | ||
|
|
||
| function selectedMatches(group: RepoGroup) { | ||
|
|
@@ -174,6 +214,8 @@ export function buildMarkdownOutput( | |
| .map((g) => g.repoFullName); | ||
| if (repos.length === 0) return ""; | ||
| return ( | ||
| buildQueryTitle(query, options) + | ||
| "\n\n" + | ||
| repos.join("\n") + | ||
| "\n\n" + | ||
| buildReplayDetails(groups, query, org, excludedRepos, excludedExtractRefs, options) + | ||
|
|
@@ -183,6 +225,8 @@ export function buildMarkdownOutput( | |
|
|
||
| const lines: string[] = []; | ||
|
|
||
| lines.push(buildQueryTitle(query, options)); | ||
| lines.push(""); | ||
| lines.push(buildSelectionSummary(groups)); | ||
| lines.push(""); | ||
|
|
||
|
|
@@ -193,6 +237,7 @@ export function buildMarkdownOutput( | |
|
|
||
| // Section header (emitted before the first repo in a new team section) | ||
| if (group.sectionLabel !== undefined) { | ||
| lines.push(""); | ||
| lines.push(`## ${group.sectionLabel}`); | ||
| lines.push(""); | ||
| } | ||
|
|
@@ -206,7 +251,10 @@ export function buildMarkdownOutput( | |
| // absolute line numbers). | ||
| const seg = m.textMatches[0]?.matches[0]; | ||
|
Comment on lines
248
to
253
|
||
| if (seg) { | ||
| lines.push(` - [ ] [${m.path}:${seg.line}:${seg.col}](${m.htmlUrl}#L${seg.line})`); | ||
| const matchedText = seg.text ? `: ${mdInlineCode(seg.text)}` : ""; | ||
| lines.push( | ||
| ` - [ ] [${m.path}:${seg.line}:${seg.col}](${m.htmlUrl}#L${seg.line})${matchedText}`, | ||
| ); | ||
| } else { | ||
| lines.push(` - [ ] [${m.path}](${m.htmlUrl})`); | ||
| } | ||
|
|
@@ -240,7 +288,13 @@ export function buildJsonOutput( | |
| return { | ||
| path: m.path, | ||
| url: m.htmlUrl, | ||
| ...(seg !== undefined ? { line: seg.line, col: seg.col } : {}), | ||
| ...(seg !== undefined | ||
| ? { | ||
| line: seg.line, | ||
| col: seg.col, | ||
| ...(seg.text ? { matchedText: seg.text } : {}), | ||
| } | ||
| : {}), | ||
| }; | ||
| }); | ||
| return { ...base, matches }; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.