forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
91 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
"account":{ | ||
"type":"Organization", | ||
"id":28536653, | ||
"node_id": "MDEyOk9yZ2FuaXphdGlvbjE=", | ||
"login":"organizationUsername", | ||
"organization_billing_email":"[email protected]" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
"account":{ | ||
"type":"Organization", | ||
"id":18404719, | ||
"node_id": "MDEyOk9yZ2FuaXphdGlvbjE=", | ||
"login":"username", | ||
"organization_billing_email":"[email protected]" | ||
}, | ||
|
@@ -52,6 +53,7 @@ | |
"account":{ | ||
"type":"Organization", | ||
"id":18404719, | ||
"node_id": "MDEyOk9yZ2FuaXphdGlvbjE=", | ||
"login":"username", | ||
"organization_billing_email":"[email protected]" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
"account":{ | ||
"type":"Organization", | ||
"id":18404719, | ||
"node_id": "MDEyOk9yZ2FuaXphdGlvbjE=", | ||
"login":"username", | ||
"organization_billing_email":"[email protected]" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) { | ||
console.log('This repo is already in sync with enterprise-releases!') | ||
} else { | ||
fs.writeFileSync(filename, json, 'utf8') | ||
console.log(`${filename} has been updated!`) | ||
} | ||
} | ||
// send owner, repo, ref, path | ||
const rawDates = JSON.parse(await getContents('github', 'enterprise-releases', 'master', 'releases.json')) | ||
|
||
// 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' } | ||
const formattedDates = {} | ||
Object.entries(rawDates).forEach(([releaseNumber, releaseObject]) => { | ||
formattedDates[releaseNumber] = { | ||
releaseDate: releaseObject.release_candidate || releaseObject.start, | ||
deprecationDate: releaseObject.end | ||
} | ||
}) | ||
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) | ||
} | ||
const formattedDatesString = JSON.stringify(formattedDates, null, 2) | ||
|
||
function prettify (json) { | ||
return JSON.stringify(json, null, 2) | ||
if (formattedDatesString === enterpriseDatesString) { | ||
console.log('This repo is already in sync with enterprise-releases!') | ||
} else { | ||
fs.writeFileSync(enterpriseDatesFile, formattedDatesString) | ||
console.log(`${enterpriseDatesFile} has been updated!`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters