forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-changelog.js
84 lines (72 loc) · 3.19 KB
/
build-changelog.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
80
81
82
83
84
const { diff } = require('@graphql-inspector/core')
const { loadSchema } = require('@graphql-tools/load')
const git = require('../../lib/git-utils')
const fs = require('fs')
// 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()
async function main () {
// Load the previous schema from this repo
// TODO -- how to make sure that this script runs _before_ this artifact is updated?
// Maybe hook into the existing `update-files` script instead of being a stand-alone script.
const oldSchemaString = fs.readFileSync('data/graphql/schema.docs.graphql').toString()
// Load the latest schema from github/github
const tree = await git.getTree('github', 'github', 'heads/master')
const schemaFileBlob = tree.find(entry => entry.path.includes('config/schema.docs.graphql') && entry.type === 'blob')
const newSchemaBuffer = await git.getContentsForBlob('github', 'github', schemaFileBlob)
// Create schema objects out of the strings
const oldSchema = await loadSchema(oldSchemaString)
const newSchema = await loadSchema(newSchemaBuffer.toString())
// Generate changes between the two schemas
const changes = diff(oldSchema, newSchema)
console.log(changes)
// If there were any changes, create a changelog entry
if (changes.length > 0) {
const previousChangelogString = fs.readFileSync('lib/graphql/static/changelog.json')
const previousChangelog = JSON.parse(previousChangelogString)
// Build a `yyyy-mm-dd`-formatted date string
const today = new Date()
const todayString = String(today.getFullYear()) + '-' + String(today.getMonth() + 1).padStart(2, '0') + '-' + String(today.getDate()).padStart(2, '0')
// TODO format `changes` into strings
const formattedChanges = []
// TODO how are these populated?
// {
// "title": "The [Checks preview](/graphql/overview/schema-previews#checks-preview) includes these changes:",
// "changes": [
// "Enum value `STALE` was added to enum `CheckConclusionState`",
// "Enum value `SKIPPED` was added to enum `CheckConclusionState`"
// ]
// }
const previewChanges = []
// TODO how are these populated?
// "upcomingChanges": [
// {
// "title": "The following changes will be made to the schema:",
// "changes": [
// "On member `Issue.timeline`: `timeline` will be removed. Use Issue.timelineItems instead. **Effective 2020-10-01**.",
// "On member `PullRequest.timeline`: `timeline` will be removed. Use PullRequest.timelineItems instead. **Effective 2020-10-01**."
// ]
// }
// ]
const upcomingChanges = []
// add a new entry to the changelog data
previousChangelog.unshift(
{
date: todayString,
schemaChanges: [
{
title: 'The GraphQL schema includes these changes:',
changes: formattedChanges
}
],
previewChanges: previewChanges,
upcomingChanges: upcomingChanges
}
)
// rewrite the updated changelog
fs.writeFileSync('lib/graphql/static/changelog.json', JSON.stringify(previousChangelog, null, 2))
}
}