From 5e979403a0fbf9d790a67806a7ddd38a60a6c343 Mon Sep 17 00:00:00 2001 From: Anna Murawska Date: Mon, 28 Sep 2020 02:40:40 -0700 Subject: [PATCH] Show FB-internal announcements only in internal changelog (#1544) Summary: Pull Request resolved: https://github.com/facebook/flipper/pull/1544 Added Facebook changelog file Reviewed By: nikoant Differential Revision: D23930322 fbshipit-source-id: bb6be359d36188f142d342604e50010170086610 --- desktop/app/src/chrome/ChangelogSheet.tsx | 4 ++-- desktop/app/src/utils/pathUtils.tsx | 21 +++++++++++++++++++++ desktop/scripts/generate-changelog.js | 13 ++++++++++++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/desktop/app/src/chrome/ChangelogSheet.tsx b/desktop/app/src/chrome/ChangelogSheet.tsx index 32032041f..b1807b287 100644 --- a/desktop/app/src/chrome/ChangelogSheet.tsx +++ b/desktop/app/src/chrome/ChangelogSheet.tsx @@ -12,7 +12,7 @@ import {readFileSync} from 'fs'; import React, {Component} from 'react'; import path from 'path'; import {reportUsage} from '../utils/metrics'; -import {getStaticPath} from '../utils/pathUtils'; +import {getChangelogPath} from '../utils/pathUtils'; const changelogKey = 'FlipperChangelogStatus'; @@ -22,7 +22,7 @@ type ChangelogStatus = { let getChangelogFromDisk = (): string => { const changelogFromDisk: string = readFileSync( - path.join(getStaticPath(), 'CHANGELOG.md'), + path.join(getChangelogPath(), 'CHANGELOG.md'), 'utf8', ).trim(); diff --git a/desktop/app/src/utils/pathUtils.tsx b/desktop/app/src/utils/pathUtils.tsx index 7b84e4438..31c2e04d5 100644 --- a/desktop/app/src/utils/pathUtils.tsx +++ b/desktop/app/src/utils/pathUtils.tsx @@ -10,6 +10,7 @@ import path from 'path'; import fs from 'fs'; import {remote} from 'electron'; +import config from '../fb-stubs/config'; let _staticPath = ''; @@ -29,3 +30,23 @@ export function getStaticPath() { } return _staticPath; } + +export function getChangelogPath() { + const staticPath = getStaticPath(); + let changelogPath = ''; + + if (config.isFBBuild) { + changelogPath = path.resolve(staticPath, 'facebook'); + } else { + changelogPath = staticPath; + } + + if (fs.existsSync(changelogPath)) { + return changelogPath; + } + + if (!fs.existsSync(changelogPath)) { + throw new Error('Changelog path path does not exist: ' + changelogPath); + } + return changelogPath; +} diff --git a/desktop/scripts/generate-changelog.js b/desktop/scripts/generate-changelog.js index 21cb0814d..9fe2531c7 100755 --- a/desktop/scripts/generate-changelog.js +++ b/desktop/scripts/generate-changelog.js @@ -20,6 +20,7 @@ const cp = require('child_process'); const desktopRoot = path.resolve(__dirname, '..'); const root = path.resolve(desktopRoot, '..'); const staticDir = path.join(desktopRoot, 'static'); +const staticFacebookDir = path.join(staticDir, 'facebook'); const version = JSON.parse( fs.readFileSync(path.join(desktopRoot, 'package.json'), 'utf8'), @@ -29,6 +30,7 @@ const now = new Date(); const date = `${now.getDate()}/${now.getMonth() + 1}/${now.getFullYear()}`; const newlineMarker = '__NEWLINE_MARKER__'; const fChangelog = path.resolve(staticDir, 'CHANGELOG.md'); +const fChangelogFacebook = path.resolve(staticFacebookDir, 'CHANGELOG.md'); const lastCommit = cp .execSync(`hg log --limit 1 --template '{node}'`, {cwd: root}) @@ -50,8 +52,10 @@ const hgLog = cp.execSync(hgLogCommand, {cwd: __dirname}).toString(); const diffRe = /^D\d+/; const changeLogLineRe = /(^changelog:\s*?)(.*?)$/i; +const changeLogFacebookLineRe = /(^Facebook changelog:\s*?)(.*?)$/i; let contents = `# ${version} (${date})\n\n`; +let contentsFacebook = `# ${version} (${date})\n\n`; let changes = 0; hgLog @@ -64,9 +68,14 @@ hgLog line.split(newlineMarker).forEach(diffline => { // if a line starts with changelog:, grab the rest of the text and add it to the changelog const match = diffline.match(changeLogLineRe); - if (match) { + const matchFacebook = diffline.match(changeLogFacebookLineRe); + if (matchFacebook) { + changes++; + contentsFacebook += ` * [${diff}](https://github.com/facebook/flipper/search?q=${diff}&type=Commits) - ${matchFacebook[2]}\n`; + } else if (match) { changes++; contents += ` * [${diff}](https://github.com/facebook/flipper/search?q=${diff}&type=Commits) - ${match[2]}\n`; + contentsFacebook += ` * [${diff}](https://github.com/facebook/flipper/search?q=${diff}&type=Commits) - ${match[2]}\n`; } }); }); @@ -75,5 +84,7 @@ if (!changes) { console.log('No diffs with changelog items found in this release'); } else { contents += '\n\n' + fs.readFileSync(fChangelog, 'utf8'); + contentsFacebook += '\n\n' + fs.readFileSync(fChangelogFacebook, 'utf8'); fs.writeFileSync(fChangelog, contents); + fs.writeFileSync(fChangelogFacebook, contentsFacebook); }