зеркало из https://github.com/github/docs.git
Merge pull request #16858 from github/update-dates-script
Refactor update-enterprise-dates script
This commit is contained in:
Коммит
b981743f4b
|
@ -92,7 +92,7 @@
|
|||
"deprecationDate": "2021-09-23"
|
||||
},
|
||||
"3.0": {
|
||||
"releaseDate": "2020-12-08",
|
||||
"releaseDate": "2020-12-16",
|
||||
"deprecationDate": "2021-12-08"
|
||||
}
|
||||
}
|
|
@ -1,79 +1,44 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const github = require('../lib/github')
|
||||
const { getContents } = require('../lib/git-utils')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const filename = path.join(__dirname, '../lib/enterprise-dates.json')
|
||||
const jsonFile = require(filename)
|
||||
const enterpriseDatesFile = path.join(__dirname, '../lib/enterprise-dates.json')
|
||||
const enterpriseDatesString = fs.readFileSync(enterpriseDatesFile, 'utf8')
|
||||
|
||||
// [start-readme]
|
||||
//
|
||||
// Run this script during Enterprise releases and deprecations.
|
||||
// It uses the GitHub API to get dates from enterprise-releases and updates `lib/enterprise-dates.json`.
|
||||
// The help site uses this JSON to display dates at the top of some Enterprise versions.
|
||||
//
|
||||
// This script requires that you have a GitHub Personal Access Token in a `.env` file.
|
||||
// If you don't have a token, get one [here](https://github.com/settings/tokens/new?scopes=repo&description=docs-dev).
|
||||
// If you don't have an `.env` file in your docs checkout, run this command in Terminal:
|
||||
//
|
||||
// `cp .env.example .env`
|
||||
//
|
||||
// Open the `.env` file in a text editor, and find the `GITHUB_TOKEN=` placeholder. Add your token after the equals sign.
|
||||
//
|
||||
// Do not commit the `.env` file; just leave it in your checkout.
|
||||
// This script fetches data from https://github.com/github/enterprise-releases/blob/master/releases.json
|
||||
// and updates `lib/enterprise-dates.json`, which the site uses for various functionality.
|
||||
//
|
||||
// [end-readme]
|
||||
|
||||
// check for required PAT
|
||||
if (!process.env.GITHUB_TOKEN) {
|
||||
console.error('Error! You must have a GITHUB_TOKEN set in an .env file to run this script.')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
main()
|
||||
|
||||
// GHE Release Lifecycle Dates
|
||||
async function main () {
|
||||
let raw
|
||||
try {
|
||||
raw = await getDataFromReleasesRepo()
|
||||
} catch (err) {
|
||||
console.log('error getting JSON from enterprise-releases repo')
|
||||
throw (err)
|
||||
}
|
||||
const json = prepareData(raw)
|
||||
if (json === prettify(jsonFile)) {
|
||||
// send owner, repo, ref, path
|
||||
const rawDates = JSON.parse(await getContents('github', 'enterprise-releases', 'master', 'releases.json'))
|
||||
|
||||
const formattedDates = {}
|
||||
Object.entries(rawDates).forEach(([releaseNumber, releaseObject]) => {
|
||||
formattedDates[releaseNumber] = {
|
||||
releaseDate: releaseObject.release_candidate || releaseObject.start,
|
||||
deprecationDate: releaseObject.end
|
||||
}
|
||||
})
|
||||
|
||||
const formattedDatesString = JSON.stringify(formattedDates, null, 2)
|
||||
|
||||
if (formattedDatesString === enterpriseDatesString) {
|
||||
console.log('This repo is already in sync with enterprise-releases!')
|
||||
} else {
|
||||
fs.writeFileSync(filename, json, 'utf8')
|
||||
console.log(`${filename} has been updated!`)
|
||||
fs.writeFileSync(enterpriseDatesFile, formattedDatesString)
|
||||
console.log(`${enterpriseDatesFile} has been updated!`)
|
||||
}
|
||||
}
|
||||
|
||||
// Uses https://octokit.github.io/rest.js/#api-Repos-getContents
|
||||
async function getDataFromReleasesRepo () {
|
||||
const octokit = github()
|
||||
const { data } = await octokit.repos.getContents({
|
||||
owner: 'github',
|
||||
repo: 'enterprise-releases',
|
||||
path: 'releases.json',
|
||||
ref: 'master',
|
||||
headers: { accept: 'application/vnd.github.v3.raw+json' }
|
||||
})
|
||||
return data
|
||||
}
|
||||
|
||||
// We only need some of the values from the source JSON
|
||||
// We use https://github.com/zeke/browser-date-formatter on the client side to reformat the dates
|
||||
function prepareData (raw) {
|
||||
const data = Object.entries(JSON.parse(raw))
|
||||
const obj = {}
|
||||
data.forEach(versions => {
|
||||
const datesObj = {}
|
||||
const version = versions[0]
|
||||
const releaseDate = versions[1].start
|
||||
const deprecationDate = versions[1].end
|
||||
datesObj.releaseDate = releaseDate
|
||||
datesObj.deprecationDate = deprecationDate
|
||||
obj[version] = datesObj
|
||||
})
|
||||
return prettify(obj)
|
||||
}
|
||||
|
||||
function prettify (json) {
|
||||
return JSON.stringify(json, null, 2)
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ const ALLOW_LIST = new Set([
|
|||
'platform-samples',
|
||||
'github-services',
|
||||
'explore',
|
||||
'enterprise-releases',
|
||||
'markup',
|
||||
'hubot',
|
||||
'VisualStudio',
|
||||
|
|
Загрузка…
Ссылка в новой задаче