1
0
mirror of synced 2025-12-26 05:02:55 -05:00
Files
docs/.github/actions-scripts/content-changes-table-comment.js
Mike Surowiec e2a35b3c38 Cleanup preview env workflow variables (#25160)
* cleanup staging action vars, prep for OS deploy workflow

* fix app_url
2022-02-09 15:12:26 +00:00

52 lines
1.6 KiB
JavaScript
Executable File

#!/usr/bin/env node
import * as github from '@actions/github'
import { setOutput } from '@actions/core'
const { GITHUB_TOKEN, APP_URL } = process.env
const context = github.context
if (!GITHUB_TOKEN) {
throw new Error(`GITHUB_TOKEN environment variable not set`)
}
if (!APP_URL) {
throw new Error(`APP_URL environment variable not set`)
}
const octokit = github.getOctokit(GITHUB_TOKEN)
const response = await octokit.rest.repos.compareCommits({
owner: context.repo.owner,
repo: context.payload.repository.name,
base: context.payload.pull_request.base.sha,
head: context.payload.pull_request.head.sha,
})
const { files } = response.data
let markdownTable =
'| **Source** | **Preview** | **Production** | **What Changed** |\n|:----------- |:----------- |:----------- |:----------- |\n'
const pathPrefix = 'content/'
const articleFiles = files.filter(
({ filename }) => filename.startsWith(pathPrefix) && !filename.endsWith('/index.md')
)
for (const file of articleFiles) {
const sourceUrl = file.blob_url
const fileName = file.filename.slice(pathPrefix.length)
const fileUrl = fileName.slice(0, fileName.lastIndexOf('.'))
const previewLink = `${APP_URL}/${fileUrl}`
const productionLink = `https://docs.github.com/${fileUrl}`
let markdownLine = ''
if (file.status === 'modified') {
markdownLine = `| [content/${fileName}](${sourceUrl}) | [Modified](${previewLink}) | [Original](${productionLink}) | |\n`
} else if (file.status === 'added') {
markdownLine = `| New file: [content/${fileName}](${sourceUrl}) | [Modified](${previewLink}) | | |\n`
}
markdownTable += markdownLine
}
setOutput('changesTable', markdownTable)