From 7ef7cf4bba0bed4419f330d7e99d5bb54ad2a2c5 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Thu, 7 Jul 2016 15:18:16 -0700 Subject: scripts: Match non-npm URLs in fixes for changelogs --- scripts/changelog.js | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'scripts') diff --git a/scripts/changelog.js b/scripts/changelog.js index b4a9d55fd..729dc6ce6 100644 --- a/scripts/changelog.js +++ b/scripts/changelog.js @@ -13,7 +13,7 @@ the result to the changelog. */ const execSync = require('child_process').execSync const branch = process.argv[2] || 'master' -const log = execSync(`git log --pretty='format:%h %H%d %s (%aN)%n%b%n---%n' ${branch}...`).toString().split(/\n/) +const log = execSync(`git log --reverse --pretty='format:%h %H%d %s (%aN)%n%b%n---%n' ${branch}...`).toString().split(/\n/) const authormap = { 'Rebecca Turner': 'iarna', 'Forrest L Norvell': 'othiym23', @@ -24,21 +24,34 @@ const authormap = { main() +function shortname (url) { + let matched = url.match(/https:\/\/github.com\/([^/]+\/[^/]+)\/(?:pull|issues)\/(\d+)/) + if (!matched) return false + let repo = matched[1] + let id = matched[2] + if (repo !== 'npm/npm') { + return `${repo}#${id}` + } else { + return `#${id}` + } +} + function print_commit (c) { - let m console.log(`* [\`${c.shortid}\`](https://github.com/npm/npm/commit/${c.fullid})`) if (c.fixes) { - console.log(` [#${c.fixes}](https://github.com/npm/npm/issues/${c.fixes})`) - } else if (c.prurl && (m = c.prurl.match(/https:\/\/github.com\/([^/]+\/[^/]+)\/pull\/(\d+)/))) { - let repo = m[1] - let prid = m[2] - if (repo !== 'npm/npm') { - console.log(` [${repo}#${prid}](${c.prurl})`) + let label = shortname(c.fixes) + if (label) { + console.log(` [${label}](${c.fixes})`) } else { - console.log(` [#${prid}](${c.prurl})`) + console.log(` [#${c.fixes}](https://github.com/npm/npm/issues/${c.fixes})`) } } else if (c.prurl) { - console.log(` [#](${c.prurl})`) + let label = shortname(c.prurl) + if (label) { + console.log(` [${label}](${c.prurl})`) + } else { + console.log(` [#](${c.prurl})`) + } } let msg = c.message .replace(/^\s+/mg, '') @@ -84,7 +97,7 @@ function main () { } else if (m = line.match(/^Credit: @(.*)/)) { if (!commit.credit) commit.credit = [] commit.credit.push(m[1]) - } else if (m = line.match(/^Fixes: (?:#|https:[/][/]github.com[/]npm[/]npm[/]issues[/])(.*)/)) { + } else if (m = line.match(/^Fixes: (?:#|https:[/][/]github.com[/]([^/]+[/][^/]+)[/]issues[/])(.*)/)) { commit.fixes = m[1] } else if (m = line.match(/^Reviewed-By: @(.*)/)) { commit.reviewed = m[1] -- cgit v1.2.3