forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-enterprise-dates.js
executable file
·79 lines (72 loc) · 2.47 KB
/
update-enterprise-dates.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env node
const github = require('../lib/github')
const fs = require('fs')
const path = require('path')
const filename = path.join(__dirname, '../lib/enterprise-dates.json')
const jsonFile = require(filename)
// [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.
//
// [end-readme]
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)) {
console.log('This repo is already in sync with enterprise-releases!')
} else {
fs.writeFileSync(filename, json, 'utf8')
console.log(`${filename} 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)
}