From f512285abae03639a382769b6925a2406c5db6be Mon Sep 17 00:00:00 2001 From: jkrone Date: Thu, 18 Jan 2018 14:21:44 -0500 Subject: [PATCH 1/8] initial implementation of repo version reporting. Just learned that ipfs.version should report the repo version so I might implement it there. Still need the /repo/version http api, though. --- package.json | 1 + src/cli/commands/repo/version.js | 3 ++- src/cli/commands/version.js | 30 ++++++++++++++++++++++++------ src/http/api/resources/repo.js | 17 +++++++++++++++++ src/http/api/routes/index.js | 2 +- src/http/api/routes/repo.js | 4 ++-- 6 files changed, 47 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 52fa0192ff..785f5a9e05 100644 --- a/package.json +++ b/package.json @@ -113,6 +113,7 @@ "is-ipfs": "^0.3.2", "is-stream": "^1.1.0", "joi": "^13.0.2", + "leveldown": "^1.9.0", "libp2p": "~0.15.0", "libp2p-circuit": "~0.1.4", "libp2p-floodsub": "~0.13.1", diff --git a/src/cli/commands/repo/version.js b/src/cli/commands/repo/version.js index 462a571da2..0114c37204 100644 --- a/src/cli/commands/repo/version.js +++ b/src/cli/commands/repo/version.js @@ -10,11 +10,12 @@ module.exports = { builder: {}, handler (argv) { + console.log('cli/commands/repo/version:', argv.ipfs.repo, '\n') argv.ipfs.repo.version(function (err, version) { if (err) { throw err } - print(version) + print(version.version) }) } } diff --git a/src/cli/commands/version.js b/src/cli/commands/version.js index 6d9ecb45d4..1599e4bbe0 100644 --- a/src/cli/commands/version.js +++ b/src/cli/commands/version.js @@ -25,12 +25,30 @@ module.exports = { handler (argv) { // TODO: handle argv.{repo|commit|number} - argv.ipfs.version((err, version) => { - if (err) { - throw err - } + // cmdkit.BoolOption("number", "n", "Only show the version number.") + // cmdkit.BoolOption("commit", "Show the commit hash.") + // cmdkit.BoolOption("repo", "Show repo version.") + + // const ipfsModule = argv.repo ? argv.ipfs.repo : argv.ipfs. + if (argv.repo) { + argv.ipfs.repo.version(function (err, version) { + if (err) { + throw err + } + + print(`ipfs-repo version: ${version.version}`) + }) + } else { + argv.ipfs.version((err, version) => { + if (err) { + throw err + } + + console.log('verison:', version) + + print(`js-ipfs version: ${version.version}`) + }) + } - print(`js-ipfs version: ${version.version}`) - }) } } diff --git a/src/http/api/resources/repo.js b/src/http/api/resources/repo.js index ccacec309b..66c2bd70e3 100644 --- a/src/http/api/resources/repo.js +++ b/src/http/api/resources/repo.js @@ -1 +1,18 @@ 'use strict' + +const boom = require('boom') + +exports = module.exports + +exports.version = (request, reply) => { + const ipfs = request.server.app.ipfs + + ipfs.repo.version((err, version) => { + if (err) { + return reply(boom.badRequest(err)) + } + reply({ + version: version + }) + }) +} diff --git a/src/http/api/routes/index.js b/src/http/api/routes/index.js index 08756fc91c..258918518d 100644 --- a/src/http/api/routes/index.js +++ b/src/http/api/routes/index.js @@ -6,7 +6,7 @@ module.exports = (server) => { require('./bootstrap')(server) require('./block')(server) require('./object')(server) - // require('./repo')(server) + require('./repo')(server) require('./config')(server) require('./swarm')(server) require('./bitswap')(server) diff --git a/src/http/api/routes/repo.js b/src/http/api/routes/repo.js index f42f03bfc1..41df217b42 100644 --- a/src/http/api/routes/repo.js +++ b/src/http/api/routes/repo.js @@ -8,7 +8,7 @@ module.exports = (server) => { api.route({ method: '*', - path: '/api/v0/repo', - handler: resources.repo + path: '/api/v0/repo/version', + handler: resources.repo.version }) } From 11be5c2eaa366a200992bedb984b397a63c43657 Mon Sep 17 00:00:00 2001 From: jkrone Date: Thu, 18 Jan 2018 15:10:06 -0500 Subject: [PATCH 2/8] Refactor version to use ipfs.version, implement --number and --all flags, partial implementation of --commit (prints empty string for now). Not sure how to get the commit info, go-ipfs doesn't seem to implement it either. --- src/cli/commands/repo/version.js | 3 +- src/cli/commands/version.js | 55 ++++++++++++++++---------------- src/core/components/version.js | 15 ++++++--- src/http/api/resources/repo.js | 1 + 4 files changed, 40 insertions(+), 34 deletions(-) diff --git a/src/cli/commands/repo/version.js b/src/cli/commands/repo/version.js index 0114c37204..807abf02b3 100644 --- a/src/cli/commands/repo/version.js +++ b/src/cli/commands/repo/version.js @@ -10,8 +10,7 @@ module.exports = { builder: {}, handler (argv) { - console.log('cli/commands/repo/version:', argv.ipfs.repo, '\n') - argv.ipfs.repo.version(function (err, version) { + argv.ipfs.repo.version((err, version) => { if (err) { throw err } diff --git a/src/cli/commands/version.js b/src/cli/commands/version.js index 1599e4bbe0..8bfe2e8c46 100644 --- a/src/cli/commands/version.js +++ b/src/cli/commands/version.js @@ -11,44 +11,43 @@ module.exports = { number: { alias: 'n', type: 'boolean', - default: false + default: false, + describe: 'Print only the version number' }, commit: { type: 'boolean', - default: false + default: false, + describe: 'Include the version\'s commit hash' }, repo: { type: 'boolean', - default: false + default: false, + describe: 'Print only the repo\'s version number' + }, + all: { + type: 'boolean', + default: false, + describe: 'Print everything we have' } }, handler (argv) { - // TODO: handle argv.{repo|commit|number} - // cmdkit.BoolOption("number", "n", "Only show the version number.") - // cmdkit.BoolOption("commit", "Show the commit hash.") - // cmdkit.BoolOption("repo", "Show repo version.") - - // const ipfsModule = argv.repo ? argv.ipfs.repo : argv.ipfs. - if (argv.repo) { - argv.ipfs.repo.version(function (err, version) { - if (err) { - throw err - } - - print(`ipfs-repo version: ${version.version}`) - }) - } else { - argv.ipfs.version((err, version) => { - if (err) { - throw err - } - - console.log('verison:', version) - + argv.ipfs.version((err, version) => { + if (err) { + throw err + } + + if (argv.repo) { + // go-ipfs prints only the number, even without the --number flag. + print(version.repo) + } else if (argv.number) { + print(`${version.version}${argv.commit ? `-${version.commit}` : ''}`) + } else if (argv.all) { + print(`js-ipfs version: ${version.version}-${version.commit}`) + print(`Repo version: ${version.repo}`) + } else { print(`js-ipfs version: ${version.version}`) - }) - } - + } + }) } } diff --git a/src/core/components/version.js b/src/core/components/version.js index 1d1fcca9c5..77f590cc8a 100644 --- a/src/core/components/version.js +++ b/src/core/components/version.js @@ -10,10 +10,17 @@ module.exports = function version (self) { opts = {} } - callback(null, { - version: pkg.version, - repo: '', - commit: '' + self.repo.version((err, repoVersion) => { + if (err) { + throw err + } + + callback(null, { + version: pkg.version, + repo: repoVersion, + commit: '' + }) }) + }) } diff --git a/src/http/api/resources/repo.js b/src/http/api/resources/repo.js index 66c2bd70e3..dd57685f27 100644 --- a/src/http/api/resources/repo.js +++ b/src/http/api/resources/repo.js @@ -11,6 +11,7 @@ exports.version = (request, reply) => { if (err) { return reply(boom.badRequest(err)) } + reply({ version: version }) From af2bfede6f8b0c73f36af38d8fb5bd0fc3c4a6d3 Mon Sep 17 00:00:00 2001 From: jkrone Date: Thu, 18 Jan 2018 15:58:13 -0500 Subject: [PATCH 3/8] clean commands/version, write tests for version. --- src/cli/commands/version.js | 9 ++++++--- src/core/components/version.js | 1 + src/http/api/routes/repo.js | 1 - test/cli/version.js | 31 ++++++++++++++++++++++++++++++- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/cli/commands/version.js b/src/cli/commands/version.js index 8bfe2e8c46..d5893185bb 100644 --- a/src/cli/commands/version.js +++ b/src/cli/commands/version.js @@ -37,16 +37,19 @@ module.exports = { throw err } + const withCommit = argv.all || argv.commit + const parsedVersion = `${version.version}${withCommit ? `-${version.commit}` : ''}` + if (argv.repo) { // go-ipfs prints only the number, even without the --number flag. print(version.repo) } else if (argv.number) { - print(`${version.version}${argv.commit ? `-${version.commit}` : ''}`) + print(parsedVersion) } else if (argv.all) { - print(`js-ipfs version: ${version.version}-${version.commit}`) + print(`js-ipfs version: ${parsedVersion}`) print(`Repo version: ${version.repo}`) } else { - print(`js-ipfs version: ${version.version}`) + print(`js-ipfs version: ${parsedVersion}`) } }) } diff --git a/src/core/components/version.js b/src/core/components/version.js index 77f590cc8a..80d5145a10 100644 --- a/src/core/components/version.js +++ b/src/core/components/version.js @@ -3,6 +3,7 @@ const pkg = require('../../../package.json') const promisify = require('promisify-es6') +// TODO add the the commit hash of the current ipfs version to the response. module.exports = function version (self) { return promisify((opts, callback) => { if (typeof opts === 'function') { diff --git a/src/http/api/routes/repo.js b/src/http/api/routes/repo.js index 41df217b42..1410211a93 100644 --- a/src/http/api/routes/repo.js +++ b/src/http/api/routes/repo.js @@ -2,7 +2,6 @@ const resources = require('./../resources') -// TODO module.exports = (server) => { const api = server.select('API') diff --git a/test/cli/version.js b/test/cli/version.js index 44986adf77..3adeac9996 100644 --- a/test/cli/version.js +++ b/test/cli/version.js @@ -5,7 +5,7 @@ const expect = require('chai').expect const pkgversion = require('../../package.json').version const runOnAndOff = require('../utils/on-and-off') -describe('version', () => runOnAndOff((thing) => { +describe.only('version', () => runOnAndOff((thing) => { let ipfs before(() => { @@ -19,4 +19,33 @@ describe('version', () => runOnAndOff((thing) => { ) }) }) + + it('handles --number', () => { + return ipfs('version --number').then(out => + expect(out).to.eql(`${pkgversion}\n`) + ) + }) + + it('handles --commit', () => { + return ipfs('version --commit').then(out => + expect(out).to.eql(`js-ipfs version: ${pkgversion}-\n`) + ) + }) + + it('handles --all', () => { + // NOTE does not confirm repo version number + return ipfs('version --all').then(out => + expect(out).to.include( + `js-ipfs version: ${pkgversion}- +Repo version: ` + ) + ) + }) + + it('handles --repo', () => { + // TODO how can we get the repo version number to confirm test is correct? + return ipfs('version --repo').then(out => + expect(out).to.include('\n') // printed something + ) + }) })) From 6c3e521a81a5cdb1c9af85c3ed3d0a93373531bd Mon Sep 17 00:00:00 2001 From: jkrone Date: Mon, 22 Jan 2018 12:38:29 -0500 Subject: [PATCH 4/8] add test for . Just scaffolding, don't know how to get the correct version to validate the test. --- package.json | 1 - src/core/components/version.js | 1 - test/cli/repo.js | 19 +++++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 test/cli/repo.js diff --git a/package.json b/package.json index f00fd56e12..937b07c496 100644 --- a/package.json +++ b/package.json @@ -114,7 +114,6 @@ "is-ipfs": "^0.3.2", "is-stream": "^1.1.0", "joi": "^13.1.0", - "leveldown": "^1.9.0", "libp2p": "~0.15.0", "libp2p-circuit": "~0.1.4", "libp2p-floodsub": "~0.13.1", diff --git a/src/core/components/version.js b/src/core/components/version.js index a7e168a1b6..0f3fa2c1e1 100644 --- a/src/core/components/version.js +++ b/src/core/components/version.js @@ -22,6 +22,5 @@ module.exports = function version (self) { commit: '' }) }) - }) } diff --git a/test/cli/repo.js b/test/cli/repo.js new file mode 100644 index 0000000000..9fb0149e57 --- /dev/null +++ b/test/cli/repo.js @@ -0,0 +1,19 @@ +/* eslint-env mocha */ +'use strict' + +const expect = require('chai').expect +const runOnAndOff = require('../utils/on-and-off') + +describe('repo', () => runOnAndOff((thing) => { + let ipfs + + before(() => { + ipfs = thing.ipfs + }) + + it('get the repo version', () => { + return ipfs('repo version').then((out) => { + expect(out).to.include(`\n`) + }) + }) +})) From 84b5641f454b9bc8ffba5c67f03c7c95b10ab67c Mon Sep 17 00:00:00 2001 From: jkrone Date: Mon, 22 Jan 2018 13:33:03 -0500 Subject: [PATCH 5/8] Add tests for , found a bug, fixed it by flattening response of http api repo/version. --- src/cli/commands/repo/version.js | 4 ++-- src/http/api/resources/repo.js | 4 +--- test/cli/repo.js | 11 ++++++++++- test/cli/version.js | 20 ++++++++++++++------ 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/cli/commands/repo/version.js b/src/cli/commands/repo/version.js index ac16dd77f8..ca3491cf7a 100644 --- a/src/cli/commands/repo/version.js +++ b/src/cli/commands/repo/version.js @@ -10,11 +10,11 @@ module.exports = { builder: {}, handler (argv) { - argv.ipfs.repo.version((err, resp) => { + argv.ipfs.repo.version((err, version) => { if (err) { throw err } - print(resp.version) + print(version) }) } } diff --git a/src/http/api/resources/repo.js b/src/http/api/resources/repo.js index dd57685f27..9650b4141a 100644 --- a/src/http/api/resources/repo.js +++ b/src/http/api/resources/repo.js @@ -12,8 +12,6 @@ exports.version = (request, reply) => { return reply(boom.badRequest(err)) } - reply({ - version: version - }) + reply(version) }) } diff --git a/test/cli/repo.js b/test/cli/repo.js index 9fb0149e57..45a3f8447c 100644 --- a/test/cli/repo.js +++ b/test/cli/repo.js @@ -1,19 +1,28 @@ /* eslint-env mocha */ 'use strict' +const fs = require('fs') +const path = require('path') const expect = require('chai').expect const runOnAndOff = require('../utils/on-and-off') +function getRepoVersion(ipfs) { + const versionPath = path.join(ipfs.repoPath, 'version') + return String(fs.readFileSync(versionPath)) +} + describe('repo', () => runOnAndOff((thing) => { let ipfs + let repoVersion before(() => { ipfs = thing.ipfs + repoVersion = getRepoVersion(ipfs) }) it('get the repo version', () => { return ipfs('repo version').then((out) => { - expect(out).to.include(`\n`) + expect(out).to.eql(`${repoVersion}\n`) }) }) })) diff --git a/test/cli/version.js b/test/cli/version.js index e89b0bb573..1e57446736 100644 --- a/test/cli/version.js +++ b/test/cli/version.js @@ -1,15 +1,24 @@ /* eslint-env mocha */ 'use strict' +const fs = require('fs') +const path = require('path') const expect = require('chai').expect const pkgversion = require('../../package.json').version const runOnAndOff = require('../utils/on-and-off') +function getRepoVersion(ipfs) { + const versionPath = path.join(ipfs.repoPath, 'version') + return String(fs.readFileSync(versionPath)) +} + describe('version', () => runOnAndOff((thing) => { let ipfs + let repoVersion before(() => { ipfs = thing.ipfs + repoVersion = getRepoVersion(ipfs) }) it('get the version', () => { @@ -33,19 +42,18 @@ describe('version', () => runOnAndOff((thing) => { }) it('handles --all', () => { - // NOTE does not confirm repo version number return ipfs('version --all').then(out => expect(out).to.include( `js-ipfs version: ${pkgversion}- -Repo version: ` +Repo version: ${repoVersion} +` ) ) }) it('handles --repo', () => { - // TODO how can we get the repo version number to confirm test is correct? - return ipfs('version --repo').then(out => - expect(out).to.include('\n') // printed something - ) + return ipfs('version --repo').then(out => { + expect(out).to.eql(`${repoVersion}\n`) + }) }) })) From fc7b62367da0c72bd02f9c0b2194902dc92a95df Mon Sep 17 00:00:00 2001 From: jkrone Date: Wed, 24 Jan 2018 12:05:12 -0500 Subject: [PATCH 6/8] bump ipfs-api version, now has /repo/version route --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 937b07c496..527987e02b 100644 --- a/package.json +++ b/package.json @@ -102,7 +102,7 @@ "hapi": "^16.6.2", "hapi-set-header": "^1.0.2", "hoek": "^5.0.2", - "ipfs-api": "^17.3.0", + "ipfs-api": "^17.5.0", "ipfs-bitswap": "~0.18.0", "ipfs-block": "~0.6.1", "ipfs-block-service": "~0.13.0", From 67e2aab8224cbcb75d321a8ad55d3bd64f8764f4 Mon Sep 17 00:00:00 2001 From: jkrone Date: Wed, 24 Jan 2018 12:45:11 -0500 Subject: [PATCH 7/8] lint; clean --- test/cli/repo.js | 6 +++--- test/cli/version.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/cli/repo.js b/test/cli/repo.js index 45a3f8447c..cac0ec977e 100644 --- a/test/cli/repo.js +++ b/test/cli/repo.js @@ -6,8 +6,8 @@ const path = require('path') const expect = require('chai').expect const runOnAndOff = require('../utils/on-and-off') -function getRepoVersion(ipfs) { - const versionPath = path.join(ipfs.repoPath, 'version') +function getRepoVersion(repoPath) { + const versionPath = path.join(repoPath, 'version') return String(fs.readFileSync(versionPath)) } @@ -17,7 +17,7 @@ describe('repo', () => runOnAndOff((thing) => { before(() => { ipfs = thing.ipfs - repoVersion = getRepoVersion(ipfs) + repoVersion = getRepoVersion(ipfs.repoPath) }) it('get the repo version', () => { diff --git a/test/cli/version.js b/test/cli/version.js index 1e57446736..c4848a5761 100644 --- a/test/cli/version.js +++ b/test/cli/version.js @@ -7,8 +7,8 @@ const expect = require('chai').expect const pkgversion = require('../../package.json').version const runOnAndOff = require('../utils/on-and-off') -function getRepoVersion(ipfs) { - const versionPath = path.join(ipfs.repoPath, 'version') +function getRepoVersion(repoPath) { + const versionPath = path.join(repoPath, 'version') return String(fs.readFileSync(versionPath)) } @@ -18,7 +18,7 @@ describe('version', () => runOnAndOff((thing) => { before(() => { ipfs = thing.ipfs - repoVersion = getRepoVersion(ipfs) + repoVersion = getRepoVersion(ipfs.repoPath) }) it('get the version', () => { From 15ee937678a95b6f01c5d1f12d33f7f9b37bfa25 Mon Sep 17 00:00:00 2001 From: jkrone Date: Wed, 24 Jan 2018 15:43:52 -0500 Subject: [PATCH 8/8] whoops. clean again --- test/cli/repo.js | 2 +- test/cli/version.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cli/repo.js b/test/cli/repo.js index cac0ec977e..dd1e29533d 100644 --- a/test/cli/repo.js +++ b/test/cli/repo.js @@ -6,7 +6,7 @@ const path = require('path') const expect = require('chai').expect const runOnAndOff = require('../utils/on-and-off') -function getRepoVersion(repoPath) { +function getRepoVersion (repoPath) { const versionPath = path.join(repoPath, 'version') return String(fs.readFileSync(versionPath)) } diff --git a/test/cli/version.js b/test/cli/version.js index c4848a5761..ba86356088 100644 --- a/test/cli/version.js +++ b/test/cli/version.js @@ -7,7 +7,7 @@ const expect = require('chai').expect const pkgversion = require('../../package.json').version const runOnAndOff = require('../utils/on-and-off') -function getRepoVersion(repoPath) { +function getRepoVersion (repoPath) { const versionPath = path.join(repoPath, 'version') return String(fs.readFileSync(versionPath)) }