github-getter
Advanced tools
Comparing version 3.0.1 to 3.1.0
@@ -7,3 +7,3 @@ 'use strict'; | ||
var fileUrl = function fileUrl(_ref) { | ||
var fileDataUrl = function fileDataUrl(_ref) { | ||
var repoName = _ref.repoName; | ||
@@ -14,19 +14,33 @@ var filePath = _ref.filePath; | ||
var commitsUrl = function commitsUrl(_ref2) { | ||
var sha = function sha(path) { | ||
return function (treeData) { | ||
return treeData.tree.filter(function (node) { | ||
return node.path === path; | ||
})[0].sha; | ||
}; | ||
}; | ||
var fileUrl = function fileUrl(_ref2, treeData) { | ||
var repoName = _ref2.repoName; | ||
var filePath = _ref2.filePath; | ||
return '/repos/' + repoName + '/git/blobs/' + sha(filePath)(treeData); | ||
}; | ||
var commitsUrl = function commitsUrl(_ref3) { | ||
var repoName = _ref3.repoName; | ||
return '/repos/' + repoName + '/commits'; | ||
}; | ||
var repoTreeUrl = function repoTreeUrl(_ref3, commits) { | ||
var repoName = _ref3.repoName; | ||
var repoTreeUrl = function repoTreeUrl(_ref4, commits) { | ||
var repoName = _ref4.repoName; | ||
return '/repos/' + repoName + '/git/trees/' + commits[0].sha + '?recursive=1'; | ||
}; | ||
var userUrl = function userUrl(_ref4) { | ||
var name = _ref4.name; | ||
var userUrl = function userUrl(_ref5) { | ||
var name = _ref5.name; | ||
return '/users/' + name + '/repos'; | ||
}; | ||
var orgUrl = function orgUrl(_ref5) { | ||
var name = _ref5.name; | ||
var orgUrl = function orgUrl(_ref6) { | ||
var name = _ref6.name; | ||
return '/users/' + name + '/repos'; | ||
@@ -37,8 +51,8 @@ }; | ||
return function (res) { | ||
return function (_ref6) { | ||
var _ref7 = _toArray(_ref6); | ||
return function (_ref7) { | ||
var _ref8 = _toArray(_ref7); | ||
var processRes = _ref7[0]; | ||
var processRes = _ref8[0]; | ||
var rest = _ref7.slice(1); | ||
var rest = _ref8.slice(1); | ||
@@ -70,4 +84,6 @@ return function (opts, cb) { | ||
var githubGetter = function githubGetter(token) { | ||
var getter = waterfallRequester(token)(); | ||
var getterWParams = waterfallRequester(token); | ||
var getter = getterWParams(); | ||
var gHFile = function gHFile(_, fileData) { | ||
@@ -80,10 +96,14 @@ return { | ||
var file = getter([fileUrl, gHFile]); | ||
var fileFromTree = function fileFromTree(data) { | ||
return getterWParams(data)([fileUrl, gHFile]); | ||
}; | ||
var gHRepo = function gHRepo(_ref8, treeData) { | ||
var repoName = _ref8.repoName; | ||
var file = getter([commitsUrl, repoTreeUrl, fileUrl, gHFile]); | ||
var gHRepo = function gHRepo(_ref9, treeData) { | ||
var repoName = _ref9.repoName; | ||
return treeData.tree.reduce(function (files, treeElem) { | ||
if (treeElem.type === 'blob') { | ||
files[treeElem.path] = setCb(file)({ repoName: repoName, filePath: treeElem.path }); | ||
files[treeElem.path] = setCb(fileFromTree(treeData))({ repoName: repoName, filePath: treeElem.path }); | ||
} | ||
@@ -97,4 +117,4 @@ return files; | ||
var gHUser = function gHUser(_, repoDataArr) { | ||
return repoDataArr.reduce(function (repos, _ref9) { | ||
var full_name = _ref9.full_name; | ||
return repoDataArr.reduce(function (repos, _ref10) { | ||
var full_name = _ref10.full_name; | ||
@@ -101,0 +121,0 @@ repos[full_name.split('/')[1]] = setCb(repo)({ repoName: full_name }); |
{ | ||
"name": "github-getter", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "Quick and easy github file retrieval", | ||
@@ -5,0 +5,0 @@ "main": "lib/", |
@@ -16,17 +16,17 @@ const test = require('tape') | ||
}) | ||
// | ||
// 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('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) => { | ||
@@ -36,4 +36,8 @@ const testData = 'test data' | ||
const filePath = 'test-file-name' | ||
const rootSha = 'rootSha' | ||
const fileSha = 'fileSha' | ||
nockFileRequest(repoName, filePath, 200, testData) | ||
nockCommitRequest(repoName, rootSha) | ||
nockTreeRequest(repoName, rootSha, { sha: fileSha, path: filePath }) | ||
nockFileRequest(repoName, testData, fileSha) | ||
@@ -48,8 +52,9 @@ file({ repoName, filePath }, (err, file) => { | ||
test('retrieving commit then tree then file', (t) => { | ||
const testData = 'test data' | ||
const repoName = 'test-repo' | ||
const filePath = 'test-path' | ||
const sha = 'test-sha' | ||
const filePath = 'test-file-name' | ||
const rootSha = 'rootSha' | ||
nockCommitRequest(repoName, sha, 200) | ||
nockTreeRequest(repoName, sha, filePath, 200) | ||
nockCommitRequest(repoName, rootSha) | ||
nockTreeRequest(repoName, rootSha, { type: 'blob', path: filePath }) | ||
@@ -70,3 +75,3 @@ repo({ repoName }, (err, fileData) => { | ||
nockUserRequest(name, false, repoName, 200) | ||
nockUserRequest(name, false, repoName) | ||
@@ -87,3 +92,3 @@ user(({ name }), (err, res) => { | ||
nockUserRequest(name, false, repoName, 200) | ||
nockUserRequest(name, false, repoName) | ||
@@ -90,0 +95,0 @@ org(({ name }), (err, res) => { |
@@ -1,31 +0,25 @@ | ||
var nock = require('nock') | ||
const nock = require('nock') | ||
var nockFileRequest = (repoName, fileName, responseCode, responseData) => { | ||
const nockFileRequest = (repoName, responseData, sha) => { | ||
nock('https://api.github.com') | ||
.get('/repos/' + repoName + '/contents/' + fileName) | ||
.reply(responseCode, typeof responseData !== 'undefined' ? { | ||
content: new Buffer(responseData).toString('base64') | ||
} : '') | ||
.get(`/repos/${repoName}/git/blobs/${sha}`) | ||
.reply(200, { content: new Buffer(responseData).toString('base64') }) | ||
} | ||
var nockCommitRequest = (repoName, sha, statusCode) => { | ||
const nockCommitRequest = (repoName, sha) => { | ||
nock('https://api.github.com') | ||
.get('/repos/' + repoName + '/commits') | ||
.reply(statusCode, [{ | ||
sha: sha | ||
}]) | ||
.reply(200, [{ sha }]) | ||
} | ||
var nockTreeRequest = (repoName, sha, path, statusCode) => { | ||
const nockTreeRequest = (repoName, rootSha, treeElem) => { | ||
nock('https://api.github.com') | ||
.get('/repos/' + repoName + '/git/trees/' + sha + '?recursive=1') | ||
.reply(statusCode, { | ||
tree: [{ type: 'blob', path }, { type: 'notablob', path }] | ||
}) | ||
.get(`/repos/${repoName}/git/trees/${rootSha}?recursive=1`) | ||
.reply(200, { tree: [treeElem, { type: 'notablob' }] }) | ||
} | ||
var nockUserRequest = (name, isOrg, repoName, statusCode) => { | ||
const nockUserRequest = (name, isOrg, repoName) => { | ||
nock('https://api.github.com') | ||
.get('/' + (isOrg ? 'orgs' : 'users') + '/' + name + '/repos') | ||
.reply(statusCode, [{ full_name: name + '/' + repoName }]) | ||
.get(`/${(isOrg ? 'orgs' : 'users')}/${name}/repos`) | ||
.reply(200, [{ full_name: `${name}/${repoName}` }]) | ||
} | ||
@@ -32,0 +26,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20050
17
470
4