Skip to content

Commit 04c03b1

Browse files
authored
Merge branch 'main' into repo-sync
2 parents 300f3bb + 639dfd6 commit 04c03b1

2 files changed

Lines changed: 61 additions & 1 deletion

File tree

.github/workflows/confirm-internal-staff-work-in-docs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ jobs:
6161
owner: 'github',
6262
repo: 'docs-internal',
6363
title: `@${context.payload.sender.login} confirm that \#${issueNo} should be in the public github/docs repo`,
64-
body: `@${context.payload.sender.login} opened https://github.com/github/docs/issues/${issueNo} publicly in the github/docs repo, instead of the private github/docs-internal repo.\n\n@${context.payload.sender.login}, please confirm that this belongs in the public repo and that no sensitive information was disclosed by commenting below and closing the issue.\n\nIf this was not intentional and sensitive information was shared, please delete https://github.com/github/docs/issues/${issueNo} and notify us in the \#docs-open-source channel.\n\nThanks! \n\n/cc @github/docs @github/docs-engineering`
64+
body: `@${context.payload.sender.login} opened https://github.com/github/docs/issues/${issueNo} publicly in the github/docs repo, instead of the private github/docs-internal repo.\n\n@${context.payload.sender.login}, please confirm that this belongs in the public repo and that no sensitive information was disclosed by commenting below and closing the issue.\n\nIf this was not intentional and sensitive information was shared, please delete https://github.com/github/docs/issues/${issueNo} and notify us in the \#docs-open-source channel.\n\nThanks! \n\n/cc @github/docs @github/docs-engineering`,
65+
labels: ['OS confirmation'],
6566
});
6667
6768
core.setOutput('did_warn', 'true')
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env node
2+
3+
// [start-readme]
4+
//
5+
// Run this script to fix known frontmatter errors by copying values from english file
6+
// Translatable properties are designated in the frontmatter JSON schema
7+
//
8+
// [end-readme]
9+
10+
const { execSync } = require('child_process')
11+
const fs = require('fs')
12+
const path = require('path')
13+
const readFileAsync = require('../../lib/readfile-async')
14+
const fm = require('../../lib/frontmatter')
15+
const matter = require('gray-matter')
16+
17+
const extractFrontmatter = async (path) => {
18+
const fileContents = await readFileAsync(path, 'utf8')
19+
return fm(fileContents)
20+
}
21+
22+
// Find all content files that differ from the default branch
23+
// TODO: make sure this will work in an Actions workflow
24+
const cmd = 'git -c diff.renameLimit=10000 diff --name-only origin/main'
25+
const changedFilesRelPaths = execSync(cmd)
26+
.toString()
27+
.split('\n')
28+
.filter(filename => {
29+
return filename.startsWith('translations/') &&
30+
filename.includes('/content/') &&
31+
!filename.endsWith('README.md')
32+
})
33+
34+
changedFilesRelPaths.forEach(async (relPath) => {
35+
const localisedAbsPath = path.join(__dirname, '../..', relPath)
36+
// find the corresponding english file by removing the first 2 path segments: /translations/<language code>
37+
const engAbsPath = path.join(__dirname, '../..', relPath.split(path.sep).slice(2).join(path.sep))
38+
39+
const localisedFrontmatter = await extractFrontmatter(localisedAbsPath)
40+
if (!localisedFrontmatter) return
41+
42+
// Load frontmatter from the source english file
43+
const englishFrontmatter = await extractFrontmatter(engAbsPath)
44+
45+
// Look for differences between the english and localised non-translatable properties
46+
let overWroteSomething = false
47+
for (const prop in englishFrontmatter.data) {
48+
if (!fm.schema.properties[prop].translatable && localisedFrontmatter.data[prop] !== englishFrontmatter.data[prop]) {
49+
localisedFrontmatter.data[prop] = englishFrontmatter.data[prop]
50+
overWroteSomething = true
51+
}
52+
}
53+
54+
// rewrite the localised file, if it changed
55+
if (overWroteSomething) {
56+
const toWrite = matter.stringify(localisedFrontmatter.content, localisedFrontmatter.data, { lineWidth: 10000, forceQuotes: true })
57+
fs.writeFileSync(localisedAbsPath, toWrite)
58+
}
59+
})

0 commit comments

Comments
 (0)