From 5b400c7744dc51c108a62e50f4f6d2339dc7ab03 Mon Sep 17 00:00:00 2001 From: Igor Barsi Date: Wed, 15 Feb 2017 20:26:47 -0500 Subject: [PATCH 1/3] fix(index): Added support for both string and object `package.json` repository formats. closes #7 --- main/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main/index.js b/main/index.js index 09871a4..2c6630e 100644 --- a/main/index.js +++ b/main/index.js @@ -76,7 +76,11 @@ function getRepositoryType() { TYPES.GITHUB, TYPES.BITBUCKET ], - default: repository_package ? getRepositoryTypeFromUrl(repository_package.repository) : TYPES.GITHUB + default: repository_package ? + getRepositoryTypeFromUrl(typeof repository_package.repository === 'string' ? + repository_package.repository : + repository_package.repository.type || repository_package.repository.url) : + TYPES.GITHUB } ]; From 158369041733f1eaaa3098ccbc5946c664110389 Mon Sep 17 00:00:00 2001 From: Igor Barsi Date: Mon, 20 Feb 2017 13:22:34 -0500 Subject: [PATCH 2/3] fix(commits): GitHub commits are now pulled from all branches. closes #4 --- main/modules/commits.js | 45 +++++++++++++++++++++++++++-------------- main/modules/helpers.js | 17 ++++++++++++++++ 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/main/modules/commits.js b/main/modules/commits.js index a12da51..0f8817f 100644 --- a/main/modules/commits.js +++ b/main/modules/commits.js @@ -4,7 +4,7 @@ import fs from 'fs'; -import { isFile, async, requestPromise } from './helpers'; +import { isFile, uniq, async, requestPromise } from './helpers'; // PUBLIC @@ -33,12 +33,10 @@ export function Commits(type = TYPES.GITHUB) { return new Promise((resolve, reject) => { async(function* () { try { - const url = config.url.replace('{owner}', owner).replace('{repo}', repository); - const { username, password } = yield _getCreds(config.token); const options = { - url, + url: config.commits_url.replace('{owner}', owner).replace('{repo}', repository), config: { headers: { 'User-Agent': owner, @@ -49,10 +47,22 @@ export function Commits(type = TYPES.GITHUB) { switch (type) { case TYPES.GITHUB: - resolve(yield _requestFullGitHubResponse((result) => result.map(GitHubCommit), options)); + const branches = yield requestPromise(config.branches_url.replace('{owner}', owner).replace('{repo}', repository), options.config); + const branch_commit_results = yield Promise.all(branches.data.map(branch => { + return _requestFullGitHubResponse(Object.assign({}, options, { + url: `${ options.url }?sha=${ branch.name }` + })); + })); + + const github_commits = branch_commit_results.reduce((acc, list) => acc.concat(list), []); + const unique_commits = uniq(github_commits, item => item.sha); + + resolve(unique_commits.map(GitHubCommit)); break; case TYPES.BITBUCKET: - resolve(yield _requestFullBitBucketResponse((result) => result.values.map(BitBucketCommit), options)); + const bitbucket_commits = yield _requestFullBitBucketResponse(options); + + resolve(bitbucket_commits.map(BitBucketCommit)); break; default: resolve([]); @@ -91,6 +101,7 @@ export default { function BitBucketCommit(value) { return { + id: value.sha, author: value.author.user ? value.author.user.display_name : value.author.raw, message: value.message, date: value.date @@ -99,6 +110,7 @@ function BitBucketCommit(value) { function GitHubCommit(value) { return { + id: value.sha, author: value.commit.author.name, message: value.commit.message, date: value.commit.committer.date @@ -109,17 +121,20 @@ function _initCommitProps(type) { switch (type) { case TYPES.BITBUCKET: return { - url: 'https://api.bitbucket.org/2.0/repositories/{owner}/{repo}/commits', + commits_url: 'https://api.bitbucket.org/2.0/repositories/{owner}/{repo}/commits', token: '.bitbucket_token' }; case TYPES.GITHUB: return { - url: 'https://api.github.com/repos/{owner}/{repo}/commits', + commits_url: 'https://api.github.com/repos/{owner}/{repo}/commits', + branches_url: 'https://api.github.com/repos/{owner}/{repo}/branches', token: '.github_token' }; default: return { - url: '' + commits_url: '', + branches_url: '', + token: '' }; } } @@ -135,16 +150,16 @@ function _getCreds(token) { }); } -function _requestFullBitBucketResponse(func, options, values = []) { +function _requestFullBitBucketResponse(options, values = []) { return new Promise((resolve, reject) => { async(function* () { try { const { url, config } = options; const response = yield requestPromise(url, config); - const chunked_values = values.concat(func(response.data)); + const chunked_values = values.concat(response.data.values); if (response.data.next) { - resolve(_requestFullBitBucketResponse(func, { url: response.data.next, config }, chunked_values)); + resolve(_requestFullBitBucketResponse({ url: response.data.next, config }, chunked_values)); } resolve(chunked_values); @@ -156,13 +171,13 @@ function _requestFullBitBucketResponse(func, options, values = []) { }); } -function _requestFullGitHubResponse(func, options, values = []) { +function _requestFullGitHubResponse(options, values = []) { return new Promise((resolve, reject) => { async(function* () { try { const { url, config } = options; const response = yield requestPromise(url, config); - const chunked_values = values.concat(func(response.data)); + const chunked_values = values.concat(response.data); const link = response.headers.link; @@ -170,7 +185,7 @@ function _requestFullGitHubResponse(func, options, values = []) { const next_url = link.substring(0, link.indexOf('rel="next"')); const next_url_formatted = next_url.trim().replace('<', '').replace('>', '').replace(';', ''); - resolve(_requestFullGitHubResponse(func, { url: next_url_formatted, config }, chunked_values)); + resolve(_requestFullGitHubResponse({ url: next_url_formatted, config }, chunked_values)); } resolve(chunked_values); diff --git a/main/modules/helpers.js b/main/modules/helpers.js index 0875acf..37135fa 100644 --- a/main/modules/helpers.js +++ b/main/modules/helpers.js @@ -22,6 +22,22 @@ export function isFile(path) { } } +export function uniq(list, func) { + const uids = []; + const unique_set = []; + + list.forEach(item => { + const uid = func(item); + + if (uids.indexOf(uid) < 0) { + uids.push(uid); + unique_set.push(item); + } + }); + + return unique_set; +} + export function wrapSpinner(promise, message = '') { const spinner = new CLI.Spinner(message); spinner.start(); @@ -72,6 +88,7 @@ export function async(gen, context = undefined) { export default { isFile, + uniq, wrapSpinner, partial, async From c33c81aa65a4420afc56eae0ab6df011c5c9f5b6 Mon Sep 17 00:00:00 2001 From: Igor Barsi Date: Mon, 20 Feb 2017 13:24:10 -0500 Subject: [PATCH 3/3] fix(dashboard): Remove reference to `Cmd-C` key combo. closes #8 --- main/modules/dashboard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/modules/dashboard.js b/main/modules/dashboard.js index 3df18a3..d8ad692 100644 --- a/main/modules/dashboard.js +++ b/main/modules/dashboard.js @@ -15,7 +15,7 @@ Configuration: __{{format}}__ Current Commits: __{{current_commits}}__ Previous Commits: __{{previous_commits}}__ -Press \`Esc\` or \`Ctrl/Cmd-C\` to quit.`; +Press \`Esc\` or \`Ctrl-C\` to quit.`; const listing_settings = { fg: 'green',