Merge branch 'main' into avm99963-monorail

Merged commit 34d8229ae2b51fb1a15bd208e6fe6185c94f6266

GitOrigin-RevId: 7ee0917f93a577e475f8e09526dd144d245593f4
diff --git a/api/v3/apps-script-client/IssueService.js b/api/v3/apps-script-client/IssueService.js
index d1c6c9d..4584dd0 100644
--- a/api/v3/apps-script-client/IssueService.js
+++ b/api/v3/apps-script-client/IssueService.js
@@ -1,4 +1,4 @@
-// Copyright 2020 The Chromium Authors. All rights reserved.
+// Copyright 2020 The Chromium Authors
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
diff --git a/api/v3/apps-script-client/ProjectService.js b/api/v3/apps-script-client/ProjectService.js
index 1487a53..d7f8f62 100644
--- a/api/v3/apps-script-client/ProjectService.js
+++ b/api/v3/apps-script-client/ProjectService.js
@@ -1,9 +1,11 @@
-// Copyright 2020 The Chromium Authors. All rights reserved.
+// Copyright 2020 The Chromium Authors
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
 /* eslint-disable no-unused-vars */
 
+const MAX_COMPONENT_PAGE_SIZE = 100;
+
 /**
  * Creates a ComponentDef.
  * @param {string} projectName The resource name of the parent project.
@@ -50,3 +52,31 @@
   const url = URL + 'monorail.v3.Projects/DeleteComponentDef';
   return run_(url, message);
 }
+
+/**
+ * Lists all ComponentDefs for a project. Automatically traverses through pages
+ * to get all components.
+ * @param {string=} projectName Resource name of the project to fetch components for.
+ * @param {string=} includeDeprecated Where to include deprecated components.
+ * @return {Array<ComponentDef>}
+ */
+function listComponentDefs(projectName = 'projects/chromium', includeDeprecated=false) {
+  const url = URL + 'monorail.v3.Projects/ListComponentDefs';
+  let components = [];
+
+  let response;
+  do {
+    const message = {
+      'parent': projectName,
+      'pageSize': MAX_COMPONENT_PAGE_SIZE,
+      'pageToken': response ? response.nextPageToken : undefined,
+    };
+    response = run_(url, message);
+    components = [...components, ...response.componentDefs];
+  } while (response.nextPageToken);
+
+  if (!includeDeprecated) {
+    components = components.filter((c) => c.state === 'ACTIVE');
+  }
+  return components;
+}
diff --git a/api/v3/apps-script-client/UserService.js b/api/v3/apps-script-client/UserService.js
index 6402db5..30611d8 100644
--- a/api/v3/apps-script-client/UserService.js
+++ b/api/v3/apps-script-client/UserService.js
@@ -1,4 +1,4 @@
-// Copyright 2020 The Chromium Authors. All rights reserved.
+// Copyright 2020 The Chromium Authors
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
diff --git a/api/v3/apps-script-client/helpers.js b/api/v3/apps-script-client/helpers.js
index 05ee920..84bd5bf 100644
--- a/api/v3/apps-script-client/helpers.js
+++ b/api/v3/apps-script-client/helpers.js
@@ -1,4 +1,4 @@
-// Copyright 2020 The Chromium Authors. All rights reserved.
+// Copyright 2020 The Chromium Authors
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
diff --git a/api/v3/apps-script-client/types.js b/api/v3/apps-script-client/types.js
index cafba21..3bb306e 100644
--- a/api/v3/apps-script-client/types.js
+++ b/api/v3/apps-script-client/types.js
@@ -1,4 +1,4 @@
-// Copyright 2020 The Chromium Authors. All rights reserved.
+// Copyright 2020 The Chromium Authors
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.