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

changed-log

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

changed-log - npm Package Compare versions

Comparing version 0.11.0 to 0.12.0

41

bin/changed-log.js
#!/usr/bin/env node
require('lazy-ass');
var check = require('check-more-types');
require('lazy-ass')
var check = require('check-more-types')
/* eslint no-console:0 */
var log = console.log.bind(console);
var debug = require('debug')('changed');
var _ = require('lodash');
var pkg = require('../package.json');
var updateNotifier = require('update-notifier');
updateNotifier({ pkg: pkg }).notify();
var log = console.log.bind(console)
var debug = require('debug')('changed')
var _ = require('lodash')
var pkg = require('../package.json')
var updateNotifier = require('update-notifier')
updateNotifier({ pkg: pkg }).notify()

@@ -18,8 +18,8 @@ var options = {

to: process.argv[4]
};
}
options.auth = _.some(process.argv, function (word) {
return word === '--auth';
});
debug('options', options);
return word === '--auth'
})
debug('options', options)

@@ -31,13 +31,18 @@ // TODO implement semver in check-more-types

to: check.maybe.unemptyString
});
})
if (!isValidCliOptions(options)) {
log('%s@%s <package name> <from version> <to version> [options]',
pkg.name, pkg.version);
log('options:\n --auth - login with github credentials for increased rate limit');
pkg.name, pkg.version)
log('options:\n --auth - login with github credentials for increased rate limit')
/* eslint no-process-exit:0 */
process.exit(-1);
process.exit(-1)
}
var changedLog = require('../src/changed-log');
if (!options.to) {
debug('"to" version is not set, assuming latest')
options.to = 'latest'
}
var changedLog = require('../src/changed-log')
changedLog(options)
.done();
.done()

@@ -5,3 +5,3 @@ {

"main": "src/changed-log.js",
"version": "0.11.0",
"version": "0.12.0",
"bin": {

@@ -18,3 +18,3 @@ "changed-log": "bin/changed-log.js"

"chalk-with-mock": "DEBUG=changed node mocks/mock-for-chalk.js bin/changed-log.js chalk 0.3.0 0.5.1",
"lint": "eslint bin/*.js src/*.js mocks/*.js",
"lint": "standard --verbose --fix bin/*.js src/*.js mocks/*.js",
"commit": "git-issues && commit-wizard",

@@ -55,6 +55,6 @@ "issues": "git-issues",

"lodash": "3.10.1",
"package-json": "2.3.3",
"package-json": "2.4.0",
"parse-github-repo-url": "1.3.0",
"ramda": "0.15.1",
"update-notifier": "1.0.2"
"update-notifier": "1.0.3"
},

@@ -64,8 +64,8 @@ "devDependencies": {

"condition-node-version": "1.3.0",
"eslint": "0.24.0",
"git-issues": "1.2.0",
"git-issues": "1.3.1",
"mocha": "3.0.2",
"pre-git": "3.10.0",
"pre-git": "3.12.0",
"really-need": "1.9.2",
"semantic-release": "6.3.0"
"semantic-release": "6.3.0",
"standard": "8.6.0"
},

@@ -72,0 +72,0 @@ "files": [

@@ -56,2 +56,6 @@ # changed-log

You can omit "latest" and just specify name and "from" version
$ changed-log <name> <from>
If you only provide a single version from a folder that contains `package.json`

@@ -58,0 +62,0 @@ it will read the 'from' version from the the `package.json`, assuming you have only

@@ -1,27 +0,27 @@

var la = require('lazy-ass');
var check = require('check-more-types');
var packageRepo = require('./package-repo');
var Promise = require('bluebird');
var la = require('lazy-ass')
var check = require('check-more-types')
var packageRepo = require('./package-repo')
var Promise = require('bluebird')
/* eslint no-console:0 */
var log = console.log.bind(console);
var debug = require('debug')('changed');
var _ = require('lodash');
var log = console.log.bind(console)
var debug = require('debug')('changed')
var _ = require('lodash')
function failedToFind(err) {
console.error('Could not find commit ids');
console.error(err.message);
return Promise.reject(err);
function failedToFind (err) {
console.error('Could not find commit ids')
console.error(err.message)
return Promise.reject(err)
}
function failedToFindComments(err) {
console.error('Could not find comments');
console.error(err.message);
return Promise.reject(err);
function failedToFindComments (err) {
console.error('Could not find comments')
console.error(err.message)
return Promise.reject(err)
}
function findCommitIds(options, repoInfo) {
la(check.object(repoInfo), 'missing repo info', repoInfo);
debug('Finding commit ids');
var tagsToCommits = require('./get-commits-from-tags');
function findCommitIds (options, repoInfo) {
la(check.object(repoInfo), 'missing repo info', repoInfo)
debug('Finding commit ids')
var tagsToCommits = require('./get-commits-from-tags')
var tagOptions = {

@@ -32,16 +32,16 @@ user: repoInfo.user,

to: options.to
};
}
return tagsToCommits(tagOptions)
.tap(debug)
.then(function mergeCommitInfo(tagsInfo) {
return _.extend({}, repoInfo, options, tagsInfo);
}, failedToFind);
.then(function mergeCommitInfo (tagsInfo) {
return _.extend({}, repoInfo, options, tagsInfo)
}, failedToFind)
}
function findCommentsBetweenTags(options) {
la(check.object(options), 'missing options', options);
la(check.object(options.fromTag), 'missing fromTag', options);
la(check.object(options.toTag), 'missing toTag', options);
function findCommentsBetweenTags (options) {
la(check.object(options), 'missing options', options)
la(check.object(options.fromTag), 'missing fromTag', options)
la(check.object(options.toTag), 'missing toTag', options)
var findCommits = require('./get-comments-between-commits');
var findCommits = require('./get-comments-between-commits')
var findOptions = {

@@ -52,13 +52,13 @@ user: options.user,

to: options.toTag.sha
};
}
function setReport(report) {
report.options.name = options.name;
report.options.from = options.from;
report.options.to = options.to;
return report;
function setReport (report) {
report.options.name = options.name
report.options.from = options.from
report.options.to = options.to
return report
}
return findCommits(findOptions)
.then(setReport, failedToFindComments);
.then(setReport, failedToFindComments)
}

@@ -68,21 +68,21 @@

from: check.equal('latest')
});
})
function changedAfterLatest(options/*, reportOptions*/) {
debug('Returning comments from commits after latest tag');
function changedAfterLatest (options/*, reportOptions */) {
debug('Returning comments from commits after latest tag')
return packageRepo(options.name)
.then(_.partial(findCommitIds, options))
.tap(debug);
.tap(debug)
}
function changedLogReport(options, reportOptions) {
function changedLogReport (options, reportOptions) {
// TODO validate options
options = options || {};
reportOptions = reportOptions || {};
options = options || {}
reportOptions = reportOptions || {}
if (isLatest(options)) {
return changedAfterLatest(options, reportOptions);
return changedAfterLatest(options, reportOptions)
}
var allTags;
var allTags

@@ -93,80 +93,80 @@ return packageRepo(options.name)

.tap(function (result) {
la(check.array(result.allTags), 'expected all tags in', result);
allTags = result.allTags;
la(check.array(result.allTags), 'expected all tags in', result)
allTags = result.allTags
})
.then(findCommentsBetweenTags)
.tap(function (result) {
console.log('found %d comments between tags', result.comments.length);
console.log('found %d comments between tags', result.comments.length)
// console.log(JSON.stringify(result, null, 2));
})
.then(function mergeCommitsAndTags(report) {
report.allTags = allTags;
return report;
.then(function mergeCommitsAndTags (report) {
report.allTags = allTags
return report
})
.tap(debug)
.tap(function (report) {
la(check.object(report), 'missing report', report);
la(check.fn(report.print), 'cannot print report', report);
report.print(reportOptions);
});
la(check.object(report), 'missing report', report)
la(check.fn(report.print), 'cannot print report', report)
report.print(reportOptions)
})
}
function startFromLatestPublishedTag(options) {
function startFromLatestPublishedTag (options) {
return options.from === 'latest' &&
!options.to;
!options.to
}
function onlyProvidedFromVersion(options) {
function onlyProvidedFromVersion (options) {
return check.unemptyString(options.from) &&
!options.to;
!options.to
}
function providedNoVersions(options) {
function providedNoVersions (options) {
return !options.from &&
!options.to;
!options.to
}
function readPackageJson() {
var exists = require('fs').existsSync;
var join = require('path').join;
var packageFileName = join(process.cwd(), 'package.json');
function readPackageJson () {
var exists = require('fs').existsSync
var join = require('path').join
var packageFileName = join(process.cwd(), 'package.json')
/* eslint consistent-return:0 */
if (!exists(packageFileName)) {
return;
return
}
var pkg = require(packageFileName);
return pkg;
var pkg = require(packageFileName)
return pkg
}
function getDependency(name) {
la(check.unemptyString(name), 'missing package name', name);
var pkg = readPackageJson();
function getDependency (name) {
la(check.unemptyString(name), 'missing package name', name)
var pkg = readPackageJson()
/* eslint consistent-return:0 */
if (!pkg) {
return;
return
}
var dependency = (pkg.dependencies && pkg.dependencies[name]) ||
(pkg.devDependencies && pkg.devDependencies[name]);
return dependency;
(pkg.devDependencies && pkg.devDependencies[name])
return dependency
}
function fillMissingFromOptions(options) {
var dependency = getDependency(options.name);
function fillMissingFromOptions (options) {
var dependency = getDependency(options.name)
if (dependency) {
options.to = options.from;
options.from = dependency;
console.log('using "from" version from package.json %s', dependency);
options.to = options.from
options.from = dependency
console.log('using "from" version from package.json %s', dependency)
}
}
function fillMissingFromToOptions(options) {
var dependency = getDependency(options.name);
function fillMissingFromToOptions (options) {
var dependency = getDependency(options.name)
if (dependency) {
options.from = dependency;
options.to = 'latest';
console.log('using "from" version from package.json %s to "latest"', dependency);
options.from = dependency
options.to = 'latest'
console.log('using "from" version from package.json %s to "latest"', dependency)
}
}
function missingOptions(options) {
function missingOptions (options) {
var isValidCliOptions = check.schema.bind(null, {

@@ -176,13 +176,13 @@ name: check.unemptyString,

to: check.unemptyString
});
return !isValidCliOptions(options);
})
return !isValidCliOptions(options)
}
function changedLog(options, reportOptions) {
options = options || {};
reportOptions = reportOptions || {};
function changedLog (options, reportOptions) {
options = options || {}
reportOptions = reportOptions || {}
if (startFromLatestPublishedTag(options)) {
log('Finding changes after last published NPM version for "%s"', options.name);
return changedLogReport(options, reportOptions);
log('Finding changes after last published NPM version for "%s"', options.name)
return changedLogReport(options, reportOptions)
}

@@ -192,27 +192,27 @@

// assume we specified target "to" version
fillMissingFromOptions(options);
fillMissingFromOptions(options)
}
if (providedNoVersions(options)) {
log('need latest "to" version');
fillMissingFromToOptions(options);
log('need latest "to" version')
fillMissingFromToOptions(options)
}
if (missingOptions(options)) {
console.error('Missing options', options);
console.error('Missing options', options)
/* eslint no-process-exit:0 */
process.exit(-1);
process.exit(-1)
}
if (options.auth) {
log('Please login to github to increase the API rate limit');
var githubLogin = require('./github-login');
log('Please login to github to increase the API rate limit')
var githubLogin = require('./github-login')
return githubLogin()
.then(_.partial(changedLogReport, options, reportOptions));
.then(_.partial(changedLogReport, options, reportOptions))
}
return changedLogReport(options, reportOptions);
return changedLogReport(options, reportOptions)
}
module.exports = changedLog;
module.exports = changedLog

@@ -232,3 +232,3 @@ if (!module.parent) {

from: 'latest'
}).done();
}).done()
}

@@ -1,12 +0,12 @@

var la = require('lazy-ass');
var check = require('check-more-types');
var utils = require('./utils');
var R = require('ramda');
var _ = require('lodash');
var debug = require('debug')('between');
var la = require('lazy-ass')
var check = require('check-more-types')
var utils = require('./utils')
var R = require('ramda')
var _ = require('lodash')
var debug = require('debug')('between')
var getCommitsBetween = require('./get-commits-between');
la(check.fn(getCommitsBetween), 'missing function get commits between', getCommitsBetween);
var getCommitsBetween = require('./get-commits-between')
la(check.fn(getCommitsBetween), 'missing function get commits between', getCommitsBetween)
var Report = require('./report');
var Report = require('./report')
var areValidOptions = check.schema.bind(null, {

@@ -17,3 +17,3 @@ user: check.unemptyString,

to: check.commitId
});
})

@@ -25,36 +25,35 @@ var afterCommitOptions = check.schema({

to: check.not.defined
});
})
function getCommentsAfter(options) {
debug('finding comments after %s/%s %s', options.user, options.repo, options.from);
function getCommentsAfter (options) {
debug('finding comments after %s/%s %s', options.user, options.repo, options.from)
var report = new Report(options);
var report = new Report(options)
return getCommitsBetween(options)
.then(R.always(report));
.then(R.always(report))
}
function getCommentsBetweenCommits(options) {
function getCommentsBetweenCommits (options) {
if (afterCommitOptions(options)) {
return getCommentsAfter(options);
return getCommentsAfter(options)
}
la(areValidOptions(options), 'bad options', options);
var report = new Report(options);
la(areValidOptions(options), 'bad options', options)
var report = new Report(options)
return getCommitsBetween(options)
.tap(function (commits) {
report.ids = _.pluck(commits, 'sha');
report.comments = _.pluck(commits, 'message');
report.ids = _.pluck(commits, 'sha')
report.comments = _.pluck(commits, 'message')
})
.then(R.always(report));
.then(R.always(report))
}
// resolves with Report object
module.exports = getCommentsBetweenCommits;
module.exports = getCommentsBetweenCommits
if (!module.parent) {
(function examples() {
(function examples () {
/* eslint no-unused-vars:0 */
function smallNumberOfCommitsExample() {
function smallNumberOfCommitsExample () {
var options = {

@@ -65,11 +64,11 @@ user: 'bahmutov',

to: '3d2b1fa3523c0be35ecfb30d4c81407fd4ce30a6'
};
}
getCommentsBetweenCommits(options)
.tap(function (report) {
la(check.object(report), 'did not get a report', report);
report.print();
});
la(check.object(report), 'did not get a report', report)
report.print()
})
}
function largeNumberOfCommitsExample() {
function largeNumberOfCommitsExample () {
var options = {

@@ -80,11 +79,11 @@ user: 'chalk',

to: '994758f01293f1fdcf63282e9917cb9f2cfbdaac' // latest (tag 0.5.1)
};
}
getCommentsBetweenCommits(options)
.tap(function (report) {
la(check.object(report), 'did not get a report', report);
report.print();
});
la(check.object(report), 'did not get a report', report)
report.print()
})
}
function commitsAfterThis() {
function commitsAfterThis () {
var options = {

@@ -94,8 +93,8 @@ user: 'chalk',

from: '8b554e254e89c85c1fd04dcc444beeb15824e1a5'
};
}
getCommentsBetweenCommits(options)
.tap(function (report) {
la(check.object(report), 'did not get a report', report);
report.print();
});
la(check.object(report), 'did not get a report', report)
report.print()
})
}

@@ -105,4 +104,4 @@

// largeNumberOfCommitsExample();
commitsAfterThis();
}());
commitsAfterThis()
}())
}

@@ -1,16 +0,16 @@

var la = require('lazy-ass');
var check = require('check-more-types');
var utils = require('./utils');
var R = require('ramda');
var _ = require('lodash');
var debug = require('debug')('between');
var reposApi = utils.github.repos;
var Promise = require('bluebird');
var getCommits = Promise.promisify(reposApi.getCommits);
var la = require('lazy-ass')
var check = require('check-more-types')
var utils = require('./utils')
var R = require('ramda')
var _ = require('lodash')
var debug = require('debug')('between')
var reposApi = utils.github.repos
var Promise = require('bluebird')
var getCommits = Promise.promisify(reposApi.getCommits)
function getCommitsFrom(user, repo, latest, stop, previousCommits) {
previousCommits = previousCommits || [];
function getCommitsFrom (user, repo, latest, stop, previousCommits) {
previousCommits = previousCommits || []
debug('commits %s/%s latest %s stop %s, previous number %d',
user, repo, utils.shortenSha(latest), utils.shortenSha(stop),
previousCommits.length);
previousCommits.length)

@@ -21,7 +21,7 @@ var messageOptions = {

sha: latest
};
}
if (utils.github.twoFactor) {
messageOptions.headers = {
'X-GitHub-OTP': utils.github.twoFactor
};
}
}

@@ -34,22 +34,22 @@

utils.shortenSha(R.last(commits).sha)
);
)
var allCommits = previousCommits.length ? previousCommits.concat(commits.slice(1)) : commits;
var fromIndex = _.findIndex(allCommits, 'sha', stop);
var allCommits = previousCommits.length ? previousCommits.concat(commits.slice(1)) : commits
var fromIndex = _.findIndex(allCommits, 'sha', stop)
if (fromIndex === -1) {
if (commits.length === 1) {
debug('fetched single commit %s, stopping', utils.shortenSha(commits[0].sha));
return allCommits;
debug('fetched single commit %s, stopping', utils.shortenSha(commits[0].sha))
return allCommits
}
var last = R.last(allCommits).sha;
debug('could not find the stop commit, fetching more commits starting with %s', last);
var last = R.last(allCommits).sha
debug('could not find the stop commit, fetching more commits starting with %s', last)
// using delay to debug
return Promise.delay(1).then(function () {
return getCommitsFrom(user, repo, last, stop, allCommits);
});
return getCommitsFrom(user, repo, last, stop, allCommits)
})
} else {
return allCommits;
return allCommits
}
});
})
}

@@ -59,15 +59,15 @@

// latest commit is first in the list
function getCommitsBetween(options) {
utils.verifyRepoOptions(options);
function getCommitsBetween (options) {
utils.verifyRepoOptions(options)
var schema = {
from: check.commitId,
to: check.commitId
};
la(check.schema(schema, options), 'invalid from and to commits', options);
}
la(check.schema(schema, options), 'invalid from and to commits', options)
return getCommitsFrom(options.user, options.repo, options.to, options.from)
.then(function (commits) {
la(check.array(commits), 'could not get list of commits', options);
la(check.array(commits), 'could not get list of commits', options)
debug('found %d commits finishing with the latest commit %s',
commits.length, utils.shortenSha(options.to));
commits.length, utils.shortenSha(options.to))

@@ -78,7 +78,7 @@ return R.map(function (commit) {

message: commit.commit.message
};
}, commits);
}
}, commits)
}).then(function (commits) {
var fromIndex = _.findIndex(commits, 'sha', options.from);
debug('from commit %s is at index %d', options.from, fromIndex);
var fromIndex = _.findIndex(commits, 'sha', options.from)
debug('from commit %s is at index %d', options.from, fromIndex)
// we are not really interested in FROM commit, so start

@@ -88,13 +88,13 @@ // slice at index 1

// the item at the fromIndex position
return _.slice(commits, 0, fromIndex);
});
return _.slice(commits, 0, fromIndex)
})
}
module.exports = getCommitsBetween;
module.exports = getCommitsBetween
if (!module.parent) {
(function examples() {
(function examples () {
/* eslint no-unused-vars:0 */
function commitsAfter() {
function commitsAfter () {
var options = {

@@ -104,9 +104,9 @@ user: 'chalk',

from: '8b554e254e89c85c1fd04dcc444beeb15824e1a5'
};
}
getCommitsBetween(options)
.then(console.log.bind(console))
.done();
.done()
}
commitsAfter();
}());
commitsAfter()
}())
}

@@ -1,17 +0,17 @@

var la = require('lazy-ass');
var check = require('check-more-types');
var utils = require('./utils');
var _ = require('lodash');
var R = require('ramda');
var Promise = require('bluebird');
var la = require('lazy-ass')
var check = require('check-more-types')
var utils = require('./utils')
var _ = require('lodash')
var R = require('ramda')
var Promise = require('bluebird')
/* eslint no-console:0 */
var log = console.log.bind(console);
var reposApi = utils.github.repos;
var gTags = Promise.promisify(reposApi.getTags);
var debug = require('debug')('tags');
var log = console.log.bind(console)
var reposApi = utils.github.repos
var gTags = Promise.promisify(reposApi.getTags)
var debug = require('debug')('tags')
function nameAndSha(tags) {
function nameAndSha (tags) {
if (check.array(tags)) {
return _.map(tags, nameAndSha);
return _.map(tags, nameAndSha)
}

@@ -21,21 +21,21 @@ return {

sha: tags.commit.sha
};
}
}
function trimVersions(tags) {
function trimVersions (tags) {
return tags.map(function (tag) {
tag.name = utils.trimVersion(tag.name);
return tag;
});
tag.name = utils.trimVersion(tag.name)
return tag
})
}
function getTags(options) {
la(check.object(options), 'missing options', options);
utils.verifyRepoOptions(options);
function getTags (options) {
la(check.object(options), 'missing options', options)
utils.verifyRepoOptions(options)
var messageOptions = _.clone(options);
var messageOptions = _.clone(options)
if (utils.github.twoFactor) {
messageOptions.headers = {
'X-GitHub-OTP': utils.github.twoFactor
};
}
}

@@ -46,3 +46,3 @@

.then(nameAndSha)
.then(trimVersions);
.then(trimVersions)
}

@@ -52,19 +52,19 @@

from: check.equal('latest')
});
})
function getLatestTag(question) {
la(isLatest(question), 'wrong latest schema', question);
function getLatestTag (question) {
la(isLatest(question), 'wrong latest schema', question)
return getTags(_.pick(question, 'user', 'repo'))
.then(function (allTags) {
la(check.array(allTags), 'missing tags', allTags);
la(check.array(allTags), 'missing tags', allTags)
// assuming the tags are sorted, with latest the first
return {
latest: allTags[0]
};
});
}
})
}
function getFromToTags(question) {
function getFromToTags (question) {
if (isLatest(question)) {
return getLatestTag(question);
return getLatestTag(question)
}

@@ -75,32 +75,38 @@

to: check.unemptyString
};
la(check.schema(tagSchema, question), question);
}
la(check.schema(tagSchema, question), question)
return getTags(_.pick(question, 'user', 'repo'))
.then(function (allTags) {
la(check.array(allTags), 'missing tags', allTags);
var fromTagIndex = _.findIndex(allTags, 'name', question.from);
la(fromTagIndex !== -1, 'cannot find tag', question.from, 'all tags', allTags);
la(check.array(allTags), 'missing tags', allTags)
var fromTagIndex = _.findIndex(allTags, 'name', question.from)
la(fromTagIndex !== -1, 'cannot find tag', question.from, 'all tags', allTags)
var toTagIndex = question.to === 'latest' ? 0 :
_.findIndex(allTags, 'name', question.to);
la(toTagIndex !== -1, 'cannot to tag', question.to, 'all tags', allTags);
var toTagIndex = question.to === 'latest' ? 0
: _.findIndex(allTags, 'name', question.to)
if (toTagIndex === -1) {
const msg = 'Cannot find "to" tag with value "' + question.to + '"'
console.error(msg)
console.error('Available tags', allTags)
return Promise.reject(new Error(msg))
}
la(toTagIndex !== -1, 'cannot to tag', question.to, 'all tags', allTags)
debug('from tag %s index %d to tag %s index %d',
question.from, fromTagIndex,
question.to, toTagIndex);
question.to, toTagIndex)
if (fromTagIndex < toTagIndex) {
debug('flipping the tag order');
var tmp = fromTagIndex;
fromTagIndex = toTagIndex;
toTagIndex = tmp;
debug('flipping the tag order')
var tmp = fromTagIndex
fromTagIndex = toTagIndex
toTagIndex = tmp
tmp = question.from;
question.from = question.to;
question.to = tmp;
tmp = question.from
question.from = question.to
question.to = tmp
}
var fromTag = allTags[fromTagIndex];
var toTag = allTags[toTagIndex];
var fromTag = allTags[fromTagIndex]
var toTag = allTags[toTagIndex]

@@ -111,14 +117,12 @@ return {

allTags: allTags
};
});
}
})
}
module.exports = getFromToTags;
module.exports = getFromToTags
if (!module.parent) {
(function examples() {
(function examples () {
/* eslint no-unused-vars:0 */
function nextUpdateExample() {
function nextUpdateExample () {
var question = {

@@ -129,11 +133,11 @@ user: 'bahmutov',

to: '0.8.2' // or 'latest?'
};
}
log('Getting commit SHA for the given tags');
log(question);
log('Getting commit SHA for the given tags')
log(question)
getFromToTags(question)
.then(log);
.then(log)
}
function nextUpdateReverseTagOrderExample() {
function nextUpdateReverseTagOrderExample () {
var question = {

@@ -144,11 +148,11 @@ user: 'bahmutov',

to: '0.8.0'
};
}
log('Getting commit SHA for the given tags');
log(question);
log('Getting commit SHA for the given tags')
log(question)
getFromToTags(question)
.then(log);
.then(log)
}
function chalkExample() {
function chalkExample () {
var question = {

@@ -159,12 +163,12 @@ user: 'chalk',

to: '0.3.0'
};
}
log('Getting commit SHA for the given tags');
log('Getting commit SHA for the given tags')
log('%s / %s from %s to %s',
question.user, question.repo, question.from, question.to);
question.user, question.repo, question.from, question.to)
getFromToTags(question)
.then(log);
.then(log)
}
function fromLatestChalkExample() {
function fromLatestChalkExample () {
var question = {

@@ -174,11 +178,11 @@ user: 'chalk',

from: 'latest'
};
}
log('Getting commit SHA for the given tags');
log('%s / %s from latest tag', question.user, question.repo);
log('Getting commit SHA for the given tags')
log('%s / %s from latest tag', question.user, question.repo)
getFromToTags(question)
.then(log);
.then(log)
}
function getLatestTagExample() {
function getLatestTagExample () {
var question = {

@@ -188,4 +192,4 @@ user: 'chalk',

from: 'latest'
};
getLatestTag(question).then(log).done();
}
getLatestTag(question).then(log).done()
}

@@ -195,5 +199,5 @@

// nextUpdateReverseTagOrderExample();
fromLatestChalkExample();
fromLatestChalkExample()
// getLatestTagExample();
}());
}())
}

@@ -1,11 +0,11 @@

var la = require('lazy-ass');
var check = require('check-more-types');
var la = require('lazy-ass')
var check = require('check-more-types')
/* eslint no-console:0 */
var log = console.log.bind(console);
var Promise = require('bluebird');
var utils = require('./utils');
var debug = require('debug')('login');
var inquirer = require('inquirer');
var log = console.log.bind(console)
var Promise = require('bluebird')
var utils = require('./utils')
var debug = require('debug')('login')
var inquirer = require('inquirer')
function askGithubUsernameAndPassword() {
function askGithubUsernameAndPassword () {
var username = {

@@ -15,3 +15,3 @@ type: 'input',

message: 'github username'
};
}
var password = {

@@ -21,3 +21,3 @@ type: 'password',

message: 'github password (not stored locally)'
};
}
var using2Factor = {

@@ -27,10 +27,10 @@ type: 'confirm',

message: 'Use 2Factor auth?'
};
}
return new Promise(function (resolve) {
var questions = [username, password, using2Factor];
var questions = [username, password, using2Factor]
inquirer.prompt(questions, function (answers) {
la(check.unemptyString(answers.username), 'missing username', answers);
la(check.unemptyString(answers.password), 'missing password', answers);
la(check.unemptyString(answers.username), 'missing username', answers)
la(check.unemptyString(answers.password), 'missing password', answers)

@@ -41,8 +41,8 @@ resolve({

using2Factor: answers.twoFactor
});
});
});
})
})
})
}
function askGithub2FactorCode() {
function askGithub2FactorCode () {
var twoFactor = {

@@ -52,21 +52,21 @@ type: 'input',

message: 'enter GitHub 2Factor code'
};
}
return new Promise(function (resolve) {
var questions = [twoFactor];
var questions = [twoFactor]
inquirer.prompt(questions, function (answers) {
la(check.unemptyString(answers.twoFactor),
'missing two factor code', answers);
'missing two factor code', answers)
resolve(answers.twoFactor);
});
});
resolve(answers.twoFactor)
})
})
}
function githubLogin() {
function githubLogin () {
return askGithubUsernameAndPassword()
.tap(function (answers) {
log('trying to login to github %s', answers.username);
la(check.unemptyString(answers.password), 'empty password for', answers.username);
log('trying to login to github %s', answers.username)
la(check.unemptyString(answers.password), 'empty password for', answers.username)

@@ -77,26 +77,26 @@ utils.github.authenticate({

password: answers.password
});
})
})
.then(function set2FactorHeader(answers) {
.then(function set2FactorHeader (answers) {
if (answers.using2Factor) {
return askGithub2FactorCode()
.then(function (twoFactor) {
la(check.unemptyString(twoFactor), 'expected valid two factor code');
debug('User 2Factor code %s', twoFactor);
utils.github.twoFactor = twoFactor;
});
la(check.unemptyString(twoFactor), 'expected valid two factor code')
debug('User 2Factor code %s', twoFactor)
utils.github.twoFactor = twoFactor
})
}
});
})
}
module.exports = githubLogin;
module.exports = githubLogin
if (!module.parent) {
(function exampleLogin() {
log('example github login');
(function exampleLogin () {
log('example github login')
githubLogin()
.then(function () {
log('finished login, trying a sample method');
log('finished login, trying a sample method')
}).then(function () {
var getFromToTags = require('./get-commits-from-tags');
var getFromToTags = require('./get-commits-from-tags')
var question = {

@@ -107,8 +107,8 @@ user: 'kensho',

to: '0.4.2'
};
}
getFromToTags(question)
.then(log);
});
}());
.then(log)
})
}())
}

@@ -1,42 +0,42 @@

var la = require('lazy-ass');
var check = require('check-more-types');
var Promise = require('bluebird');
var R = require('ramda');
var debug = require('debug')('changed');
var packageField = require('package-json');
var utils = require('./utils');
var la = require('lazy-ass')
var check = require('check-more-types')
var Promise = require('bluebird')
var R = require('ramda')
var debug = require('debug')('changed')
var packageField = require('package-json')
var utils = require('./utils')
/* eslint no-console:0 */
var log = console.log.bind(console);
var log = console.log.bind(console)
function getRepo(info) {
debug('Getting repo from info object');
debug(info);
function getRepo (info) {
debug('Getting repo from info object')
debug(info)
if (check.object(info.repository)) {
return info.repository;
return info.repository
}
la(check.object(info.versions), 'missing versions', info);
var latestTag = R.last(Object.keys(info.versions));
var latest = info.versions[latestTag];
return latest.repository;
la(check.object(info.versions), 'missing versions', info)
var latestTag = R.last(Object.keys(info.versions))
var latest = info.versions[latestTag]
return latest.repository
}
function failedAtSomething(label, err) {
console.error('failed at %s', label);
console.error(err);
return Promise.reject(err);
function failedAtSomething (label, err) {
console.error('failed at %s', label)
console.error(err)
return Promise.reject(err)
}
// resolves with the github url for the given NPM package name
function packageRepo(name) {
la(check.unemptyString(name), 'missing package name', name);
function packageRepo (name) {
la(check.unemptyString(name), 'missing package name', name)
if (utils.isGithubName(name)) {
debug('package name "%s" is repo', name);
return Promise.resolve(utils.parseGithubName(name));
debug('package name "%s" is repo', name)
return Promise.resolve(utils.parseGithubName(name))
}
debug('getting package repo for "%s"', name);
var json;
debug('getting package repo for "%s"', name)
var json

@@ -46,3 +46,3 @@ return Promise.resolve(packageField(name))

.tap(function (info) {
json = info;
json = info
})

@@ -52,5 +52,5 @@ .then(getRepo)

.then(function (repo) {
debug('just the repo', repo);
utils.verifyGithub(json, repo);
return repo;
debug('just the repo', repo)
utils.verifyGithub(json, repo)
return repo
})

@@ -60,7 +60,7 @@ .then(R.prop('url'))

.then(R.tap(function (parsed) {
debug('parsed github url', parsed);
}));
debug('parsed github url', parsed)
}))
}
module.exports = packageRepo;
module.exports = packageRepo

@@ -70,8 +70,8 @@ if (!module.parent) {

// var name = 'next-update';
var name = 'grunt-contrib-jshint';
log('getting repo info for package %s', name);
var name = 'grunt-contrib-jshint'
log('getting repo info for package %s', name)
packageRepo(name)
.then(log)
.catch(log);
}());
.catch(log)
}())
}

@@ -1,57 +0,57 @@

var la = require('lazy-ass');
var check = require('check-more-types');
var la = require('lazy-ass')
var check = require('check-more-types')
/* eslint no-console:0 */
var log = console.log.bind(console);
var chalk = require('chalk');
var pkg = require('../package.json');
var utils = require('./utils');
var _ = require('lodash');
var log = console.log.bind(console)
var chalk = require('chalk')
var pkg = require('../package.json')
var utils = require('./utils')
var _ = require('lodash')
function Report(options) {
function Report (options) {
// TODO validate options
la(check.object(options), 'missing options');
la(check.object(options), 'missing options')
this.options = options;
this.ids = [];
this.comments = [];
this.allTags = [];
this.options = options
this.ids = []
this.comments = []
this.allTags = []
}
Report.prototype.tagForCommit = function tagForCommit(sha) {
var report = this;
return _.find(report.allTags, 'sha', sha);
};
Report.prototype.tagForCommit = function tagForCommit (sha) {
var report = this
return _.find(report.allTags, 'sha', sha)
}
Report.prototype.print = function print(opts) {
opts = opts || {};
var report = this;
Report.prototype.print = function print (opts) {
opts = opts || {}
var report = this
log('Changelog for module', chalk.underline(report.options.name),
'repo', chalk.underline(report.options.user + '/' + report.options.repo),
'from', report.options.from, 'to', report.options.to);
'from', report.options.from, 'to', report.options.to)
la(report.ids.length === report.comments.length,
'mismatch in ids vs comments', report);
'mismatch in ids vs comments', report)
report.ids.forEach(function (id, k) {
var comment = report.comments[k] || '';
var comment = report.comments[k] || ''
if (!opts.details) {
comment = utils.firstLine(comment);
comment = utils.firstLine(comment)
}
var ownsTag = report.tagForCommit(id);
var ownsTag = report.tagForCommit(id)
if (ownsTag) {
log('\n' + chalk.bold.underline(ownsTag.name));
log('\n' + chalk.bold.underline(ownsTag.name))
}
log(' ' + chalk.bold(utils.shortenSha(id)) + ': ' + comment);
});
log(' ' + chalk.bold(utils.shortenSha(id)) + ': ' + comment)
})
log('\nReport generated by %s %s', pkg.name, pkg.homepage);
};
log('\nReport generated by %s %s', pkg.name, pkg.homepage)
}
module.exports = Report;
module.exports = Report
if (!module.parent) {
(function sampleReport() {
(function sampleReport () {
var report = new Report({

@@ -63,3 +63,3 @@ user: 'bahmutov',

to: '0.8.3'
});
})
report.ids = [

@@ -70,3 +70,3 @@ '89d437c4fe1178f120511ef43d6f6440956ba559',

'a4eb79977600fc5d001617449a1874168b38d6c3'
];
]
report.comments = [

@@ -77,3 +77,3 @@ 'Printing allowed type, fixes #59',

'bump'
];
]
report.allTags = [

@@ -110,5 +110,5 @@ { name: '0.0.12', sha: 'a343f9062999ae11418b2e1ee86d5f1776873a50' },

{ name: '0.5.0', sha: '82747f3eff789b5ea8fade040735b2c11b116eb8' }
];
report.print();
}());
]
report.print()
}())
}

@@ -1,8 +0,8 @@

'use strict';
'use strict'
var log = require('debug')('changed');
var la = require('lazy-ass');
var check = require('check-more-types');
var R = require('ramda');
var parseGh = require('parse-github-repo-url');
var log = require('debug')('changed')
var la = require('lazy-ass')
var check = require('check-more-types')
var R = require('ramda')
var parseGh = require('parse-github-repo-url')

@@ -12,22 +12,22 @@ var repoSchema = {

repo: check.unemptyString
};
}
var isRepoQuestion = R.partial(check.schema, repoSchema);
function verifyRepoOptions(options) {
la(isRepoQuestion(options), 'missing repo info', options);
var isRepoQuestion = R.partial(check.schema, repoSchema)
function verifyRepoOptions (options) {
la(isRepoQuestion(options), 'missing repo info', options)
}
function isGithubUrl(url) {
function isGithubUrl (url) {
return check.unemptyString(url) &&
/github\.com/.test(url);
/github\.com/.test(url)
}
function verifyGithub(message, repo) {
function verifyGithub (message, repo) {
la(check.object(repo) &&
repo.type === 'git' &&
isGithubUrl(repo.url),
'not a github repo', repo, message);
'not a github repo', repo, message)
}
var GitHubApi = require('github');
var GitHubApi = require('github')
var github = new GitHubApi({

@@ -38,59 +38,59 @@ // required

debug: false
});
})
function parseGithubUrl(url) {
la(isGithubUrl(url), 'not a github url', url);
log('parsing github url', url);
function parseGithubUrl (url) {
la(isGithubUrl(url), 'not a github url', url)
log('parsing github url', url)
var githubUrlRegex = /github\.com[\/:]([a-zA-Z-]+?)\/([a-zA-Z-\.0-9]+?)(\.git)?$/;
var matches = githubUrlRegex.exec(url);
var githubUrlRegex = /github\.com[/:]([a-zA-Z-]+?)\/([a-zA-Z-.0-9]+?)(\.git)?$/
var matches = githubUrlRegex.exec(url)
la(check.array(matches),
'could not extract user and repo name from github url', url);
'could not extract user and repo name from github url', url)
return {
user: matches[1],
repo: matches[2]
};
}
}
function shortenSha(str) {
la(check.unemptyString(str), 'expected long commit sha string', str);
return str.substr(0, 7);
function shortenSha (str) {
la(check.unemptyString(str), 'expected long commit sha string', str)
return str.substr(0, 7)
}
function trimVersion(str) {
la(check.unemptyString(str), 'missig tag', str);
var startsWithV = /^v\d+/;
function trimVersion (str) {
la(check.unemptyString(str), 'missig tag', str)
var startsWithV = /^v\d+/
if (startsWithV.test(str)) {
return str.substr(1);
return str.substr(1)
}
return str;
return str
}
function firstLine(str) {
la(check.string(str), 'expected str', str);
str = str.trim();
var firstNewline = str.indexOf('\n');
function firstLine (str) {
la(check.string(str), 'expected str', str)
str = str.trim()
var firstNewline = str.indexOf('\n')
if (firstNewline !== -1) {
return str.substr(0, firstNewline);
return str.substr(0, firstNewline)
}
return str;
return str
}
// returns true if the package name is really github username/reponame
function isGithubName(str) {
function isGithubName (str) {
if (check.not.unemptyString(str)) {
return false;
return false
}
var parsed = parseGh(str);
return check.array(parsed);
var parsed = parseGh(str)
return check.array(parsed)
}
function parseGithubName(str) {
la(isGithubName(str), 'not a github name', str);
log('parsing github name', str);
var matches = parseGh(str);
function parseGithubName (str) {
la(isGithubName(str), 'not a github name', str)
log('parsing github name', str)
var matches = parseGh(str)
return {
user: matches[0],
repo: matches[1]
};
}
}

@@ -109,2 +109,2 @@

parseGithubName: parseGithubName
};
}
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