Merge branch 'main' into avm99963-monorail
Merged commit 34d8229ae2b51fb1a15bd208e6fe6185c94f6266
GitOrigin-RevId: 7ee0917f93a577e475f8e09526dd144d245593f4
diff --git a/static_src/shared/helpers.js b/static_src/shared/helpers.js
index 362b4ec..968d05e 100644
--- a/static_src/shared/helpers.js
+++ b/static_src/shared/helpers.js
@@ -1,4 +1,4 @@
-// Copyright 2019 The Chromium Authors. All rights reserved.
+// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -211,3 +211,29 @@
export const shouldWaitForDefaultQuery = (queryParams) => {
return !queryParams.hasOwnProperty('q');
};
+
+// constant value for required redirect project
+const redirectProjects = Object.freeze(['pigweed', 'git', 'gerrit', 'skia', 'fuchsia']);
+
+/**
+ * Generate the url link for issue in project.
+ * @param {string} projectName Name of the project.
+ * @param {string} subUrl the sub URL without query params.
+ * @param {Object} params the query params.
+ * @return {string} the new URL
+ */
+export function generateProjectIssueURL(projectName, subPath, params = {}) {
+ const queryString = window.location.search;
+ const urlParams = new URLSearchParams(queryString);
+ const noRedirect = urlParams.has('no_tracker_redirect');
+ let baseUrl = '';
+ if (!noRedirect && redirectProjects.includes(projectName)) {
+ // Full url path will trigger backend service call to handle redirect.
+ baseUrl = 'https://bugs.chromium.org/p/' + projectName + '/issues' + subPath;
+ return urlWithNewParams(baseUrl, params, {}, undefined)
+ } else {
+ baseUrl = '/p/' + projectName + '/issues' + subPath;
+ const noRedirectParam = noRedirect ? {'no_tracker_redirect' : 1} : undefined
+ return urlWithNewParams(baseUrl, params, noRedirectParam, undefined)
+ }
+}
\ No newline at end of file