1- /**
2- * Hi there! 👋
3- * To test this code locally, outside of Actions, you need to run
4- * the script src/workflows/content-changes-table-comment-cli.ts
5- *
6- * See the instructions in the doc string comment at the
7- * top of src/workflows/content-changes-table-comment-cli.ts
8- */
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.
94
105import fs from 'node:fs'
116import path from 'node:path'
@@ -26,11 +21,10 @@ import { inLiquid } from './lib/in-liquid'
2621const { GITHUB_TOKEN , APP_URL , BASE_SHA , HEAD_SHA } = process . env
2722const context = github . context
2823
29- // the max size of the comment (in bytes)
30- // the action we use to post the comment caps out at about 144kb
31- // see docs-engineering#1849 and peter-evans/create-or-update-comment#271 for more info.
32- // The max size the action allows is 2^16, but our table calculates near the end
33- // of its rendering before we add a key, so playing it safe with 2^15.
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.
3428const MAX_COMMENT_SIZE = 32768
3529
3630const PROD_URL = 'https://docs.github.com'
@@ -57,8 +51,7 @@ async function main(owner: string, repo: string, baseSHA: string, headSHA: strin
5751
5852 const octokit = retryingGithub ( GITHUB_TOKEN )
5953
60- // get the list of file changes from the PR
61- // this works even if the head commit is from a fork
54+ // The list of file changes, which works even for a head commit from a fork.
6255 const response = await octokit . rest . repos . compareCommitsWithBasehead ( {
6356 owner,
6457 repo,
@@ -109,15 +102,12 @@ async function main(owner: string, repo: string, baseSHA: string, headSHA: strin
109102 const fileName = file . filename . slice ( pathPrefix . length )
110103 const fileUrl = fileName . replace ( '/index.md' , '' ) . replace ( / \. m d $ / , '' )
111104
112- // get the file contents and decode them
113105 // this script is called from the main branch, so we need the API call to get the contents from the branch, instead
114106 const fileContents = await getContents (
115107 owner ,
116108 repo ,
117- // Can't get its content if it no longer exists.
118- // Meaning, you'd get a 404 on the `getContents()` utility function.
119- // So, to be able to get necessary meta data about what it *was*,
120- // if it was removed, fall back to the 'base'.
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.
121111 file . status === 'removed' ? baseSHA : headSHA ,
122112 file . filename ,
123113 )
@@ -209,23 +199,20 @@ function makeRow({
209199 contentCell += `[\`${ fileName } \`](${ sourceUrl } )`
210200
211201 try {
212- // the try/catch is needed because getApplicableVersions() returns either [] or throws an error when it can't parse the versions frontmatter
213- // try/catch can be removed if docs-engineering#1821 is resolved
214- // i.e. for feature based versioning, like ghec: 'issue-6337'
202+ // getApplicableVersions() throws on missing, invalid or unsupported
203+ // versions frontmatter. Remove the try/catch once
204+ // github/docs-engineering#1821 is fixed.
215205 const fileVersions : string [ ] = getApplicableVersions ( data ?. versions )
216206
217207 for ( const plan in allVersionShortnames ) {
218- // plan is the shortName (i.e., fpt)
219- // allVersionShortNames[plan] is the planName (i.e., free-pro-team)
220-
221- // walk by the plan names since we generate links differently for most plans
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.
222211 const versions = fileVersions . filter ( ( fileVersion ) =>
223212 fileVersion . includes ( allVersionShortnames [ plan ] ) ,
224213 )
225214
226215 if ( versions . length === 1 ) {
227- // for fpt and ghec
228-
229216 if ( versions . toString ( ) === nonEnterpriseDefaultVersion ) {
230217 // omit version from fpt url
231218
0 commit comments