github-api-tags-full
Advanced tools
Comparing version 4.0.0 to 5.0.0
61
index.js
@@ -5,3 +5,5 @@ var Promise = require('bluebird'), | ||
objectAssign = require('object-assign'), | ||
arrayFlatten = require('array-flatten'); | ||
arrayFlatten = require('array-flatten'), | ||
util = require('util'), | ||
EventEmitter = require('events').EventEmitter; | ||
@@ -28,35 +30,64 @@ var getTags = function(pageNo, repoId, github) { | ||
githubTags = function(repoId, github) { | ||
var GithubTags = function() { | ||
this.self = this; | ||
this.tagsAll = 0; | ||
this.tagsDone = 0; | ||
this.tagCommitsDone = 0; | ||
}; | ||
GithubTags.prototype.fetch = function(repoId, github) { | ||
Promise.promisifyAll(github.repos); | ||
var self = this.self; | ||
// Current github API (v3) doesn't support sorting tags (e.g. by their creation date). | ||
return getTags(1, repoId, github) | ||
.then(function(firstTags) { | ||
self.tagsAll += firstTags.length; | ||
self.emit('page', 1); | ||
var lastPageUrl = parseLinks(firstTags.meta.link).last; | ||
var lastPageNo = url.parse(lastPageUrl, true).query.page; | ||
var pageNos = []; | ||
for(var pageNo = 2; pageNo <= lastPageNo; pageNo++) { | ||
var pageNos = []; | ||
for(var pageNo = 2; pageNo <= lastPageNo; pageNo++) { | ||
pageNos.push(pageNo); | ||
} | ||
// tagPages.push(firstTags); // add own tags (from this 1st lookup) | ||
return Promise | ||
.map(pageNos, function(pageNo) { // each page no | ||
return getTags(pageNo, repoId, github) | ||
.then(function(tags) { | ||
self.tagsAll += tags.length; | ||
self.emit('page', pageNo); | ||
return tags; | ||
}) | ||
.map(function(tag) { | ||
return getTagCommit(tag, repoId, github); | ||
self.tagsDone += 1; | ||
self.emit('tag', tag); | ||
return getTagCommit(tag, repoId, github) | ||
.then(function(tagCommit) { | ||
self.tagCommitsDone += 1; | ||
self.emit('tag-commit', tagCommit); | ||
}); | ||
}); | ||
}) | ||
.then(function(tagsCommits) { | ||
// Also add the first tags | ||
.then(function(tagCommits) { | ||
// Also add the tags from the 1st page | ||
return Promise | ||
.map(firstTags, function(tag) { | ||
return getTagCommit(tag, repoId, github); | ||
self.tagsDone += 1; | ||
self.emit('tag', tag); | ||
return getTagCommit(tag, repoId, github) | ||
.then(function(tagCommit) { | ||
self.tagCommitsDone += 1; | ||
self.emit('tag-commit', tagCommit); | ||
return tagCommit; | ||
}); | ||
}) | ||
.then(function(firstTagsCommits) { | ||
return tagsCommits.concat(firstTagsCommits); | ||
.then(function(firstTagCommits) { | ||
return tagCommits.concat(firstTagCommits); | ||
}); | ||
@@ -72,2 +103,4 @@ | ||
module.exports = githubTags; | ||
util.inherits(GithubTags, EventEmitter); | ||
module.exports = GithubTags; |
@@ -6,6 +6,7 @@ { | ||
"object-assign": "^4.0.1", | ||
"parse-links": "^0.1.0" | ||
"parse-links": "^0.1.0", | ||
"progress": "^1.1.8" | ||
}, | ||
"name": "github-api-tags-full", | ||
"version": "4.0.0", | ||
"version": "5.0.0", | ||
"description": "Gets all tags with their respective commit for sorting from Github API", | ||
@@ -12,0 +13,0 @@ "main": "index.js", |
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
7917
6
114
5
+ Addedprogress@^1.1.8
+ Addedprogress@1.1.8(transitive)