Fetch File
Fetch a file from one or more public Github repositories.
Installation
$ npm install github-fetch-file
Usage
var fetch = ;
fetch( filepath, repos, clbk )
Fetches a file
from one or more public Github repositories.
// List of repository slugs (username|org/repo):var repos ='kgryte/utils-copy''dstructs/matrix''math-io/gamma''unknown_user/repo';// Fetch a top-level `README.md` file from each repo:;{if errorthrow errormessage ;consoledir results ;/*{"meta": {"total": 4,"success": 3,"failure": 1},"data": {"kgryte/utils-copy": "...","dstructs/matrix": "...","math-io/gamma": "..."},"failures": {"unknown_user/repo": "Not Found"}}*/}
fetch.factory( filepath, repos, clbk )
Creates a reusable function
.
var repos ='kgryte/utils-copy''dstructs/matrix''math-io/gamma''unknown_user/repo';var get = fetch;;;;// ...
The factory method accepts the same arguments
as fetch()
.
Notes
- If the module encounters an application-level
error
(e.g., no network connection, etc), theerror
is returned immediately to the providedcallback
. - If the module encounters a downstream
error
(e.g., timeout, reset connection, etc), theerror
is included in the returned results under thefailures
field.
Examples
var fetch = ;var repos ='kgryte/utils-copy''math-io/gamma''dstructs/matrix';;{if errorthrow errormessage ;consoledir results ;}
To run the example code from the top-level application directory,
$ DEBUG=* node ./examples/index.js
CLI
Installation
To use the module as a general utility, install the module globally
$ npm install -g github-fetch-file
Usage
Usage: ghfetchfile [options] file --repo slug1 --repo slug2 ...Options:-h, --help Print this message.-V, --version Print the package version.--repo slug Repository slug; e.g., kgryte/github-fetch-file.
Notes
- If a repository file is successfully resolved, the file content is written to
stdout
. - If a repository file cannot be resolved due to a downstream
error
(failure), the reposlug
(and its associatederror
) is written tosterr
. - Output order is not guaranteed to match input order.
Examples
$ DEBUG=* ghfetchfile README.md --repo 'kgryte/utils-copy' --repo 'dstructs/matrix' --repo 'math-io/gamma'# => {...}
For local installations, modify the command to point to the local installation directory; e.g.,
$ DEBUG=* ./node_modules/.bin/ghfetchfile README.md --repo 'kgryte/utils-copy' --repo 'dstructs/matrix' --repo 'math-io/gamma'# => {...}
Or, if you have cloned this repository and run npm install
, modify the command to point to the executable; e.g.,
$ DEBUG=* node ./bin/cli README.md --repo 'kgryte/utils-copy' --repo 'dstructs/matrix' --repo 'math-io/gamma'# => {...}
Tests
Unit
This repository uses tape for unit tests. To run the tests, execute the following command in the top-level application directory:
$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
Test Coverage
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-cov
Istanbul creates a ./reports/coverage
directory. To access an HTML version of the report,
$ make view-cov
Browser Support
This repository uses Testling for browser testing. To run the tests in a (headless) local web browser, execute the following command in the top-level application directory:
$ make test-browsers
To view the tests in a local web browser,
$ make view-browser-tests
License
Copyright
Copyright © 2016. Athan Reines.