( oldSchemaString, newSchemaString, previews, oldUpcomingChanges, newUpcomingChanges )
| 38 | * @return {object?} |
| 39 | */ |
| 40 | export async function createChangelogEntry( |
| 41 | oldSchemaString, |
| 42 | newSchemaString, |
| 43 | previews, |
| 44 | oldUpcomingChanges, |
| 45 | newUpcomingChanges |
| 46 | ) { |
| 47 | // Create schema objects out of the strings |
| 48 | const oldSchema = await loadSchema(oldSchemaString, {}) |
| 49 | const newSchema = await loadSchema(newSchemaString, {}) |
| 50 | |
| 51 | // Generate changes between the two schemas |
| 52 | const changes = await diff(oldSchema, newSchema) |
| 53 | const changesToReport = [] |
| 54 | changes.forEach(function (change) { |
| 55 | if (CHANGES_TO_REPORT.includes(change.type)) { |
| 56 | changesToReport.push(change) |
| 57 | } else if (CHANGES_TO_IGNORE.includes(change.type)) { |
| 58 | // Do nothing |
| 59 | } else { |
| 60 | throw new Error( |
| 61 | 'This change type should be added to CHANGES_TO_REPORT or CHANGES_TO_IGNORE: ' + change.type |
| 62 | ) |
| 63 | } |
| 64 | }) |
| 65 | |
| 66 | const { schemaChangesToReport, previewChangesToReport } = segmentPreviewChanges( |
| 67 | changesToReport, |
| 68 | previews |
| 69 | ) |
| 70 | |
| 71 | const addedUpcomingChanges = newUpcomingChanges.filter(function (change) { |
| 72 | // Manually check each of `newUpcomingChanges` for an equivalent entry |
| 73 | // in `oldUpcomingChanges`. |
| 74 | return !oldUpcomingChanges.find(function (oldChange) { |
| 75 | return ( |
| 76 | oldChange.location === change.location && |
| 77 | oldChange.date === change.date && |
| 78 | oldChange.description === change.description |
| 79 | ) |
| 80 | }) |
| 81 | }) |
| 82 | |
| 83 | // If there were any changes, create a changelog entry |
| 84 | if ( |
| 85 | schemaChangesToReport.length > 0 || |
| 86 | previewChangesToReport.length > 0 || |
| 87 | addedUpcomingChanges.length > 0 |
| 88 | ) { |
| 89 | const changelogEntry = { |
| 90 | schemaChanges: [], |
| 91 | previewChanges: [], |
| 92 | upcomingChanges: [], |
| 93 | } |
| 94 | |
| 95 | const cleanedSchemaChanges = cleanMessagesFromChanges(schemaChangesToReport) |
| 96 | const renderedScheamChanges = await Promise.all( |
| 97 | cleanedSchemaChanges.map(async (change) => { |
no test coverage detected