зеркало из https://github.com/github/docs.git
Add upcoming changes to build-changelog
This commit is contained in:
Родитель
7b7ae0b5e4
Коммит
360c517a7d
|
@ -26,23 +26,42 @@ async function main() {
|
||||||
const previewsString = fs.readFileSync('data/graphql/graphql_previews.yml')
|
const previewsString = fs.readFileSync('data/graphql/graphql_previews.yml')
|
||||||
const previews = yaml.safeLoad(previewsString)
|
const previews = yaml.safeLoad(previewsString)
|
||||||
|
|
||||||
const changelogEntry = createChangelogEntry(oldSchemaString, newSchemaBuffer.toString(), previews)
|
// TODO how to make sure to get these before the file is updated?
|
||||||
if (changelogEntry) {
|
const oldUpcomingChangesString = fs.readFileSync('data/graphql/graphql_upcoming_changes_public.yml')
|
||||||
// Build a `yyyy-mm-dd`-formatted date string
|
const oldUpcomingChanges = yaml.safeLoad(oldUpcomingChangesString).upcoming_changes
|
||||||
// and tag the changelog entry with it
|
// TODO actually get different changes here
|
||||||
const today = new Date()
|
const newUpcomingChanges = oldUpcomingChanges
|
||||||
const todayString = String(today.getFullYear()) + '-' + String(today.getMonth() + 1).padStart(2, '0') + '-' + String(today.getDate()).padStart(2, '0')
|
|
||||||
changelogEntry.date = todayString
|
|
||||||
|
|
||||||
const previousChangelogString = fs.readFileSync('lib/graphql/static/changelog.json')
|
const changelogEntry = createChangelogEntry(oldSchemaString, newSchemaBuffer.toString(), previews, oldUpcomingChanges, newUpcomingChanges)
|
||||||
const previousChangelog = JSON.parse(previousChangelogString)
|
if (changelogEntry) {
|
||||||
// add a new entry to the changelog data
|
prependDatedEntry(changelogEntry, 'lib/graphql/static/changelog.json')
|
||||||
previousChangelog.unshift(changelogEntry)
|
|
||||||
// rewrite the updated changelog
|
|
||||||
fs.writeFileSync('lib/graphql/static/changelog.json', JSON.stringify(previousChangelog, null, 2))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tag `changelogEntry` with `date: YYYY-mm-dd`, then prepend it to the JSON
|
||||||
|
* structure written to `targetPath`. (`changelogEntry` and that file are modified in place.)
|
||||||
|
* @param {object} changelogEntry
|
||||||
|
* @param {string} targetPath
|
||||||
|
* @return {void}
|
||||||
|
*/
|
||||||
|
function prependDatedEntry(changelogEntry, targetPath) {
|
||||||
|
// Build a `yyyy-mm-dd`-formatted date string
|
||||||
|
// and tag the changelog entry with it
|
||||||
|
const today = new Date()
|
||||||
|
const todayString = String(today.getFullYear()) + '-' +
|
||||||
|
String(today.getMonth() + 1).padStart(2, '0') + '-' +
|
||||||
|
String(today.getDate()).padStart(2, '0')
|
||||||
|
changelogEntry.date = todayString
|
||||||
|
|
||||||
|
const previousChangelogString = fs.readFileSync(targetPath)
|
||||||
|
const previousChangelog = JSON.parse(previousChangelogString)
|
||||||
|
// add a new entry to the changelog data
|
||||||
|
previousChangelog.unshift(changelogEntry)
|
||||||
|
// rewrite the updated changelog
|
||||||
|
fs.writeFileSync(targetPath, JSON.stringify(previousChangelog, null, 2))
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare `oldSchemaString` to `newSchemaString`, and if there are any
|
* Compare `oldSchemaString` to `newSchemaString`, and if there are any
|
||||||
* changes that warrant a changelog entry, return a changelog entry.
|
* changes that warrant a changelog entry, return a changelog entry.
|
||||||
|
@ -50,10 +69,12 @@ async function main() {
|
||||||
* Otherwise, return null.
|
* Otherwise, return null.
|
||||||
* @param {string} [oldSchemaString]
|
* @param {string} [oldSchemaString]
|
||||||
* @param {string} [newSchemaString]
|
* @param {string} [newSchemaString]
|
||||||
* @param {object} [previews]
|
* @param {Array<object>} [previews]
|
||||||
|
* @param {Array<object>} [oldUpcomingChanges]
|
||||||
|
* @param {Array<object>} [newUpcomingChanges]
|
||||||
* @return {object?}
|
* @return {object?}
|
||||||
*/
|
*/
|
||||||
async function createChangelogEntry(oldSchemaString, newSchemaString, previews) {
|
async function createChangelogEntry(oldSchemaString, newSchemaString, previews, oldUpcomingChanges, newUpcomingChanges) {
|
||||||
// Create schema objects out of the strings
|
// Create schema objects out of the strings
|
||||||
const oldSchema = await loadSchema(oldSchemaString)
|
const oldSchema = await loadSchema(oldSchemaString)
|
||||||
const newSchema = await loadSchema(newSchemaString)
|
const newSchema = await loadSchema(newSchemaString)
|
||||||
|
@ -72,8 +93,20 @@ async function createChangelogEntry(oldSchemaString, newSchemaString, previews)
|
||||||
})
|
})
|
||||||
|
|
||||||
const { schemaChangesToReport, previewChangesToReport } = segmentPreviewChanges(changesToReport, previews)
|
const { schemaChangesToReport, previewChangesToReport } = segmentPreviewChanges(changesToReport, previews)
|
||||||
|
|
||||||
|
const addedUpcomingChanges = newUpcomingChanges.filter(function (change) {
|
||||||
|
// Manually check each of `newUpcomingChanges` for an equivalent entry
|
||||||
|
// in `oldUpcomingChanges`.
|
||||||
|
return !oldUpcomingChanges.find(function (oldChange) {
|
||||||
|
return (oldChange.location == change.location &&
|
||||||
|
oldChange.date == change.date &&
|
||||||
|
oldChange.description == change.description
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// If there were any changes, create a changelog entry
|
// If there were any changes, create a changelog entry
|
||||||
if (schemaChangesToReport.length > 0 || previewChangesToReport.length > 0) {
|
if (schemaChangesToReport.length > 0 || previewChangesToReport.length > 0 || addedUpcomingChanges.length > 0) {
|
||||||
const changelogEntry = {
|
const changelogEntry = {
|
||||||
schemaChanges: [],
|
schemaChanges: [],
|
||||||
previewChanges: [],
|
previewChanges: [],
|
||||||
|
@ -97,17 +130,18 @@ async function createChangelogEntry(oldSchemaString, newSchemaString, previews)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO how are these populated?
|
if (addedUpcomingChanges.length > 0) {
|
||||||
// "upcomingChanges": [
|
changelogEntry.upcomingChanges.push({
|
||||||
// {
|
title: "The following changes will be made to the schema:",
|
||||||
// "title": "The following changes will be made to the schema:",
|
changes: addedUpcomingChanges.map(function (change) {
|
||||||
// "changes": [
|
const location = change.location
|
||||||
// "On member `Issue.timeline`: `timeline` will be removed. Use Issue.timelineItems instead. **Effective 2020-10-01**.",
|
const description = change.description
|
||||||
// "On member `PullRequest.timeline`: `timeline` will be removed. Use PullRequest.timelineItems instead. **Effective 2020-10-01**."
|
const date = change.date.split("T")[0]
|
||||||
// ]
|
return "On member `" + location + "`:" + description + " **Effective " + date + "**."
|
||||||
// }
|
})
|
||||||
// ]
|
})
|
||||||
const upcomingChanges = []
|
}
|
||||||
|
|
||||||
return changelogEntry
|
return changelogEntry
|
||||||
} else {
|
} else {
|
||||||
return null
|
return null
|
||||||
|
|
|
@ -23,6 +23,13 @@ Object {
|
||||||
"title": "The GraphQL schema includes these changes:",
|
"title": "The GraphQL schema includes these changes:",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"upcomingChanges": Array [],
|
"upcomingChanges": Array [
|
||||||
|
Object {
|
||||||
|
"changes": Array [
|
||||||
|
"On member \`Query.stableField\`:\`stableField\` will be removed. **Effective 2021-06-01**.",
|
||||||
|
],
|
||||||
|
"title": "The following changes will be made to the schema:",
|
||||||
|
},
|
||||||
|
],
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -49,7 +49,24 @@ describe('creating a changelog from old schema and new schema', () => {
|
||||||
- '@github/engineering'
|
- '@github/engineering'
|
||||||
`)
|
`)
|
||||||
|
|
||||||
const entry = await createChangelogEntry(oldSchemaString, newSchemaString, previews)
|
oldUpcomingChanges = yaml.safeLoad(`
|
||||||
|
upcoming_changes:
|
||||||
|
- location: EnterprisePendingCollaboratorEdge.isUnlicensed
|
||||||
|
description: '\`isUnlicensed\` will be removed.'
|
||||||
|
date: '2021-01-01T00:00:00+00:00'
|
||||||
|
`).upcoming_changes
|
||||||
|
|
||||||
|
newUpcomingChanges = yaml.safeLoad(`
|
||||||
|
upcoming_changes:
|
||||||
|
- location: Query.stableField
|
||||||
|
description: '\`stableField\` will be removed.'
|
||||||
|
date: '2021-06-01T00:00:00+00:00'
|
||||||
|
- location: EnterprisePendingCollaboratorEdge.isUnlicensed
|
||||||
|
description: '\`isUnlicensed\` will be removed.'
|
||||||
|
date: '2021-01-01T00:00:00+00:00'
|
||||||
|
`).upcoming_changes
|
||||||
|
|
||||||
|
const entry = await createChangelogEntry(oldSchemaString, newSchemaString, previews, oldUpcomingChanges, newUpcomingChanges)
|
||||||
expect(entry).toMatchSnapshot()
|
expect(entry).toMatchSnapshot()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -59,7 +76,7 @@ describe('creating a changelog from old schema and new schema', () => {
|
||||||
i: Int!
|
i: Int!
|
||||||
}`
|
}`
|
||||||
|
|
||||||
const nullEntry = await createChangelogEntry(schemaString, schemaString, [])
|
const nullEntry = await createChangelogEntry(schemaString, schemaString, [], [], [])
|
||||||
expect(nullEntry).toBeNull()
|
expect(nullEntry).toBeNull()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Загрузка…
Ссылка в новой задаче