1- // To test this locally, outside of Actions, run
2- // src/workflows/content-changes-table-comment-cli.ts. Its file header has the
3- // instructions.
1+ // Run src/workflows/content-changes-table-comment-cli.ts to test this outside Actions.
42
53import fs from 'node:fs'
64import path from 'node:path'
@@ -21,15 +19,12 @@ import { inLiquid } from './lib/in-liquid'
2119const { GITHUB_TOKEN , APP_URL , BASE_SHA , HEAD_SHA } = process . env
2220const context = github . context
2321
24- // Max table size in characters. peter-evans/create-or-update-comment allows a
25- // 2^16 character comment, but the table measures itself near the end of
26- // rendering, before the key is added, so this stays at 2^15 for headroom. See
27- // github/docs-engineering#1849 and peter-evans/create-or-update-comment#271.
22+ // peter-evans/create-or-update-comment allows 65,536-character comments. This
23+ // table measures itself before adding the key, so 32,768 leaves headroom.
2824const MAX_COMMENT_SIZE = 32768
2925
3026const PROD_URL = 'https://docs.github.com'
3127
32- // When this file is invoked directly from action as opposed to being imported
3328if ( import . meta. url . endsWith ( process . argv [ 1 ] ) ) {
3429 const baseOwner = context . payload . pull_request ! . base . repo . owner . login
3530 const baseRepo = context . payload . pull_request ! . base . repo . name
@@ -51,7 +46,7 @@ async function main(owner: string, repo: string, baseSHA: string, headSHA: strin
5146
5247 const octokit = retryingGithub ( GITHUB_TOKEN )
5348
54- // The list of file changes, which works even for a head commit from a fork .
49+ // Compare through the base repo so forked head commits work .
5550 const response = await octokit . rest . repos . compareCommitsWithBasehead ( {
5651 owner,
5752 repo,
@@ -102,12 +97,11 @@ async function main(owner: string, repo: string, baseSHA: string, headSHA: strin
10297 const fileName = file . filename . slice ( pathPrefix . length )
10398 const fileUrl = fileName . replace ( '/index.md' , '' ) . replace ( / \. m d $ / , '' )
10499
105- // this script is called from the main branch , so we need the API call to get the contents from the branch, instead
100+ // The workflow runs from main, so request the file from the changed branch.
106101 const fileContents = await getContents (
107102 owner ,
108103 repo ,
109- // `getContents()` 404s on a file that no longer exists, so for a
110- // removed file read the base sha to get metadata about what it was.
104+ // Removed files need the base SHA because getContents 404s at the head SHA.
111105 file . status === 'removed' ? baseSHA : headSHA ,
112106 file . filename ,
113107 )
@@ -199,33 +193,29 @@ function makeRow({
199193 contentCell += `[\`${ fileName } \`](${ sourceUrl } )`
200194
201195 try {
202- // getApplicableVersions() throws on missing, invalid or unsupported
203- // versions frontmatter. Remove the try/catch once
204- // github/docs-engineering#1821 is fixed.
196+ // getApplicableVersions throws for missing, invalid, or unsupported versions frontmatter.
205197 const fileVersions : string [ ] = getApplicableVersions ( data ?. versions )
206198
207199 for ( const plan in allVersionShortnames ) {
208- // `plan` is the short name, e.g. fpt, used as the link label.
209- // allVersionShortnames[plan] is the plan name, e.g. free-pro-team, used
210- // to pick the file's matching versions. Most plans link differently.
200+ // Plan shortnames, for example fpt, label links; full names match versions.
211201 const versions = fileVersions . filter ( ( fileVersion ) =>
212202 fileVersion . includes ( allVersionShortnames [ plan ] ) ,
213203 )
214204
215205 if ( versions . length === 1 ) {
216206 if ( versions . toString ( ) === nonEnterpriseDefaultVersion ) {
217- // omit version from fpt url
207+ // Default free-pro-team URLs omit the version segment.
218208
219209 reviewCell += `[${ plan } ](${ APP_URL } /${ fileUrl } )<br>`
220210 prodCell += `[${ plan } ](${ PROD_URL } /${ fileUrl } )<br>`
221211 } else {
222- // for non-versioned releases (ghec) use full url
212+ // Other single-version releases use the full version URL.
223213
224214 reviewCell += `[${ plan } ](${ APP_URL } /${ versions } /${ fileUrl } )<br>`
225215 prodCell += `[${ plan } ](${ PROD_URL } /${ versions } /${ fileUrl } )<br>`
226216 }
227217 } else if ( versions . length ) {
228- // for ghes releases, link each version
218+ // GHES releases link each matching version.
229219
230220 reviewCell += `${ plan } @ `
231221 prodCell += `${ plan } @ `
@@ -246,8 +236,7 @@ function makeRow({
246236 let note = ''
247237 if ( file . status === 'removed' ) {
248238 note = 'removed'
249- // If the file was removed, the `reviewCell` no longer makes sense
250- // since it was based on looking at the base sha.
239+ // Removed files do not exist in the review environment, so review links do not apply.
251240 reviewCell = 'n/a'
252241 } else if ( fromReusable ) {
253242 note += 'from reusable'
0 commit comments