@@ -31,6 +31,15 @@ const ROOT_DIR = join(import.meta.dirname, "..");
3131
3232// --- Parse changeset PR body ---
3333
34+ /**
35+ * Parse the changesets-generated PR body into a flat list of entries.
36+ * Deduplicates by linked PR number, skips dependency-only bumps, and
37+ * heuristically categorizes each entry as fix / feature / breaking /
38+ * improvement based on its leading text.
39+ *
40+ * @param {string } body - Raw markdown body from the changesets release PR.
41+ * @returns {Array<{text: string, type: 'fix' | 'feature' | 'breaking' | 'improvement'}> }
42+ */
3443function parsePrBody ( body ) {
3544 const entries = [ ] ;
3645 if ( ! body ) return entries ;
@@ -88,6 +97,13 @@ function parsePrBody(body) {
8897
8998const REPO = "triggerdotdev/trigger.dev" ;
9099
100+ /**
101+ * Run a git command in the repo root and return its trimmed stdout.
102+ * Rejects with the underlying execFile error on non-zero exit.
103+ *
104+ * @param {string[] } args - argv passed to git (e.g. ["log", "--format=%H"]).
105+ * @returns {Promise<string> }
106+ */
91107function gitExec ( args ) {
92108 return new Promise ( ( resolve , reject ) => {
93109 execFile ( "git" , args , { cwd : ROOT_DIR , maxBuffer : 1024 * 1024 } , ( err , stdout ) => {
@@ -97,6 +113,13 @@ function gitExec(args) {
97113 } ) ;
98114}
99115
116+ /**
117+ * Find the commit that first added a file (used to attribute a
118+ * `.server-changes/*.md` file back to the PR that introduced it).
119+ *
120+ * @param {string } filePath - Path relative to repo root.
121+ * @returns {Promise<string|null> } Commit SHA, or null if not found / git failed.
122+ */
100123async function getCommitForFile ( filePath ) {
101124 try {
102125 // Find the commit that added this file
@@ -107,6 +130,15 @@ async function getCommitForFile(filePath) {
107130 }
108131}
109132
133+ /**
134+ * Look up the PR that introduced a given commit. Prefers merged PRs and
135+ * picks the earliest-merged one (matches @changesets/get-github-info).
136+ * Requires GITHUB_TOKEN or GH_TOKEN; returns null without a token, on
137+ * fetch failure, or when no PR is associated with the commit.
138+ *
139+ * @param {string } commitSha
140+ * @returns {Promise<number|null> } PR number, or null.
141+ */
110142async function getPrForCommit ( commitSha ) {
111143 const token = process . env . GITHUB_TOKEN || process . env . GH_TOKEN ;
112144 if ( ! token || ! commitSha ) return null ;
@@ -139,6 +171,16 @@ async function getPrForCommit(commitSha) {
139171
140172// --- Parse .server-changes/ files ---
141173
174+ /**
175+ * Read every `.server-changes/*.md` file (skipping README.md), parse
176+ * frontmatter, and return the entries to render under "Server changes" in
177+ * the enhanced PR body. Looks up the introducing PR for each file and
178+ * appends a PR link if one is found and not already inline. Frontmatter
179+ * `type` and `area` fields drive section grouping (defaults: improvement,
180+ * webapp).
181+ *
182+ * @returns {Promise<Array<{text: string, type: string, area: string}>> }
183+ */
142184async function parseServerChanges ( ) {
143185 const dir = join ( ROOT_DIR , ".server-changes" ) ;
144186 const entries = [ ] ;
@@ -189,6 +231,15 @@ async function parseServerChanges() {
189231 return entries ;
190232}
191233
234+ /**
235+ * Minimal YAML frontmatter parser — splits a `---`-delimited header from
236+ * the body and returns both. Frontmatter values are trimmed strings; no
237+ * type coercion. Returns the whole content as `body` when no frontmatter
238+ * is present.
239+ *
240+ * @param {string } content
241+ * @returns {{frontmatter: Record<string, string>, body: string} }
242+ */
192243function parseFrontmatter ( content ) {
193244 const match = content . match ( / ^ - - - \n ( [ \s \S ] * ?) \n - - - \n ? ( [ \s \S ] * ) $ / ) ;
194245 if ( ! match ) return { frontmatter : { } , body : content } ;
@@ -392,6 +443,13 @@ async function getReleaseContext() {
392443 return { sourceBranch, currentLatest, willBeLatest, lineMatch } ;
393444}
394445
446+ /**
447+ * Entry point. Reads the raw changesets PR body from CHANGESET_PR_BODY env
448+ * or stdin, gathers package + server entries and release-branch context,
449+ * and writes the enhanced markdown body to stdout.
450+ *
451+ * @returns {Promise<void> }
452+ */
395453async function main ( ) {
396454 let rawBody = process . env . CHANGESET_PR_BODY || "" ;
397455 if ( ! rawBody && ! process . stdin . isTTY ) {
0 commit comments