From 63a6fa98d350731d270afaad9c7a6a777f4e36aa Mon Sep 17 00:00:00 2001 From: Sarah Schneider Date: Wed, 9 Dec 2020 20:19:40 -0500 Subject: [PATCH 1/4] use release_candidate instead of start date if present --- script/update-enterprise-dates.js | 88 +++++++++---------------------- 1 file changed, 26 insertions(+), 62 deletions(-) diff --git a/script/update-enterprise-dates.js b/script/update-enterprise-dates.js index 9f3c67f972..9eeffbed27 100755 --- a/script/update-enterprise-dates.js +++ b/script/update-enterprise-dates.js @@ -1,79 +1,43 @@ #!/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)) { + 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) -} From fa2b8b69dc58764d0a6bbfa51c06d7f40a01c71d Mon Sep 17 00:00:00 2001 From: Sarah Schneider Date: Wed, 9 Dec 2020 20:26:36 -0500 Subject: [PATCH 2/4] ran script/update-enterprise-dates.js --- lib/enterprise-dates.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/enterprise-dates.json b/lib/enterprise-dates.json index d5724da995..b397abfbba 100644 --- a/lib/enterprise-dates.json +++ b/lib/enterprise-dates.json @@ -92,7 +92,7 @@ "deprecationDate": "2021-09-23" }, "3.0": { - "releaseDate": "2020-12-08", + "releaseDate": "2020-12-16", "deprecationDate": "2021-12-08" } } \ No newline at end of file From 4275c87be0c9cec414c0ec8d917b5e2f3f526dba Mon Sep 17 00:00:00 2001 From: Sarah Schneider Date: Wed, 9 Dec 2020 20:29:40 -0500 Subject: [PATCH 3/4] add comment --- script/update-enterprise-dates.js | 1 + 1 file changed, 1 insertion(+) diff --git a/script/update-enterprise-dates.js b/script/update-enterprise-dates.js index 9eeffbed27..9bdeb549f1 100755 --- a/script/update-enterprise-dates.js +++ b/script/update-enterprise-dates.js @@ -22,6 +22,7 @@ if (!process.env.GITHUB_TOKEN) { main() async function main () { + // send owner, repo, ref, path const rawDates = JSON.parse(await getContents('github', 'enterprise-releases', 'master', 'releases.json')) const formattedDates = {} From e0c929c13f770859a228bff9606d2eb4cab9fc79 Mon Sep 17 00:00:00 2001 From: Sarah Schneider Date: Wed, 9 Dec 2020 21:13:11 -0500 Subject: [PATCH 4/4] add exclusion --- tests/meta/repository-references.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/meta/repository-references.js b/tests/meta/repository-references.js index 9df0e07888..518ad3e735 100644 --- a/tests/meta/repository-references.js +++ b/tests/meta/repository-references.js @@ -15,6 +15,7 @@ const ALLOW_LIST = new Set([ 'platform-samples', 'github-services', 'explore', + 'enterprise-releases', 'markup', 'hubot', 'VisualStudio',