Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github-getter

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github-getter - npm Package Compare versions

Comparing version 2.0.0 to 3.0.0

.eslintignore

8

lib/gHGetter.js
'use strict';
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
Object.defineProperty(exports, "__esModule", {

@@ -10,2 +8,4 @@ value: true

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _gHRequest = require('./gHRequest.js');

@@ -27,4 +27,4 @@

var err_ = undefined,
response_ = undefined;
var err_ = void 0,
response_ = void 0;
var hasResponse = false;

@@ -31,0 +31,0 @@ var configFuncCaller = false;

'use strict';
var _gHGetter = require('./gHGetter.js');
// githubFile: get its data
(0, _gHGetter.gHFile)('des-des/github-getter', 'README.md')({
getData: function getData(err, readmeData) {
return console.log(readmeData);
}
});
// githubRepo: get a githubFile for every file in a repo (or just the readme)
(0, _gHGetter.gHRepo)('des-des/github-getter')({
getFiles: function getFiles(err, files) {
if (!err) {
files['package.json']({
getData: function getData(err, packageData) {
return console.log(packageData);
}
});
}
},
getReadme: function getReadme(err, readme) {
return readme({
getData: function getData(err, readmeData) {
return console.log(readmeData);
}
});
}
});
// githubUser: get a githubRepo for every repo belonging to a user or org
(0, _gHGetter.gHUser)('des-des')({
getRepos: function getRepos(err, repos) {
return repos['github-getter']({
getReadme: function getReadme(err, readme) {
if (!err) {
readme({
getData: function getData(err, readmeData) {
return console.log(readmeData);
}
});
}
}
});
}
});
module.exports = require('./github_getter.js').githubGetter;
{
"name": "github-getter",
"version": "2.0.0",
"version": "3.0.0",
"description": "Quick and easy github file retrieval",

@@ -15,6 +15,9 @@ "main": "lib/gHGetter.js",

"scripts": {
"test": "babel-node ./node_modules/.bin/babel-istanbul cover tape test/ && npm run coverage",
"test": "npm run lint && npm run test:cover",
"test:cover" : "babel-node ./node_modules/.bin/babel-istanbul cover tape test/ && npm run coverage",
"dev:test": "nodemon -q --exec \"node test/ | tap-notify | tap-spec\"",
"coverage": "istanbul check-coverage --statements 100 --functions 100 --lines 100 --branches -100",
"prepublish": "npm run build",
"build": "babel src -d lib",
"lint": "standard",
"build:watch": "babel src -d lib -w"

@@ -25,5 +28,3 @@ },

"license": "ISC",
"dependencies": {
"env2": "^2.0.4"
},
"dependencies": {},
"devDependencies": {

@@ -35,4 +36,8 @@ "babel-cli": "^6.5.0",

"nock": "^7.0.2",
"nodemon": "^1.9.1",
"standard": "^7.1.1",
"tap-notify": "^1.0.0",
"tap-spec": "^4.1.1",
"tape": "^4.4.0"
}
}

@@ -1,2 +0,4 @@

[![codecov.io](https://codecov.io/github/des-des/github-getter/coverage.svg?branch=master)](https://codecov.io/github/des-des/github-getter?branch=master) [![bitHound Overall Score](https://www.bithound.io/github/des-des/github-getter/badges/score.svg)](https://www.bithound.io/github/des-des/github-getter) [![bitHound Dependencies](https://www.bithound.io/github/des-des/github-getter/badges/dependencies.svg)](https://www.bithound.io/github/des-des/github-getter/master/dependencies/npm) [![bitHound Dev Dependencies](https://www.bithound.io/github/des-des/github-getter/badges/devDependencies.svg)](https://www.bithound.io/github/des-des/github-getter/master/dependencies/npm)
[![codecov.io](https://codecov.io/github/des-des/github-getter/coverage.svg?branch=master)](https://codecov.io/github/des-des/github-getter?branch=master)
[![travis-ci.org](https://travis-ci.org/des-des/github-getter.svg?branch=master)](https://travis-ci.org/des-des/github-getter.svg?branch=master)
[![codecov.io](https://codecov.io/github/des-des/github-getter/coverage.svg?branch=master)](https://codecov.io/github/des-des/github-getter?branch=master)

@@ -9,61 +11,62 @@ **webhooks coming soon (so you gh hosted content can tell you site when to update!)**

A quick and easy way to get files from github
#### A quick and easy way to get files from github
github-getter is a small module to take the hassle out of downloading files from github. Download specific files, or specify repositories/users and recieve lists of files/repositories available.
## Why?
Hosting content on github is awesome! github-getter makes accessing those files easy (so you don't waste your precious time reading api docs!)
Save time digging around docs / fiddling with with headers.
## How?
Break down interaction with github into users, repos and files.
get a github api token. Create a personal one [here](https://github.com/settings/tokens) or use [oauth](https://github.com/settings/tokens).
### SETUP
#### node 6
```js
const { user, repo, file } = require('./src/')(process.env.ghtoken)
* `import { GHFile, GHRepo, GHUser } from 'github-getter'`
const logContent = (err, res) => {
if (err) throw err
console.log(res.content)
}
* `GHFile` Input a filepath and repo name to get and `GHFile` object OR
* `GHRepo`: Input a repo name to get a `GHFile` object for everything in the repo OR
* `GHUser`: Input a user/org name and get a `GHRepo` object for each repository belonging to that user/org
### USAGE
file({ repoName: 'des-des/github-getter', filePath: 'README.md' }, logContent)
1. navigate to `https://github.com/settings/tokens`
2. click this button to create new token
![image](https://cloud.githubusercontent.com/assets/12845233/12928897/04595204-cf68-11e5-8a4a-d41f5eca6a97.png)
3. create a file called `config.env` in your projects root
4. add the line `ghtoken=****************` to the file, adding you token.
5. run the command `npm i github-getter --save`
6. get coding!
repo({ repoName: 'des-des/github-getter' }, (err, githubGetter) => {
if (err) throw err
githubGetter['README.md'](logContent)
})
user({ name: 'des-des' }, (err, desdes) => {
if (err) throw err
desdes['github-getter']((err, githubGetter) => {
if (err) throw err
githubGetter['README.md'](logContent)
})
})
```
```javascript
import { gHUser, gHRepo } from 'github-getter.js';
## Documentation
gHUser('dwyl', true)({
getRepos: (err, repos) => {
repos.adoro({ // my favorate dwyl repo ;)
getReadme: (err, readme) => readme({
getData: console.log
// logs the file from https://github.com/dwyl/adoro/blob/master/README.md to the console
})
});
}
});
gHRepo('des-des/aibox')({
getFiles: (err, files) => {
files['.babelrc']({
getData: console.log
// logs the file from https://github.com/des-des/aibox/blob/master/.babelrc to the console
});
},
getReadme: (err, readme) => readme({
getData: console.log
// logs the file from https://github.com/des-des/aibox/blob/master/README.md to the console
})
});
```
see src/index.es6 for the example!
* `init` - `token => githubGetter`, where
* `token` - github api token.
* `githubGetter` - object with
* `file` - `({ repoName, filePath }, cb) => {}`, where
* `repoName` - name of the repository,
* `filePath` - path of desired file, ie `assets/someData.json`,
* `cb` - `(err, githubFile) => {}`.
* `repo` - `({ repoName }, cb) => {}`, where
* `repoName` - name of the repository,
* `cb` - `(err, githubRepo) => {}`.
* `user` - `({ name }, cb) => {}`, where
* `name` - github user name,
* `cb` - `(err, githubUser) => {}`.
* `org` - `({ name }, cb) => {}`, where
* `name` - github org name,
* `cb` - `(err, githubUser) => {}`.
* `githubFile` - object containing
* `content` - string containing file content
* githubRepo - an object were keys are paths to repos files:
* `[filepath]` - `cb(err, githubFile) => {}`.
* githubUser - an object were keys are repo names belonging to the user/org:
* `[repoName]` - `cb(err, githubRepo) => {}`.

@@ -1,4 +0,92 @@

require('./gHFile.test.js');
require('./gHRepo.test.js');
require('./gHUser.test.js');
require('./async.test.js');
const test = require('tape')
const {
nockFileRequest, nockCommitRequest, nockTreeRequest, nockUserRequest
} = require('./nocks')
const { file, repo, user, org } = require('../src/')('token')
const { setCb } = require('../src/github_getter.js')
test('util', t => {
t.plan(1)
const f = (data, cb) => cb(data)
setCb(f)('test')(data => {
t.equal(data, 'test', 'setCb binds correctly')
})
})
test('error test', t => {
const testData = 'test data'
const repoName = 'test-repo'
const filePath = 'test-file-name'
nockFileRequest(repoName, filePath, 400, testData)
file({ repoName, filePath }, (err) => {
t.ok(err, 'error passed')
t.end()
})
})
test('ghFile requests and recieves file data', (t) => {
const testData = 'test data'
const repoName = 'test-repo'
const filePath = 'test-file-name'
nockFileRequest(repoName, filePath, 200, testData)
file({ repoName, filePath }, (err, file) => {
t.ok(!err, 'no error passed')
t.equal(file.content, testData, 'corrent data received')
t.end()
})
})
test('retrieving commit then tree then file', (t) => {
const repoName = 'test-repo'
const filePath = 'test-path'
const sha = 'test-sha'
nockCommitRequest(repoName, sha, 200)
nockTreeRequest(repoName, sha, filePath, 200)
repo({ repoName }, (err, fileData) => {
t.ok(!err, 'no error')
const expected = [filePath]
const actual = Object.keys(fileData)
t.deepEqual(actual, expected, 'returned file has correct repo and path')
t.end()
})
})
test('user', (t) => {
const name = 'test-user-name'
const repoName = 'test-repo-name'
nockUserRequest(name, false, repoName, 200)
user(({ name }), (err, res) => {
t.ok(!err, 'no error')
const expected = [repoName]
const actual = Object.keys(res)
t.deepEqual(actual, expected, 'correct repo name in return object')
t.end()
})
})
test('org', (t) => {
const name = 'test-org-name'
const repoName = 'test-repo-name'
nockUserRequest(name, false, repoName, 200)
org(({ name }), (err, res) => {
t.ok(!err, 'no error')
const expected = [repoName]
const actual = Object.keys(res)
t.deepEqual(actual, expected, 'correct repo name in return object')
t.end()
})
})

@@ -1,2 +0,2 @@

var nock = require('nock');
var nock = require('nock')

@@ -8,25 +8,20 @@ var nockFileRequest = (repoName, fileName, responseCode, responseData) => {

content: new Buffer(responseData).toString('base64')
} : '');
};
} : '')
}
var nockCommitRequest = (repoName, sha, statusCode) => {
console.log('nocking commit request');
nock('https://api.github.com')
.get('/repos/' + repoName + '/commits')
.get('/repos/' + repoName + '/commits')
.reply(statusCode, [{
sha: sha
}]);
};
}])
}
var nockTreeRequest = (repoName, sha, filePath, statusCode) => {
var nockTreeRequest = (repoName, sha, path, statusCode) => {
nock('https://api.github.com')
.get('/repos/' + repoName + '/git/trees/' + sha + '?recursive=1')
.get('/repos/' + repoName + '/git/trees/' + sha + '?recursive=1')
.reply(statusCode, {
tree: [
{
path: filePath
}
]
});
};
tree: [{ type: 'blob', path }, { type: 'notablob', path }]
})
}

@@ -36,12 +31,10 @@ var nockUserRequest = (name, isOrg, repoName, statusCode) => {

.get('/' + (isOrg ? 'orgs' : 'users') + '/' + name + '/repos')
.reply(statusCode, [{
full_name: name + '/' + repoName
}]);
};
.reply(statusCode, [{ full_name: name + '/' + repoName }])
}
module.exports = {
nockFileRequest: nockFileRequest,
nockCommitRequest: nockCommitRequest,
nockTreeRequest: nockTreeRequest,
nockUserRequest: nockUserRequest
};
nockFileRequest,
nockCommitRequest,
nockTreeRequest,
nockUserRequest
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc