Skip to content

Commit 50db768

Browse files
authored
docs(nodejs_mono_repo): update broken links in README (#1577)
Makes sure file names do not contain `/workspace/google-cloud-node/`, since the post-processor runs from the root, but the link only needs the relative directory. Since this is a shared function, we need to make the changes in the node post-processing.
1 parent 7d86a9b commit 50db768

File tree

3 files changed

+108
-1
lines changed

3 files changed

+108
-1
lines changed

synthtool/languages/node_mono_repo.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,16 @@ def template_metadata(relative_dir: str) -> Dict[str, Any]:
116116
except FileNotFoundError:
117117
pass
118118

119-
all_samples = samples.all_samples([str(Path(relative_dir, "samples/*.js"))])
119+
all_samples = samples.all_samples(
120+
[
121+
str(Path(relative_dir, "samples/*.js")),
122+
str(Path(relative_dir, "samples/*/*.js")),
123+
str(Path(relative_dir, "samples/*/*/*.js")),
124+
]
125+
)
126+
127+
for sample in all_samples:
128+
sample["file"] = re.sub(r"/workspace/google-cloud-node/", "", sample["file"])
120129

121130
# quickstart.js sample is special - only include it in the samples list if there is
122131
# a quickstart snippet present in the file
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// ** This file is automatically generated by gapic-generator-typescript. **
16+
// ** https://github.com/googleapis/gapic-generator-typescript **
17+
// ** All changes to this file may be overwritten. **
18+
19+
20+
21+
'use strict';
22+
23+
function main(parent, backupId, backup) {
24+
// [START metastore_v1_generated_DataprocMetastore_CreateBackup_async]
25+
/**
26+
* TODO(developer): Uncomment these variables before running the sample.
27+
*/
28+
/**
29+
* Required. The relative resource name of the service in which to create a backup
30+
* of the following form:
31+
* `projects/{project_number}/locations/{location_id}/services/{service_id}`.
32+
*/
33+
// const parent = 'abc123'
34+
/**
35+
* Required. The ID of the backup, which is used as the final component of the
36+
* backup's name.
37+
* This value must be between 1 and 64 characters long, begin with a letter,
38+
* end with a letter or number, and consist of alpha-numeric ASCII characters
39+
* or hyphens.
40+
*/
41+
// const backupId = 'abc123'
42+
/**
43+
* Required. The backup to create. The `name` field is ignored. The ID of the created
44+
* backup must be provided in the request's `backup_id` field.
45+
*/
46+
// const backup = {}
47+
/**
48+
* Optional. A request ID. Specify a unique request ID to allow the server to ignore the
49+
* request if it has completed. The server will ignore subsequent requests
50+
* that provide a duplicate request ID for at least 60 minutes after the first
51+
* request.
52+
* For example, if an initial request times out, followed by another request
53+
* with the same request ID, the server ignores the second request to prevent
54+
* the creation of duplicate commitments.
55+
* The request ID must be a valid
56+
* UUID (https://en.wikipedia.org/wiki/Universally_unique_identifier#Format)
57+
* A zero UUID (00000000-0000-0000-0000-000000000000) is not supported.
58+
*/
59+
// const requestId = 'abc123'
60+
61+
// Imports the Metastore library
62+
const {DataprocMetastoreClient} = require('@google-cloud/dataproc-metastore').v1;
63+
64+
// Instantiates a client
65+
const metastoreClient = new DataprocMetastoreClient();
66+
67+
async function callCreateBackup() {
68+
// Construct request
69+
const request = {
70+
parent,
71+
backupId,
72+
backup,
73+
};
74+
75+
// Run request
76+
const [operation] = await metastoreClient.createBackup(request);
77+
const [response] = await operation.promise();
78+
console.log(response);
79+
}
80+
81+
callCreateBackup();
82+
// [END metastore_v1_generated_DataprocMetastore_CreateBackup_async]
83+
}
84+
85+
process.on('unhandledRejection', err => {
86+
console.error(err.message);
87+
process.exitCode = 1;
88+
});
89+
main(...process.argv.slice(2));

tests/test_node_mono_repo.py

+9
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ def test_no_samples():
8888
assert len(metadata["samples"]) == 0
8989

9090

91+
def test_fix_sample_path():
92+
with util.copied_fixtures_dir(FIXTURES):
93+
metadata = node_mono_repo.template_metadata(
94+
FIXTURES / "nodejs_mono_repo_with_samples" / "packages" / "datastore"
95+
)
96+
for sample in metadata["samples"]:
97+
assert "/workspace/google-cloud-node/" not in sample["file"]
98+
99+
91100
def test_extract_clients_no_file():
92101
index_ts_path = pathlib.Path(
93102
FIXTURES / "node_templates" / "index_samples" / "no_exist_index.ts"

0 commit comments

Comments
 (0)