Skip to content

Commit b981743

Browse files
authored
Merge pull request #16858 from github/update-dates-script
Refactor update-enterprise-dates script
2 parents fc6af9d + bc01b6c commit b981743

3 files changed

Lines changed: 28 additions & 62 deletions

File tree

lib/enterprise-dates.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
"deprecationDate": "2021-09-23"
9393
},
9494
"3.0": {
95-
"releaseDate": "2020-12-08",
95+
"releaseDate": "2020-12-16",
9696
"deprecationDate": "2021-12-08"
9797
}
9898
}

script/update-enterprise-dates.js

Lines changed: 26 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,44 @@
11
#!/usr/bin/env node
22

3-
const github = require('../lib/github')
3+
const { getContents } = require('../lib/git-utils')
44
const fs = require('fs')
55
const path = require('path')
6-
const filename = path.join(__dirname, '../lib/enterprise-dates.json')
7-
const jsonFile = require(filename)
6+
const enterpriseDatesFile = path.join(__dirname, '../lib/enterprise-dates.json')
7+
const enterpriseDatesString = fs.readFileSync(enterpriseDatesFile, 'utf8')
88

99
// [start-readme]
1010
//
11-
// Run this script during Enterprise releases and deprecations.
12-
// It uses the GitHub API to get dates from enterprise-releases and updates `lib/enterprise-dates.json`.
13-
// The help site uses this JSON to display dates at the top of some Enterprise versions.
14-
//
15-
// This script requires that you have a GitHub Personal Access Token in a `.env` file.
16-
// If you don't have a token, get one [here](https://github.com/settings/tokens/new?scopes=repo&description=docs-dev).
17-
// If you don't have an `.env` file in your docs checkout, run this command in Terminal:
18-
//
19-
// `cp .env.example .env`
20-
//
21-
// Open the `.env` file in a text editor, and find the `GITHUB_TOKEN=` placeholder. Add your token after the equals sign.
22-
//
23-
// Do not commit the `.env` file; just leave it in your checkout.
11+
// This script fetches data from https://github.com/github/enterprise-releases/blob/master/releases.json
12+
// and updates `lib/enterprise-dates.json`, which the site uses for various functionality.
2413
//
2514
// [end-readme]
2615

16+
// check for required PAT
17+
if (!process.env.GITHUB_TOKEN) {
18+
console.error('Error! You must have a GITHUB_TOKEN set in an .env file to run this script.')
19+
process.exit(1)
20+
}
21+
2722
main()
2823

29-
// GHE Release Lifecycle Dates
3024
async function main () {
31-
let raw
32-
try {
33-
raw = await getDataFromReleasesRepo()
34-
} catch (err) {
35-
console.log('error getting JSON from enterprise-releases repo')
36-
throw (err)
37-
}
38-
const json = prepareData(raw)
39-
if (json === prettify(jsonFile)) {
40-
console.log('This repo is already in sync with enterprise-releases!')
41-
} else {
42-
fs.writeFileSync(filename, json, 'utf8')
43-
console.log(`${filename} has been updated!`)
44-
}
45-
}
25+
// send owner, repo, ref, path
26+
const rawDates = JSON.parse(await getContents('github', 'enterprise-releases', 'master', 'releases.json'))
4627

47-
// Uses https://octokit.github.io/rest.js/#api-Repos-getContents
48-
async function getDataFromReleasesRepo () {
49-
const octokit = github()
50-
const { data } = await octokit.repos.getContents({
51-
owner: 'github',
52-
repo: 'enterprise-releases',
53-
path: 'releases.json',
54-
ref: 'master',
55-
headers: { accept: 'application/vnd.github.v3.raw+json' }
28+
const formattedDates = {}
29+
Object.entries(rawDates).forEach(([releaseNumber, releaseObject]) => {
30+
formattedDates[releaseNumber] = {
31+
releaseDate: releaseObject.release_candidate || releaseObject.start,
32+
deprecationDate: releaseObject.end
33+
}
5634
})
57-
return data
58-
}
5935

60-
// We only need some of the values from the source JSON
61-
// We use https://github.com/zeke/browser-date-formatter on the client side to reformat the dates
62-
function prepareData (raw) {
63-
const data = Object.entries(JSON.parse(raw))
64-
const obj = {}
65-
data.forEach(versions => {
66-
const datesObj = {}
67-
const version = versions[0]
68-
const releaseDate = versions[1].start
69-
const deprecationDate = versions[1].end
70-
datesObj.releaseDate = releaseDate
71-
datesObj.deprecationDate = deprecationDate
72-
obj[version] = datesObj
73-
})
74-
return prettify(obj)
75-
}
36+
const formattedDatesString = JSON.stringify(formattedDates, null, 2)
7637

77-
function prettify (json) {
78-
return JSON.stringify(json, null, 2)
38+
if (formattedDatesString === enterpriseDatesString) {
39+
console.log('This repo is already in sync with enterprise-releases!')
40+
} else {
41+
fs.writeFileSync(enterpriseDatesFile, formattedDatesString)
42+
console.log(`${enterpriseDatesFile} has been updated!`)
43+
}
7944
}

tests/meta/repository-references.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const ALLOW_LIST = new Set([
1515
'platform-samples',
1616
'github-services',
1717
'explore',
18+
'enterprise-releases',
1819
'markup',
1920
'hubot',
2021
'VisualStudio',

0 commit comments

Comments
 (0)