MCPcopy Create free account
hub / github.com/remix-run/react-router / getSourceLink

Function getSourceLink

scripts/changes/migrate-changesets.ts:92–114  ·  view source on GitHub ↗

* Returns a markdown link to the PR or commit that introduced the given file. * Prefers a PR link like `([#123](...))`, falls back to a short SHA link.

(filePath: string)

Source from the content-addressed store, hash-verified

90 * Prefers a PR link like `([#123](...))`, falls back to a short SHA link.
91 */
92function getSourceLink(filePath: string): string {
93 let result = cp.spawnSync(
94 "git",
95 ["log", "--format=%H %s", "-1", "--", filePath],
96 { encoding: "utf-8" },
97 );
98
99 let line = result.stdout.trim();
100 if (!line) return "";
101
102 let spaceIndex = line.indexOf(" ");
103 let sha = line.slice(0, spaceIndex);
104 let subject = line.slice(spaceIndex + 1);
105
106 let prMatch = subject.match(/\(#(\d+)\)$/);
107 if (prMatch) {
108 let pr = prMatch[1];
109 return ` ([#${pr}](${GITHUB_REPO_URL}/pull/${pr}))`;
110 }
111
112 let shortSha = sha.slice(0, 8);
113 return ` ([${shortSha}](${GITHUB_REPO_URL}/commit/${sha}))`;
114}
115
116function slugify(name: string): string {
117 return name

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected