From 1b00b643f1d4f8a11a719c3f8f529d5626b25552 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Tue, 24 Apr 2018 14:02:09 -0700 Subject: [PATCH 1/8] Fix link to documentation I think this was broken by https://github.com/pelias/documentation/pull/219 and the rename of pelias/pelias-doc to pelias/documentation --- public/apiDoc.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/apiDoc.md b/public/apiDoc.md index 4e3ce186..e0026593 100644 --- a/public/apiDoc.md +++ b/public/apiDoc.md @@ -1 +1 @@ -## [View our documentation on GitHub](https://github.com/pelias/pelias-doc/blob/master/index.md) +## [View our documentation on GitHub](https://github.com/pelias/documentation/) From a0aa5ed7f24cd512ebd395d45955b56875b680dc Mon Sep 17 00:00:00 2001 From: semhul Date: Fri, 27 Apr 2018 14:30:09 +0200 Subject: [PATCH 2/8] Adding support for unit field in structured search. If libpostal finds it in input use it for searching --- controller/structured_libpostal.js | 33 ++++++++----- test/unit/controller/structured_libpostal.js | 49 ++++++++++++++++++++ 2 files changed, 71 insertions(+), 11 deletions(-) diff --git a/controller/structured_libpostal.js b/controller/structured_libpostal.js index 626bf945..f9362471 100644 --- a/controller/structured_libpostal.js +++ b/controller/structured_libpostal.js @@ -3,19 +3,20 @@ const Debug = require('../helper/debug'); const debugLog = new Debug('controller:libpostal'); const logger = require('pelias-logger').get('api'); -// if there's a house_number in the libpostal response, return it -// otherwise return the postcode field (which may be undefined) -function findHouseNumberField(response) { - const house_number_field = response.find(f => f.label === 'house_number'); - - if (house_number_field) { - return house_number_field; +// Find field in libpostal response +function findField(response, field, replacementField) { + const libpostalField = response.find(f => f.label === field); + + if (libpostalField) { + return libpostalField; + } else if(replacementField) { + return response.find(f => f.label === replacementField); + } else { + return; } - - return response.find(f => f.label === 'postcode'); - } + function setup(libpostalService, should_execute) { function controller( req, res, next ){ // bail early if req/res don't pass conditions for execution @@ -35,7 +36,9 @@ function setup(libpostalService, should_execute) { // libpostal parses some inputs, like `3370 cobbe ave`, as a postcode+street // so because we're treating the entire field as a street address, it's safe // to assume that an identified postcode is actually a house number. - const house_number_field = findHouseNumberField(response); + // if there's a house_number in the libpostal response, return it + // otherwise return the postcode field (which may be undefined) + const house_number_field = findField(response, 'house_number', 'postcode'); // if we're fairly certain that libpostal identified a house number // (from either the house_number or postcode field), place it into the @@ -48,6 +51,14 @@ function setup(libpostalService, should_execute) { // remove the first instance of the number and trim whitespace req.clean.parsed_text.street = _.trim(_.replace(req.clean.parsed_text.address, req.clean.parsed_text.number, '')); + // If libpostal have parsed unit then add it for search + const unit_field = findField(response, 'unit'); + if(unit_field) { + req.clean.parsed_text.unit = unit_field.value; + // Removing unit from street and trim + req.clean.parsed_text.street = _.trim(_.replace(req.clean.parsed_text.street, req.clean.parsed_text.unit, '')); + } + } else { // otherwise no house number was identifiable, so treat the entire input // as a street diff --git a/test/unit/controller/structured_libpostal.js b/test/unit/controller/structured_libpostal.js index 142d8260..16660459 100644 --- a/test/unit/controller/structured_libpostal.js +++ b/test/unit/controller/structured_libpostal.js @@ -291,6 +291,55 @@ module.exports.tests.success_conditions = (test, common) => { }); + test('service returning house_number and unit should set req.clean.parsed_text.unit', t => { + const service = (req, callback) => { + const response = [ + { + label: 'road', + value: 'the street' + }, + { + label: 'house_number', + value: '22' + }, + { + label: 'unit', + value: '1 th' + } + ]; + + callback(null, response); + }; + + const controller = libpostal(service, () => true); + + const req = { + clean: { + parsed_text: { + address: 'the street 22 1 th' + } + }, + errors: [] + }; + + controller(req, undefined, () => { + t.deepEquals(req, { + clean: { + parsed_text: { + street: 'the street', + number: '22', + unit: '1 th' + } + }, + errors: [] + }, 'req should have been modified'); + + t.end(); + + }); + + }); + // test('service returning valid response should convert and append', t => { // const service = (req, callback) => { // const response = [ From 37430d5daba3a2b5cf6c9a830df6dc6e744e99cc Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Fri, 11 May 2018 14:21:24 -0400 Subject: [PATCH 3/8] Run semantic-relase on the production branch This change will make semantic-release run only on the `production` branch. This means only merges to production will create new NPM packages, GitHub releases, git tags, and `:latest` Docker images on Docker hub. Connects https://github.com/pelias/pelias/issues/721 --- package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 50f7d81f..1b8081e4 100644 --- a/package.json +++ b/package.json @@ -90,5 +90,8 @@ "validate", "test", "check-dependencies" - ] + ], + "release": { + "branch": "production" + } } From b829fc1a2038bd52efd0b7d2a6fbecef4d275777 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Wed, 25 Apr 2018 21:09:56 -0400 Subject: [PATCH 4/8] feat: Add Node.js 10 to TravisCI Connects https://github.com/pelias/pelias/issues/723 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index f91c3dfc..02cecfe8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ notifications: node_js: - 6 - 8 + - 10 matrix: fast_finish: true script: npm run travis From 06f7099598ccc8e124a69f1c27aaf219da789e58 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Fri, 11 May 2018 15:11:51 -0400 Subject: [PATCH 5/8] Fix semantic release run --- .travis.yml | 2 +- package.json | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 02cecfe8..52a610d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ before_install: before_script: - npm prune after_success: - - npm run semantic-release + - npx semantic-release branches: except: - /^v\d+\.\d+\.\d+$/ diff --git a/package.json b/package.json index 1b8081e4..a7759a27 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,6 @@ "travis": "npm run check-dependencies && npm test", "unit": "./bin/units", "validate": "npm ls", - "semantic-release": "semantic-release pre && npm publish && semantic-release post", "config": "node -e \"console.log(JSON.stringify(require( 'pelias-config' ).generate(require('./schema')), null, 2))\"", "check-dependencies": "node_modules/.bin/npm-check --production --ignore pelias-interpolation", "prune": "npm prune" From 01ca6e6c65d62f66ee3003a68a6df57f0bdd6f31 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Fri, 11 May 2018 19:26:30 -0400 Subject: [PATCH 6/8] Remove npm-check --- package.json | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index a7759a27..ffa18966 100644 --- a/package.json +++ b/package.json @@ -14,11 +14,10 @@ "lint": "jshint .", "start": "./bin/start", "test": "npm run unit", - "travis": "npm run check-dependencies && npm test", + "travis": "npm test", "unit": "./bin/units", "validate": "npm ls", "config": "node -e \"console.log(JSON.stringify(require( 'pelias-config' ).generate(require('./schema')), null, 2))\"", - "check-dependencies": "node_modules/.bin/npm-check --production --ignore pelias-interpolation", "prune": "npm prune" }, "repository": { @@ -71,7 +70,6 @@ "difflet": "^1.0.1", "istanbul": "^0.4.2", "jshint": "^2.5.6", - "npm-check": "git://github.com/orangejulius/npm-check.git#disable-update-check", "nsp": "^3.0.0", "pelias-mock-logger": "1.2.0", "precommit-hook": "^3.0.0", @@ -87,8 +85,7 @@ "lint", "prune", "validate", - "test", - "check-dependencies" + "test" ], "release": { "branch": "production" From e5afa25b5ea6b7a3645b643e2368a791a68745f8 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Fri, 11 May 2018 19:28:28 -0400 Subject: [PATCH 7/8] Skip npm prune on Travis Travis always installs fresh, so this should never be needed --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 52a610d1..5aec4536 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,8 +11,6 @@ matrix: script: npm run travis before_install: - npm i -g npm -before_script: - - npm prune after_success: - npx semantic-release branches: From 27385da8ddd551b6e571d660f5fdc5b06c2beb46 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Fri, 11 May 2018 19:40:09 -0400 Subject: [PATCH 8/8] Change default NPM package name --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ffa18966..34af521a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pelias-api", - "version": "0.0.0-semantic-release", + "version": "0.0.0-development", "author": "pelias", "description": "Pelias API", "homepage": "https://github.com/pelias/api",