-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: switch to ESM, fix output colourising
* upgrade all deps, including ESM-only deps * --simple is now default output, including colourising, with --markdown being an opt-in output format. * move process + print logic to separate module for exporting for simplifying branch-diff * add --sha and --reverse options from branch-diff to dedupe some processing code Fixes: #120 Closes: #107 Closes: #119
- Loading branch information
Showing
11 changed files
with
228 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,63 @@ | ||
'use strict' | ||
|
||
const ghauth = require('ghauth') | ||
const ghissues = require('ghissues') | ||
const async = require('async') | ||
import { promisify } from 'util' | ||
import ghauth from 'ghauth' | ||
import ghissues from 'ghissues' | ||
import async from 'async' | ||
|
||
const authOptions = { | ||
configName: 'changelog-maker', | ||
scopes: ['repo'], | ||
noDeviceFlow: true | ||
} | ||
|
||
function collectCommitLabels (list, callback) { | ||
export async function collectCommitLabels (list) { | ||
const sublist = list.filter((commit) => { | ||
return typeof commit.ghIssue === 'number' && commit.ghUser && commit.ghProject | ||
}) | ||
|
||
if (!sublist.length) { | ||
return setImmediate(callback) | ||
return | ||
} | ||
|
||
ghauth(authOptions, (err, authData) => { | ||
if (err) { | ||
return callback(err) | ||
} | ||
|
||
const cache = {} | ||
|
||
const q = async.queue((commit, next) => { | ||
function onFetch (err, issue) { | ||
if (err) { | ||
console.error('Error fetching issue #%s: %s', commit.ghIssue, err.message) | ||
return next() | ||
} | ||
const authData = await promisify(ghauth)(authOptions) | ||
|
||
if (issue.labels) { | ||
commit.labels = issue.labels.map((label) => label.name) | ||
} | ||
const cache = {} | ||
|
||
next() | ||
const q = async.queue((commit, next) => { | ||
function onFetch (err, issue) { | ||
if (err) { | ||
console.error('Error fetching issue #%s: %s', commit.ghIssue, err.message) | ||
return next() | ||
} | ||
|
||
if (commit.ghUser === 'iojs') { | ||
commit.ghUser = 'nodejs' // forcibly rewrite as the GH API doesn't do it for us | ||
if (issue.labels) { | ||
commit.labels = issue.labels.map((label) => label.name) | ||
} | ||
|
||
// To prevent multiple simultaneous requests for the same issue | ||
// from hitting the network at the same time, immediately assign a Promise | ||
// to the cache that all commits with the same ghIssue value will use. | ||
const key = `${commit.ghUser}/${commit.ghProject}#${commit.ghIssue}` | ||
cache[key] = cache[key] || new Promise((resolve, reject) => { | ||
ghissues.get(authData, commit.ghUser, commit.ghProject, commit.ghIssue, (err, issue) => { | ||
if (err) { | ||
return reject(err) | ||
} | ||
next() | ||
} | ||
|
||
resolve(issue) | ||
}) | ||
if (commit.ghUser === 'iojs') { | ||
commit.ghUser = 'nodejs' // forcibly rewrite as the GH API doesn't do it for us | ||
} | ||
|
||
// To prevent multiple simultaneous requests for the same issue | ||
// from hitting the network at the same time, immediately assign a Promise | ||
// to the cache that all commits with the same ghIssue value will use. | ||
const key = `${commit.ghUser}/${commit.ghProject}#${commit.ghIssue}` | ||
cache[key] = cache[key] || new Promise((resolve, reject) => { | ||
ghissues.get(authData, commit.ghUser, commit.ghProject, commit.ghIssue, (err, issue) => { | ||
if (err) { | ||
return reject(err) | ||
} | ||
|
||
resolve(issue) | ||
}) | ||
cache[key].then((val) => onFetch(null, val), (err) => onFetch(err)) | ||
}, 15) | ||
q.drain(callback) | ||
q.push(sublist) | ||
}) | ||
} | ||
}) | ||
cache[key].then((val) => onFetch(null, val), (err) => onFetch(err)) | ||
}, 15) | ||
|
||
module.exports = collectCommitLabels | ||
q.push(sublist) | ||
await q.drain() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.