Merge branch 'main' into avm99963-monorail

Merged commit 34d8229ae2b51fb1a15bd208e6fe6185c94f6266

GitOrigin-RevId: 7ee0917f93a577e475f8e09526dd144d245593f4
diff --git a/static_src/shared/consts/approval.js b/static_src/shared/consts/approval.js
index 772025d..73db792 100644
--- a/static_src/shared/consts/approval.js
+++ b/static_src/shared/consts/approval.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.
 
diff --git a/static_src/shared/consts/index.js b/static_src/shared/consts/index.js
index bb196b3..f296dc6 100644
--- a/static_src/shared/consts/index.js
+++ b/static_src/shared/consts/index.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.
 export const SERVER_LIST_ISSUES_LIMIT = 100000;
diff --git a/static_src/shared/consts/permissions.js b/static_src/shared/consts/permissions.js
index 8c8ef1b..71677b6 100644
--- a/static_src/shared/consts/permissions.js
+++ b/static_src/shared/consts/permissions.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.
 
diff --git a/static_src/shared/converters.js b/static_src/shared/converters.js
index 308df2d..758eb17 100644
--- a/static_src/shared/converters.js
+++ b/static_src/shared/converters.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.
 // Based on: https://source.chromium.org/chromium/infra/infra/+/main:appengine/monorail/project/project_constants.py;l=13
diff --git a/static_src/shared/converters.test.js b/static_src/shared/converters.test.js
index 428a74d..8700a99 100644
--- a/static_src/shared/converters.test.js
+++ b/static_src/shared/converters.test.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/static_src/shared/convertersV0.js b/static_src/shared/convertersV0.js
index ffb8a36..5a50d8a 100644
--- a/static_src/shared/convertersV0.js
+++ b/static_src/shared/convertersV0.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.
 
@@ -14,7 +14,7 @@
 
 import qs from 'qs';
 
-import {equalsIgnoreCase, capitalizeFirst} from './helpers.js';
+import {equalsIgnoreCase, capitalizeFirst, generateProjectIssueURL} from './helpers.js';
 import {fromShortlink} from 'shared/federated.js';
 import {UserInputError} from 'shared/errors.js';
 import './typedef.js';
@@ -522,14 +522,11 @@
     return extRef.toURL();
   }
 
-  let paramString = '';
   if (Object.keys(queryParamsCopy).length) {
     delete queryParamsCopy.id;
-
-    paramString = `&${qs.stringify(queryParamsCopy)}`;
   }
-
-  return `/p/${ref.projectName}/issues/detail?id=${ref.localId}${paramString}`;
+  const params = {'id': ref.localId, ...queryParamsCopy};
+  return generateProjectIssueURL(ref.projectName, '/detail', params);
 }
 
 /**
diff --git a/static_src/shared/convertersV0.test.js b/static_src/shared/convertersV0.test.js
index 2e34622..cf20b59 100644
--- a/static_src/shared/convertersV0.test.js
+++ b/static_src/shared/convertersV0.test.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.
 
diff --git a/static_src/shared/cron.js b/static_src/shared/cron.js
index bd67507..dec83ab 100644
--- a/static_src/shared/cron.js
+++ b/static_src/shared/cron.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.
 
diff --git a/static_src/shared/cron.test.js b/static_src/shared/cron.test.js
index e2f9a8e..85d07c6 100644
--- a/static_src/shared/cron.test.js
+++ b/static_src/shared/cron.test.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.
 
diff --git a/static_src/shared/dom-helpers.js b/static_src/shared/dom-helpers.js
index 81dec80..545ffa2 100644
--- a/static_src/shared/dom-helpers.js
+++ b/static_src/shared/dom-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.
 
diff --git a/static_src/shared/dom-helpers.test.js b/static_src/shared/dom-helpers.test.js
index 78d535a..e500ceb 100644
--- a/static_src/shared/dom-helpers.test.js
+++ b/static_src/shared/dom-helpers.test.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.
 
diff --git a/static_src/shared/errors.js b/static_src/shared/errors.js
index 81c0035..4b4a7a8 100644
--- a/static_src/shared/errors.js
+++ b/static_src/shared/errors.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.
 
diff --git a/static_src/shared/experiments.js b/static_src/shared/experiments.js
index 1528a00..50934e6 100644
--- a/static_src/shared/experiments.js
+++ b/static_src/shared/experiments.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/static_src/shared/experiments.test.js b/static_src/shared/experiments.test.js
index d5f96b7..929060d 100644
--- a/static_src/shared/experiments.test.js
+++ b/static_src/shared/experiments.test.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/static_src/shared/federated.js b/static_src/shared/federated.js
index e5b7567..7b4af3c 100644
--- a/static_src/shared/federated.js
+++ b/static_src/shared/federated.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.
 
diff --git a/static_src/shared/federated.test.js b/static_src/shared/federated.test.js
index 011b924..95da053 100644
--- a/static_src/shared/federated.test.js
+++ b/static_src/shared/federated.test.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.
 
diff --git a/static_src/shared/ga-helpers.js b/static_src/shared/ga-helpers.js
index 52d1176..7dc1c44 100644
--- a/static_src/shared/ga-helpers.js
+++ b/static_src/shared/ga-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.
 
diff --git a/static_src/shared/ga-helpers.test.js b/static_src/shared/ga-helpers.test.js
index 1876a27..e12c9e1 100644
--- a/static_src/shared/ga-helpers.test.js
+++ b/static_src/shared/ga-helpers.test.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.
 
diff --git a/static_src/shared/gapi-loader.js b/static_src/shared/gapi-loader.js
index 5249d68..7a93b6d 100644
--- a/static_src/shared/gapi-loader.js
+++ b/static_src/shared/gapi-loader.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.
 
diff --git a/static_src/shared/gapi-loader.test.js b/static_src/shared/gapi-loader.test.js
index d385861..481c026 100644
--- a/static_src/shared/gapi-loader.test.js
+++ b/static_src/shared/gapi-loader.test.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.
 
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
diff --git a/static_src/shared/helpers.test.js b/static_src/shared/helpers.test.js
index 7c40ed5..e05a9a2 100644
--- a/static_src/shared/helpers.test.js
+++ b/static_src/shared/helpers.test.js
@@ -1,12 +1,11 @@
-// 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.
 
 import {assert} from 'chai';
 import {arrayDifference, setHasAny, capitalizeFirst, hasPrefix, objectToMap,
   objectValuesForKeys, equalsIgnoreCase, immutableSplice, userIsMember,
-  urlWithNewParams, createObjectComparisonFunc} from './helpers.js';
-
+  urlWithNewParams, createObjectComparisonFunc, generateProjectIssueURL} from './helpers.js';
 
 describe('arrayDifference', () => {
   it('empty array stays empty', () => {
@@ -359,3 +358,15 @@
     });
   });
 });
+
+describe('generateProjectIssueURL', () => {
+  it('no redirect required and no param', () => {
+    assert.equal(generateProjectIssueURL('project', '/list'), '/p/project/issues/list');
+  });
+
+  it('no redirect required and with param', () => {
+    assert.equal(generateProjectIssueURL('project', '/detail', {'id': 123}), '/p/project/issues/detail?id=123');
+  });
+
+  //TODO(crbug.com/monorail/12029): add more unit test.
+});
\ No newline at end of file
diff --git a/static_src/shared/issue-fields.js b/static_src/shared/issue-fields.js
index 0acbe60..09322e8 100644
--- a/static_src/shared/issue-fields.js
+++ b/static_src/shared/issue-fields.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.
 
diff --git a/static_src/shared/issue-fields.test.js b/static_src/shared/issue-fields.test.js
index c37faa9..091f7c8 100644
--- a/static_src/shared/issue-fields.test.js
+++ b/static_src/shared/issue-fields.test.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.
 
diff --git a/static_src/shared/math.js b/static_src/shared/math.js
index 36e2d75..2208997 100644
--- a/static_src/shared/math.js
+++ b/static_src/shared/math.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.
 
diff --git a/static_src/shared/math.test.js b/static_src/shared/math.test.js
index 4b4c153..88e1df0 100644
--- a/static_src/shared/math.test.js
+++ b/static_src/shared/math.test.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.
 
diff --git a/static_src/shared/metadata-helpers.js b/static_src/shared/metadata-helpers.js
index 5735557..ae20919 100644
--- a/static_src/shared/metadata-helpers.js
+++ b/static_src/shared/metadata-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.
 
diff --git a/static_src/shared/metadata-helpers.test.js b/static_src/shared/metadata-helpers.test.js
index fd04806..55f8c59 100644
--- a/static_src/shared/metadata-helpers.test.js
+++ b/static_src/shared/metadata-helpers.test.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.
 
diff --git a/static_src/shared/settings.js b/static_src/shared/settings.js
index 0b5fc3c..3a4aa49 100644
--- a/static_src/shared/settings.js
+++ b/static_src/shared/settings.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.
 
diff --git a/static_src/shared/shared-styles.js b/static_src/shared/shared-styles.js
index c00f639..b01898e 100644
--- a/static_src/shared/shared-styles.js
+++ b/static_src/shared/shared-styles.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.
 
@@ -200,4 +200,4 @@
     min-height: 5vh;
     max-height: 15vh;
   }
-`;
\ No newline at end of file
+`;
diff --git a/static_src/shared/test/constants-hotlists.js b/static_src/shared/test/constants-hotlists.js
index a496905..c6c5b45 100644
--- a/static_src/shared/test/constants-hotlists.js
+++ b/static_src/shared/test/constants-hotlists.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.
 
diff --git a/static_src/shared/test/constants-issueV0.js b/static_src/shared/test/constants-issueV0.js
index 4f52aef..0051949 100644
--- a/static_src/shared/test/constants-issueV0.js
+++ b/static_src/shared/test/constants-issueV0.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.
 
diff --git a/static_src/shared/test/constants-permissions.js b/static_src/shared/test/constants-permissions.js
index f4b09c0..0ac763e 100644
--- a/static_src/shared/test/constants-permissions.js
+++ b/static_src/shared/test/constants-permissions.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/static_src/shared/test/constants-projectV0.js b/static_src/shared/test/constants-projectV0.js
index 4a46af8..02e91b9 100644
--- a/static_src/shared/test/constants-projectV0.js
+++ b/static_src/shared/test/constants-projectV0.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.
 
diff --git a/static_src/shared/test/constants-projects.js b/static_src/shared/test/constants-projects.js
index c25f46b..6bd852e 100644
--- a/static_src/shared/test/constants-projects.js
+++ b/static_src/shared/test/constants-projects.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.
 
diff --git a/static_src/shared/test/constants-stars.js b/static_src/shared/test/constants-stars.js
index 42e7012..57ede35 100644
--- a/static_src/shared/test/constants-stars.js
+++ b/static_src/shared/test/constants-stars.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.
 
diff --git a/static_src/shared/test/constants-users.js b/static_src/shared/test/constants-users.js
index 0a9bbf8..f29f588 100644
--- a/static_src/shared/test/constants-users.js
+++ b/static_src/shared/test/constants-users.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.
 
@@ -40,4 +40,3 @@
   name: 'projects/proj/members/1234',
   role: 'CONTRIBUTOR',
 });
-
diff --git a/static_src/shared/test/fakes.js b/static_src/shared/test/fakes.js
index d506f6a..f63cc46 100644
--- a/static_src/shared/test/fakes.js
+++ b/static_src/shared/test/fakes.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.
 
diff --git a/static_src/shared/test/helpers.js b/static_src/shared/test/helpers.js
index 63a1e12..e7eba6f 100644
--- a/static_src/shared/test/helpers.js
+++ b/static_src/shared/test/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.
 
@@ -54,4 +54,3 @@
 
   fireEvent.keyDown(input, {key: 'Enter', code: 'Enter'});
 }
-
diff --git a/static_src/shared/typedef.js b/static_src/shared/typedef.js
index 923e1db..9b4aa0f 100644
--- a/static_src/shared/typedef.js
+++ b/static_src/shared/typedef.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.