
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
glob-github
Advanced tools
Run glob expressions against the Github Repo Contents API and return the matching files and metadata; with caching.
Run glob expressions against the Github Repo Contents API and return the matching files and metadata; with caching.
**/*.md
to match filesnpm install --save glob-github
Here's a quick example:
var glob = require('glob-github');
glob({
user: 'mixu',
repo: 'singlepageappbook',
glob: '**/*.md',
authenticate: {
type: 'oauth',
token: '<AUTH TOKEN HERE>'
}
}, function(err, results, meta) {
console.log(err, results, meta);
// results is an array of Github Get Contents API call results:
// [ { type: 'file', name: 'index.md', path: 'input/index.md', ... }]
// meta:
// { limit: 4774, cacheHits: 0, apiCalls: 16 }
});
glob(opts, onDone)
, where opts
is an options hash containing:
opts.user
: Github usernameopts.repo
: Github repoopts.branch
: Github branch (since v1.2.0
); defaults to masteropts.glob
: glob expression to match againstopts.authenticate
: a hash passed to node-github
opts.cache
: (Optional). A hash that can be reused across calls, pass in a {}
on the first usage and keep passing the same hash in every time to keep using the cache. Note that the results are automatically cached so you only need to pass this if you want to, say, write the cache to disk or something.opts.github
: (Optional). An instance of node-github
that you have configured to your liking.The onDone(err, results, meta)
callback receives three arguments:
err
: an error, if anyresults
: an array of results which match the given glob expression as returned from the Github Get Contents API; see the link for examples.meta
: an object containing metadata:
meta.limit
: the smallest Github API x-rate-limit
header value that has been receivedmeta.cacheHits
: the number of Github API calls that were fulfilled from the cache to resolve the glob expressionmeta.githubAPI
: the number of Github API calls that were made to resolve the glob expressionIf you make the same call (or another glob expression resolution) against the same repo, glob-github
will attempt to fulfill matches from the cache:
var glob = require('glob-github');
var config = {
user: 'mixu',
repo: 'singlepageappbook',
glob: '**/*.md',
authenticate: {
type: 'oauth',
token: '<AUTH TOKEN HERE>'
}
};
glob(config, function(err, results, meta) {
// should show some number of meta.githubAPI
console.log(meta);
glob(config, function(err, results, meta) {
// should be fulfilled completely from the cache!
console.log(meta);
});
});
Concurrent calls are deduplicated: if a request for a specific Github endpoint (e.g. username + repo + path combination) is already pending, then any concurrent requests simply wait for that request to complete rather than making a new request.
var glob = require('glob-github');
var config = { ... };
glob(config, function(err, results, meta) {
console.log(err, results.length, meta);
});
glob(config, function(err, results, meta) {
console.log(err, results.length, meta);
});
You should see something like:
null 16 { limit: 10, cacheHits: 10, apiCalls: 6 }
null 16 { limit: 10, cacheHits: 6, apiCalls: 10 }
Note how the 16 API calls needed to resolve this **/*.md
glob are divided between the two concurrent glob()
calls so that only 16 requests are made and the duplicate requests are served from the cache.
FAQs
Run glob expressions against the Github Repo Contents API and return the matching files and metadata; with caching.
We found that glob-github demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.