github-api-tags-full
Advanced tools
Comparing version 6.0.0 to 7.0.0
var GitHubApi = require('github'), | ||
GithubApiTags = require('./'), | ||
path = require('path'), | ||
ProgressBar = require('progress'), | ||
moment = require('moment'); | ||
moment = require('moment'), | ||
Replay = require('replay'); | ||
@@ -16,3 +16,4 @@ var repoId = { | ||
var githubApiAuth = require('./github-api-auth.json'); | ||
// var githubApiAuth = false; | ||
var githubApiAuth = require('../docker-golang-nightly/generate/config/github-api-auth.json'); | ||
if(githubApiAuth) { | ||
@@ -24,10 +25,11 @@ github.authenticate(githubApiAuth); | ||
var bar = new ProgressBar('Fetching tag/commit :current/:total [:bar] :percent :etas', { total: 100 }); | ||
var tagChanged = function() { | ||
bar.total = this.tagsAll * 2; | ||
var bar = new ProgressBar('Fetching full tag :current/:total [:bar] :percent :etas', { total: 100 }); | ||
var pageFetched = function() { | ||
bar.total = this.tagsAll; | ||
}; | ||
var tagFetched = function() { | ||
bar.tick(); | ||
}; | ||
gat.on('tag', tagChanged); | ||
gat.on('tag-commit', tagChanged); | ||
gat.on('page', pageFetched); | ||
gat.on('tag', tagFetched); | ||
@@ -50,4 +52,5 @@ | ||
console.log('Tags sorted:'); | ||
console.log(tagsSortedDateDesc); | ||
console.log('Tags sorted.'); | ||
console.log('Latest tag: '); | ||
console.log(tagsSortedDateDesc[0]); | ||
}); |
108
index.js
@@ -12,8 +12,14 @@ var Promise = require('bluebird'), | ||
objectAssign(repoId, { per_page: 100, page: pageNo }) // max 100 per_page | ||
); | ||
) | ||
.then(function(tags) { | ||
return { | ||
no: pageNo, | ||
tags: tags | ||
}; | ||
}); | ||
}; | ||
var getTagCommit = function(tag, repoId, github) { | ||
var getTagWithCommit = function(tag, repoId, github) { | ||
return getCommit(tag, repoId, github) | ||
.then(function(commitDetails) { // commit for tag | ||
.then(function(commitDetails) { // commit (details) for tag | ||
tag.commit = objectAssign(tag.commit, commitDetails.commit); // existing commit contains the sha+url | ||
@@ -30,9 +36,15 @@ return tag; | ||
var GithubTags = function() { | ||
this.self = this; | ||
this.tagsAll = 0; | ||
this.tagsDone = 0; | ||
this.tagCommitsDone = 0; | ||
var GithubTags = function() { | ||
this.tagsAll = 0; | ||
this.tagsDone = 0; | ||
this.pagesAll = 0; | ||
this.pagesDone = 0; | ||
}; | ||
var getLastPageNo = function(page) { | ||
var lastPageUrl = parseLinks(page.tags.meta.link).last; | ||
var lastPageNo = url.parse(lastPageUrl, true).query.page; | ||
return lastPageNo; | ||
}; | ||
GithubTags.prototype.fetch = function(repoId, github) { | ||
@@ -42,66 +54,44 @@ | ||
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) { | ||
return getTags(1, repoId, github).bind(this) | ||
.then(function(firstPage) { | ||
var lastPageNo = getLastPageNo(firstPage); | ||
this.pagesAll = lastPageNo; | ||
self.tagsAll += firstTags.length; | ||
self.emit('page', 1); | ||
var restPages = []; | ||
for(pageNo = 2; pageNo <= lastPageNo; pageNo++) { | ||
restPages.push( getTags(pageNo, repoId, github) ); | ||
} | ||
var lastPageUrl = parseLinks(firstTags.meta.link).last; | ||
var lastPageNo = url.parse(lastPageUrl, true).query.page; | ||
var allPages = restPages; | ||
allPages.push(Promise.resolve(firstPage)); | ||
var pageNos = []; | ||
for(var pageNo = 2; pageNo <= lastPageNo; pageNo++) { | ||
pageNos.push(pageNo); | ||
} | ||
return Promise.map(allPages, function(page) { | ||
var tags = page.tags; | ||
this.tagsAll += tags.length; | ||
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) { | ||
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; | ||
}); | ||
}); | ||
}) | ||
this.pagesDone += 1; | ||
this.emit('page', page.no); | ||
.then(function(tagCommits) { | ||
// Also add the tags from the 1st page | ||
return Promise | ||
.map(firstTags, function(tag) { | ||
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(firstTagCommits) { | ||
return tagCommits.concat(firstTagCommits); | ||
}); | ||
return Promise.each(tags, function(tag) { | ||
return getTagWithCommit(tag, repoId, github) | ||
.then(function(tagWithCommit) { | ||
this.tagsDone += 1; | ||
this.emit('tag', tagWithCommit); | ||
}.bind(this)); | ||
}.bind(this)); | ||
}); | ||
}.bind(this)) | ||
}) | ||
.then(function(tags) { | ||
return arrayFlatten.depth(tags, 2); | ||
}); | ||
.then(cleanTagsArray); | ||
}; | ||
var cleanTagsArray = function(arrTags) { | ||
return arrayFlatten.depth(arrTags, 2); | ||
}; | ||
util.inherits(GithubTags, EventEmitter); | ||
module.exports = GithubTags; |
@@ -6,10 +6,14 @@ { | ||
"object-assign": "^4.0.1", | ||
"parse-links": "^0.1.0", | ||
"progress": "^1.1.8" | ||
"parse-links": "^0.1.0" | ||
}, | ||
"name": "github-api-tags-full", | ||
"version": "6.0.0", | ||
"version": "7.0.0", | ||
"description": "Gets all tags with their respective commit for sorting from Github API", | ||
"main": "index.js", | ||
"devDependencies": {}, | ||
"devDependencies": { | ||
"github": "^0.2.4", | ||
"moment": "^2.11.2", | ||
"progress": "^1.1.8", | ||
"replay": "^2.0.6" | ||
}, | ||
"scripts": { | ||
@@ -16,0 +20,0 @@ "test": "echo \"Error: no test specified\" && exit 1" |
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
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
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
4
8183
4
119
1
- Removedprogress@^1.1.8
- Removedprogress@1.1.8(transitive)