From 0990f91a18ffc8740bfb8f9a4f7b549010e15ea0 Mon Sep 17 00:00:00 2001 From: DPE bot Date: Wed, 8 Aug 2018 06:03:30 -0700 Subject: [PATCH] Re-generate library using /synth.py (#270) --- .circleci/config.yml | 17 ++++- .circleci/get_workflow_name.py | 67 ++++++++++++++++++++ src/v2/bigtable_client.js | 67 ++++++++++---------- test/gapic-v2.js | 109 +++++++-------------------------- 4 files changed, 138 insertions(+), 122 deletions(-) create mode 100644 .circleci/get_workflow_name.py diff --git a/.circleci/config.yml b/.circleci/config.yml index dd4c80cc6..cf867c5f0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -59,7 +59,18 @@ jobs: - image: 'node:6' user: node steps: &unit_tests_steps - - checkout + - checkout + - run: &remove_package_lock + name: Remove package-lock.json if needed. + command: | + WORKFLOW_NAME=`python .circleci/get_workflow_name.py` + echo "Workflow name: $WORKFLOW_NAME" + if [ "$WORKFLOW_NAME" = "nightly" ]; then + echo "Nightly build detected, removing package-lock.json." + rm -f package-lock.json samples/package-lock.json + else + echo "Not a nightly build, skipping this step." + fi - run: &npm_install_and_link name: Install and link the module command: |- @@ -86,6 +97,7 @@ jobs: user: node steps: - checkout + - run: *remove_package_lock - run: *npm_install_and_link - run: &samples_npm_install_and_link name: Link the module being tested to the samples. @@ -106,6 +118,7 @@ jobs: user: node steps: - checkout + - run: *remove_package_lock - run: *npm_install_and_link - run: name: Build documentation. @@ -116,6 +129,7 @@ jobs: user: node steps: - checkout + - run: *remove_package_lock - run: name: Decrypt credentials. command: | @@ -142,6 +156,7 @@ jobs: user: node steps: - checkout + - run: *remove_package_lock - run: name: Decrypt credentials. command: | diff --git a/.circleci/get_workflow_name.py b/.circleci/get_workflow_name.py new file mode 100644 index 000000000..ff6b58fd2 --- /dev/null +++ b/.circleci/get_workflow_name.py @@ -0,0 +1,67 @@ +# Copyright 2018 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Get workflow name for the current build using CircleCI API. +Would be great if this information is available in one of +CircleCI environment variables, but it's not there. +https://circleci.ideas.aha.io/ideas/CCI-I-295 +""" + +import json +import os +import sys +import urllib2 + + +def main(): + try: + username = os.environ['CIRCLE_PROJECT_USERNAME'] + reponame = os.environ['CIRCLE_PROJECT_REPONAME'] + build_num = os.environ['CIRCLE_BUILD_NUM'] + except: + sys.stderr.write( + 'Looks like we are not inside CircleCI container. Exiting...\n') + return 1 + + try: + request = urllib2.Request( + "https://circleci.com/api/v1.1/project/github/%s/%s/%s" % + (username, reponame, build_num), + headers={"Accept": "application/json"}) + contents = urllib2.urlopen(request).read() + except: + sys.stderr.write('Cannot query CircleCI API. Exiting...\n') + return 1 + + try: + build_info = json.loads(contents) + except: + sys.stderr.write( + 'Cannot parse JSON received from CircleCI API. Exiting...\n') + return 1 + + try: + workflow_name = build_info['workflows']['workflow_name'] + except: + sys.stderr.write( + 'Cannot get workflow name from CircleCI build info. Exiting...\n') + return 1 + + print workflow_name + return 0 + + +retval = main() +exit(retval) diff --git a/src/v2/bigtable_client.js b/src/v2/bigtable_client.js index cc3d80e02..79fde2c12 100644 --- a/src/v2/bigtable_client.js +++ b/src/v2/bigtable_client.js @@ -251,11 +251,10 @@ class BigtableClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - table_name: request.tableName, - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + 'table_name': request.tableName + }); return this._innerApiCalls.readRows(request, options); } @@ -298,11 +297,10 @@ class BigtableClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - table_name: request.tableName, - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + 'table_name': request.tableName + }); return this._innerApiCalls.sampleRowKeys(request, options); } @@ -372,11 +370,10 @@ class BigtableClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - table_name: request.tableName, - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + 'table_name': request.tableName + }); return this._innerApiCalls.mutateRow(request, options, callback); } @@ -429,11 +426,10 @@ class BigtableClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - table_name: request.tableName, - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + 'table_name': request.tableName + }); return this._innerApiCalls.mutateRows(request, options); } @@ -518,11 +514,10 @@ class BigtableClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - table_name: request.tableName, - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + 'table_name': request.tableName + }); return this._innerApiCalls.checkAndMutateRow(request, options, callback); } @@ -596,11 +591,10 @@ class BigtableClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - table_name: request.tableName, - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + 'table_name': request.tableName + }); return this._innerApiCalls.readModifyWriteRow(request, options, callback); } @@ -633,7 +627,9 @@ class BigtableClient { * @returns {String} - A string representing the project. */ matchProjectFromTableName(tableName) { - return this._pathTemplates.tablePathTemplate.match(tableName).project; + return this._pathTemplates.tablePathTemplate + .match(tableName) + .project; } /** @@ -644,7 +640,9 @@ class BigtableClient { * @returns {String} - A string representing the instance. */ matchInstanceFromTableName(tableName) { - return this._pathTemplates.tablePathTemplate.match(tableName).instance; + return this._pathTemplates.tablePathTemplate + .match(tableName) + .instance; } /** @@ -655,8 +653,11 @@ class BigtableClient { * @returns {String} - A string representing the table. */ matchTableFromTableName(tableName) { - return this._pathTemplates.tablePathTemplate.match(tableName).table; + return this._pathTemplates.tablePathTemplate + .match(tableName) + .table; } } + module.exports = BigtableClient; diff --git a/test/gapic-v2.js b/test/gapic-v2.js index cab1dbbd7..186c52ba5 100644 --- a/test/gapic-v2.js +++ b/test/gapic-v2.js @@ -32,11 +32,7 @@ describe('BigtableClient', () => { }); // Mock request - var formattedTableName = client.tablePath( - '[PROJECT]', - '[INSTANCE]', - '[TABLE]' - ); + var formattedTableName = client.tablePath('[PROJECT]', '[INSTANCE]', '[TABLE]'); var request = { tableName: formattedTableName, }; @@ -48,10 +44,7 @@ describe('BigtableClient', () => { }; // Mock Grpc layer - client._innerApiCalls.readRows = mockServerStreamingGrpcMethod( - request, - expectedResponse - ); + client._innerApiCalls.readRows = mockServerStreamingGrpcMethod(request, expectedResponse); var stream = client.readRows(request); stream.on('data', response => { @@ -72,21 +65,13 @@ describe('BigtableClient', () => { }); // Mock request - var formattedTableName = client.tablePath( - '[PROJECT]', - '[INSTANCE]', - '[TABLE]' - ); + var formattedTableName = client.tablePath('[PROJECT]', '[INSTANCE]', '[TABLE]'); var request = { tableName: formattedTableName, }; // Mock Grpc layer - client._innerApiCalls.readRows = mockServerStreamingGrpcMethod( - request, - null, - error - ); + client._innerApiCalls.readRows = mockServerStreamingGrpcMethod(request, null, error); var stream = client.readRows(request); stream.on('data', () => { @@ -110,11 +95,7 @@ describe('BigtableClient', () => { }); // Mock request - var formattedTableName = client.tablePath( - '[PROJECT]', - '[INSTANCE]', - '[TABLE]' - ); + var formattedTableName = client.tablePath('[PROJECT]', '[INSTANCE]', '[TABLE]'); var request = { tableName: formattedTableName, }; @@ -128,10 +109,7 @@ describe('BigtableClient', () => { }; // Mock Grpc layer - client._innerApiCalls.sampleRowKeys = mockServerStreamingGrpcMethod( - request, - expectedResponse - ); + client._innerApiCalls.sampleRowKeys = mockServerStreamingGrpcMethod(request, expectedResponse); var stream = client.sampleRowKeys(request); stream.on('data', response => { @@ -152,21 +130,13 @@ describe('BigtableClient', () => { }); // Mock request - var formattedTableName = client.tablePath( - '[PROJECT]', - '[INSTANCE]', - '[TABLE]' - ); + var formattedTableName = client.tablePath('[PROJECT]', '[INSTANCE]', '[TABLE]'); var request = { tableName: formattedTableName, }; // Mock Grpc layer - client._innerApiCalls.sampleRowKeys = mockServerStreamingGrpcMethod( - request, - null, - error - ); + client._innerApiCalls.sampleRowKeys = mockServerStreamingGrpcMethod(request, null, error); var stream = client.sampleRowKeys(request); stream.on('data', () => { @@ -190,11 +160,7 @@ describe('BigtableClient', () => { }); // Mock request - var formattedTableName = client.tablePath( - '[PROJECT]', - '[INSTANCE]', - '[TABLE]' - ); + var formattedTableName = client.tablePath('[PROJECT]', '[INSTANCE]', '[TABLE]'); var rowKey = '122'; var mutations = []; var request = { @@ -226,11 +192,7 @@ describe('BigtableClient', () => { }); // Mock request - var formattedTableName = client.tablePath( - '[PROJECT]', - '[INSTANCE]', - '[TABLE]' - ); + var formattedTableName = client.tablePath('[PROJECT]', '[INSTANCE]', '[TABLE]'); var rowKey = '122'; var mutations = []; var request = { @@ -263,11 +225,7 @@ describe('BigtableClient', () => { }); // Mock request - var formattedTableName = client.tablePath( - '[PROJECT]', - '[INSTANCE]', - '[TABLE]' - ); + var formattedTableName = client.tablePath('[PROJECT]', '[INSTANCE]', '[TABLE]'); var entries = []; var request = { tableName: formattedTableName, @@ -278,10 +236,7 @@ describe('BigtableClient', () => { var expectedResponse = {}; // Mock Grpc layer - client._innerApiCalls.mutateRows = mockServerStreamingGrpcMethod( - request, - expectedResponse - ); + client._innerApiCalls.mutateRows = mockServerStreamingGrpcMethod(request, expectedResponse); var stream = client.mutateRows(request); stream.on('data', response => { @@ -302,11 +257,7 @@ describe('BigtableClient', () => { }); // Mock request - var formattedTableName = client.tablePath( - '[PROJECT]', - '[INSTANCE]', - '[TABLE]' - ); + var formattedTableName = client.tablePath('[PROJECT]', '[INSTANCE]', '[TABLE]'); var entries = []; var request = { tableName: formattedTableName, @@ -314,11 +265,7 @@ describe('BigtableClient', () => { }; // Mock Grpc layer - client._innerApiCalls.mutateRows = mockServerStreamingGrpcMethod( - request, - null, - error - ); + client._innerApiCalls.mutateRows = mockServerStreamingGrpcMethod(request, null, error); var stream = client.mutateRows(request); stream.on('data', () => { @@ -342,11 +289,7 @@ describe('BigtableClient', () => { }); // Mock request - var formattedTableName = client.tablePath( - '[PROJECT]', - '[INSTANCE]', - '[TABLE]' - ); + var formattedTableName = client.tablePath('[PROJECT]', '[INSTANCE]', '[TABLE]'); var rowKey = '122'; var request = { tableName: formattedTableName, @@ -379,11 +322,7 @@ describe('BigtableClient', () => { }); // Mock request - var formattedTableName = client.tablePath( - '[PROJECT]', - '[INSTANCE]', - '[TABLE]' - ); + var formattedTableName = client.tablePath('[PROJECT]', '[INSTANCE]', '[TABLE]'); var rowKey = '122'; var request = { tableName: formattedTableName, @@ -414,11 +353,7 @@ describe('BigtableClient', () => { }); // Mock request - var formattedTableName = client.tablePath( - '[PROJECT]', - '[INSTANCE]', - '[TABLE]' - ); + var formattedTableName = client.tablePath('[PROJECT]', '[INSTANCE]', '[TABLE]'); var rowKey = '122'; var rules = []; var request = { @@ -450,11 +385,7 @@ describe('BigtableClient', () => { }); // Mock request - var formattedTableName = client.tablePath( - '[PROJECT]', - '[INSTANCE]', - '[TABLE]' - ); + var formattedTableName = client.tablePath('[PROJECT]', '[INSTANCE]', '[TABLE]'); var rowKey = '122'; var rules = []; var request = { @@ -478,6 +409,7 @@ describe('BigtableClient', () => { }); }); }); + }); function mockSimpleGrpcMethod(expectedRequest, response, error) { @@ -499,7 +431,8 @@ function mockServerStreamingGrpcMethod(expectedRequest, response, error) { var mockStream = through2.obj((chunk, enc, callback) => { if (error) { callback(error); - } else { + } + else { callback(null, response); } });