clean up release notes script

This commit is contained in:
Samuel Attard 2018-06-21 18:13:19 +10:00
parent 2c255680a9
commit 57a18d4c49
No known key found for this signature in database
GPG key ID: 273DC1869D8F13EF

View file

@ -1,5 +1,5 @@
const { GitProcess } = require('dugite') const { GitProcess } = require('dugite')
const Entities = require('html-entities').AllHtmlEntities; const Entities = require('html-entities').AllHtmlEntities
const fetch = require('node-fetch') const fetch = require('node-fetch')
const fs = require('fs') const fs = require('fs')
const GitHub = require('github') const GitHub = require('github')
@ -9,13 +9,16 @@ const semver = require('semver')
const CACHE_DIR = path.resolve(__dirname, '.cache') const CACHE_DIR = path.resolve(__dirname, '.cache')
// Fill this with tags to ignore if you are generating release notes for older // Fill this with tags to ignore if you are generating release notes for older
// versions // versions
const EXCLUDE_TAGS = ['v3.0.0-beta.1'] //
// E.g. ['v3.0.0-beta.1'] to generate the release notes for 3.0.0-beta.1 :) from
// the current 3-0-x branch
const EXCLUDE_TAGS = []
const entities = new Entities() const entities = new Entities()
const github = new GitHub() const github = new GitHub()
const gitDir = path.resolve(__dirname, '..', '..') const gitDir = path.resolve(__dirname, '..', '..')
github.authenticate({ type: 'token', token: process.env.ELECTRON_GITHUB_TOKEN }) github.authenticate({ type: 'token', token: process.env.ELECTRON_GITHUB_TOKEN })
let currentBranch; let currentBranch
const semanticMap = new Map() const semanticMap = new Map()
for (const line of fs.readFileSync(path.resolve(__dirname, 'legacy-pr-semantic-map.csv'), 'utf8').split('\n')) { for (const line of fs.readFileSync(path.resolve(__dirname, 'legacy-pr-semantic-map.csv'), 'utf8').split('\n')) {
@ -80,7 +83,7 @@ const getBranches = async () => {
if (branchDetails.exitCode === 0) { if (branchDetails.exitCode === 0) {
return branchDetails.stdout.trim().split('\n').map(b => b.trim()).filter(branch => branch !== 'origin/HEAD -> origin/master') return branchDetails.stdout.trim().split('\n').map(b => b.trim()).filter(branch => branch !== 'origin/HEAD -> origin/master')
} }
throw GitProcess.parseError(tagDetails.stderr) throw GitProcess.parseError(branchDetails.stderr)
} }
const semverify = (v) => v.replace(/^origin\//, '').replace('x', '0').replace(/-/g, '.') const semverify = (v) => v.replace(/^origin\//, '').replace('x', '0').replace(/-/g, '.')
@ -110,17 +113,8 @@ const commitBeforeTag = async (commit, tag) => {
throw GitProcess.parseError(tagDetails.stderr) throw GitProcess.parseError(tagDetails.stderr)
} }
// const getBranchOffBeforeBranchOffPoint = async (branchOffPoint) => {
// const releaseBranch
// }
/**
* This method will get all commits that have landed in the current
* branch since the given "point", the point must be a commit hash or other
* git identifier
*/
const getCommitsMergedIntoCurrentBranchSincePoint = async (point) => { const getCommitsMergedIntoCurrentBranchSincePoint = async (point) => {
return await getCommitsBetween(point, 'HEAD') return getCommitsBetween(point, 'HEAD')
} }
const getCommitsBetween = async (point1, point2) => { const getCommitsBetween = async (point1, point2) => {
@ -139,17 +133,17 @@ const getCommitDetails = async (commitHash) => {
const bits = commitInfo.split('</a>)')[0].split('>') const bits = commitInfo.split('</a>)')[0].split('>')
const prIdent = bits[bits.length - 1].trim() const prIdent = bits[bits.length - 1].trim()
if (!prIdent || commitInfo.indexOf('href="/electron/electron/pull') === -1) { if (!prIdent || commitInfo.indexOf('href="/electron/electron/pull') === -1) {
console.warn(`WARNING: Could not track commit "${commitHash}" to a pull request, it may have been committed directly to the branch`); console.warn(`WARNING: Could not track commit "${commitHash}" to a pull request, it may have been committed directly to the branch`)
return null return null
} }
const title = commitInfo.split('title="')[1].split('"')[0]; const title = commitInfo.split('title="')[1].split('"')[0]
if (!title.startsWith(TITLE_PREFIX)) { if (!title.startsWith(TITLE_PREFIX)) {
console.warn(`WARNING: Unknown PR title for commit "${commitHash}" in PR "${prIdent}"`) console.warn(`WARNING: Unknown PR title for commit "${commitHash}" in PR "${prIdent}"`)
return null return null
} }
return { return {
mergedFrom: prIdent, mergedFrom: prIdent,
prTitle: entities.decode(title.substr(TITLE_PREFIX.length)), prTitle: entities.decode(title.substr(TITLE_PREFIX.length))
} }
} }
@ -451,9 +445,7 @@ async function main() {
const currentBranchOff = await getBranchOffPoint(await getCurrentBranch()) const currentBranchOff = await getBranchOffPoint(await getCurrentBranch())
const commits = await getCommitsMergedIntoCurrentBranchSincePoint( const commits = await getCommitsMergedIntoCurrentBranchSincePoint(
lastKnownReleaseInCurrentStream lastKnownReleaseInCurrentStream || currentBranchOff
? lastKnownReleaseInCurrentStream
: currentBranchOff
) )
if (!lastKnownReleaseInCurrentStream) { if (!lastKnownReleaseInCurrentStream) {