blob: 84bd5bfaf5a40fe3bb1e8e85ce31600dc50a271d [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001// Copyright 2020 The Chromium Authors
Copybara854996b2021-09-07 19:36:02 +00002// 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 */
12function 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 */
21function 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 */
37function 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 */
46function 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 */
56function 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 */
70function 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*/
80function computeComponentDefName(project, componentIdOrPath) {
81 return `projects/${project}/componentDefs/${componentIdOrPath}`;
82}