-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add global throttler to comply with GitHub recommendation
- Loading branch information
Showing
13 changed files
with
272 additions
and
195 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,50 @@ | ||
const {basename} = require('path'); | ||
const {isPlainObject, castArray, uniqWith} = require('lodash'); | ||
const pReduce = require('p-reduce'); | ||
const globby = require('globby'); | ||
const debug = require('debug')('semantic-release:github'); | ||
|
||
module.exports = async assets => | ||
uniqWith( | ||
(await pReduce( | ||
assets, | ||
async (result, asset) => { | ||
// Wrap single glob definition in Array | ||
const glob = castArray(isPlainObject(asset) ? asset.path : asset); | ||
// Skip solo negated pattern (avoid to include every non js file with `!**/*.js`) | ||
if (glob.length <= 1 && glob[0].startsWith('!')) { | ||
debug( | ||
'skipping the negated glob %o as its alone in its group and would retrieve a large amount of files ', | ||
glob[0] | ||
); | ||
return result; | ||
} | ||
const globbed = await globby(glob, {expandDirectories: true, gitignore: false, dot: true}); | ||
if (isPlainObject(asset)) { | ||
if (globbed.length > 1) { | ||
// If asset is an Object with a glob the `path` property that resolve to multiple files, | ||
// Output an Object definition for each file matched and set each one with: | ||
// - `path` of the matched file | ||
// - `name` based on the actual file name (to avoid assets with duplicate `name`) | ||
// - other properties of the original asset definition | ||
return [...result, ...globbed.map(file => Object.assign({}, asset, {path: file, name: basename(file)}))]; | ||
} | ||
// If asset is an Object, output an Object definition with: | ||
// - `path` of the matched file if there is one, or the original `path` definition (will be considered as a missing file) | ||
// - other properties of the original asset definition | ||
return [...result, Object.assign({}, asset, {path: globbed[0] || asset.path})]; | ||
} | ||
if (globbed.length > 0) { | ||
// If asset is a String definition, output each files matched | ||
return [...result, ...globbed]; | ||
} | ||
// If asset is a String definition but no match is found, output the elements of the original glob (each one will be considered as a missing file) | ||
return [...result, ...glob]; | ||
}, | ||
[] | ||
// Sort with Object first, to prioritize Object definition over Strings in dedup | ||
)).sort(asset => !isPlainObject(asset)), | ||
[] | ||
.concat( | ||
...(await Promise.all( | ||
assets.map(async asset => { | ||
// Wrap single glob definition in Array | ||
const glob = castArray(isPlainObject(asset) ? asset.path : asset); | ||
// Skip solo negated pattern (avoid to include every non js file with `!**/*.js`) | ||
if (glob.length <= 1 && glob[0].startsWith('!')) { | ||
debug( | ||
'skipping the negated glob %o as its alone in its group and would retrieve a large amount of files ', | ||
glob[0] | ||
); | ||
return []; | ||
} | ||
const globbed = await globby(glob, {expandDirectories: true, gitignore: false, dot: true}); | ||
if (isPlainObject(asset)) { | ||
if (globbed.length > 1) { | ||
// If asset is an Object with a glob the `path` property that resolve to multiple files, | ||
// Output an Object definition for each file matched and set each one with: | ||
// - `path` of the matched file | ||
// - `name` based on the actual file name (to avoid assets with duplicate `name`) | ||
// - other properties of the original asset definition | ||
return globbed.map(file => Object.assign({}, asset, {path: file, name: basename(file)})); | ||
} | ||
// If asset is an Object, output an Object definition with: | ||
// - `path` of the matched file if there is one, or the original `path` definition (will be considered as a missing file) | ||
// - other properties of the original asset definition | ||
return Object.assign({}, asset, {path: globbed[0] || asset.path}); | ||
} | ||
if (globbed.length > 0) { | ||
// If asset is a String definition, output each files matched | ||
return globbed; | ||
} | ||
// If asset is a String definition but no match is found, output the elements of the original glob (each one will be considered as a missing file) | ||
return glob; | ||
}) | ||
// Sort with Object first, to prioritize Object definition over Strings in dedup | ||
)) | ||
) | ||
.sort(asset => !isPlainObject(asset)), | ||
// Compare `path` property if Object definition, value itself if String | ||
(a, b) => (isPlainObject(a) ? a.path : a) === (isPlainObject(b) ? b.path : b) | ||
); |
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
Oops, something went wrong.