Adrià Vilanova MartÃnez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | /* eslint-disable no-unused-vars */ |
| 6 | |
| 7 | /** |
| 8 | * Returns the user's resource name. |
| 9 | * @param {string|number} user The user's email or user_id |
| 10 | * @return {string} |
| 11 | */ |
| 12 | function computeUserName(user) { |
| 13 | return `users/${user}`; |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * Returns the users' resource names. |
| 18 | * @param {Array<string|number>} users Array of user emails/user_ids. |
| 19 | * @return {Array<string>} |
| 20 | */ |
| 21 | function computeUserNames(users) { |
| 22 | const userNames = []; |
| 23 | users.forEach((user) => { |
| 24 | userNames.push(computeUserName(user)); |
| 25 | }); |
| 26 | return userNames; |
| 27 | } |
| 28 | |
| 29 | |
| 30 | /** |
| 31 | * Returns the issue's resource name. |
| 32 | * @param {string} project The name of the project the issue belongs to, |
| 33 | * e.g. 'chromium'. |
| 34 | * @param {number} id The issue's id. |
| 35 | * @return {string} |
| 36 | */ |
| 37 | function computeIssueName(project, id) { |
| 38 | return `projects/${project}/issues/${id}`; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Returns the project's resource name. |
| 43 | * @param {string} project The display name of the project, e.g. 'chromium'. |
| 44 | * @return {string} |
| 45 | */ |
| 46 | function computeProjectName(project) { |
| 47 | return `projects/${project}`; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Returns the projects' resource names in the same order. |
| 52 | * @param {Array<string>} projects The display names of the projects, |
| 53 | * e.g. 'chromium'. |
| 54 | * @return {Array<string>} |
| 55 | */ |
| 56 | function computeProjectNames(projects) { |
| 57 | const projectNames = []; |
| 58 | projects.forEach((project) => { |
| 59 | projectNames.push(computeProjectName(project)); |
| 60 | }); |
| 61 | return projectNames; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Returns the FieldDef's resource name. |
| 66 | * @param {string} project The display name of the project, e.g. 'chromium'. |
| 67 | * @param {number} fieldId ID of the FieldDef. |
| 68 | * @return {string} |
| 69 | */ |
| 70 | function computeFieldDefName(project, fieldId) { |
| 71 | return `projects/${project}/fieldDefs/${fieldId}`; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Returns the ComponentDef's resource name. |
| 76 | * @param {string} project The display name of the project, e.g. 'chromium'. |
| 77 | * @param {number|string} componentIdOrPath ID or value of the ComponentDef. |
| 78 | * @return {string} |
| 79 | */ |
| 80 | function computeComponentDefName(project, componentIdOrPath) { |
| 81 | return `projects/${project}/componentDefs/${componentIdOrPath}`; |
| 82 | } |