Merge branch 'main' into avm99963-monorail

Merged commit 3779da353b36d43cf778e7d4f468097714dd4540

GitOrigin-RevId: 6451a5c6b75afb0fd1f37b3f14521148d0722ea8
diff --git a/static_src/reducers/issueV0.js b/static_src/reducers/issueV0.js
index 880ebbc..8f670c9 100644
--- a/static_src/reducers/issueV0.js
+++ b/static_src/reducers/issueV0.js
@@ -14,7 +14,7 @@
 import {createSelector} from 'reselect';
 import {autolink} from 'autolink.js';
 import {fieldTypes, extractTypeForIssue,
-  fieldValuesToMap} from 'shared/issue-fields.js';
+  fieldValuesToMap, migratedTypes} from 'shared/issue-fields.js';
 import {removePrefix, objectToMap} from 'shared/helpers.js';
 import {issueRefToString, issueToIssueRefString,
   issueStringToRef, issueNameToRefString} from 'shared/convertersV0.js';
@@ -493,7 +493,9 @@
 const RESTRICT_VIEW_PREFIX = 'restrict-view-';
 const RESTRICT_EDIT_PREFIX = 'restrict-editissue-';
 const RESTRICT_COMMENT_PREFIX = 'restrict-addissuecomment-';
-const MIGRATED_ISSUE_PREFIX = 'migrated-to-b-';
+const MIGRATED_ISSUE_PREFIX = 'migrated-to-';
+const MIGRATED_BUGANIZER_ISSUE_PREFIX = 'migrated-to-b-';
+const MIGRATED_LAUNCH_ISSUE_PREFIX = 'migrated-to-launch-';
 
 /**
  * Selector to retrieve all normalized Issue data in the Redux store,
@@ -704,22 +706,49 @@
     },
 );
 
-// Gets the Issue Tracker ID of a moved issue.
+// Gets the Issue Tracker or Launch ID of a moved issue.
 export const migratedId = createSelector(
   labelRefs,
   (labelRefs) => {
     if (!labelRefs) return '';
 
-    // Assume that there's only one migrated-to-b-* label. Or at least drop any
+    // Assume that there's only one migrated-to-* label. Or at least drop any
+    // labels besides the first one.
+    const migrationLabel = labelRefs.find((labelRef) => {
+      return labelRef.label.toLowerCase().startsWith(MIGRATED_ISSUE_PREFIX);
+    });
+    
+    if (migrationLabel) {
+      if (migrationLabel.label.toLowerCase().startsWith(MIGRATED_BUGANIZER_ISSUE_PREFIX)) {
+        return migrationLabel.label.substring(MIGRATED_BUGANIZER_ISSUE_PREFIX.length);
+      } else if (migrationLabel.label.toLowerCase().startsWith(MIGRATED_LAUNCH_ISSUE_PREFIX)) {
+        return migrationLabel.label.substring(MIGRATED_LAUNCH_ISSUE_PREFIX.length);
+      }
+    }
+    return '';
+  },
+);
+
+// Gets the Issue Migrated Type of a moved issue.
+export const migratedType = createSelector(
+  labelRefs,
+  (labelRefs) => {
+    if (!labelRefs) return migratedTypes.NONE;
+
+    // Assume that there's only one migrated-to-* label. Or at least drop any
     // labels besides the first one.
     const migrationLabel = labelRefs.find((labelRef) => {
       return labelRef.label.toLowerCase().startsWith(MIGRATED_ISSUE_PREFIX);
     });
 
     if (migrationLabel) {
-      return migrationLabel.label.substring(MIGRATED_ISSUE_PREFIX.length);
+      if (migrationLabel.label.toLowerCase().startsWith(MIGRATED_BUGANIZER_ISSUE_PREFIX)) {
+        return migratedTypes.BUGANIZER_TYPE;
+      } else if (migrationLabel.label.toLowerCase().startsWith(MIGRATED_LAUNCH_ISSUE_PREFIX)) {
+        return migratedTypes.LAUNCH_TYPE;
+      }
     }
-    return '';
+    return migratedTypes.NONE;
   },
 );
 
diff --git a/static_src/reducers/issueV0.test.js b/static_src/reducers/issueV0.test.js
index 33b63c1..b79cdb5 100644
--- a/static_src/reducers/issueV0.test.js
+++ b/static_src/reducers/issueV0.test.js
@@ -12,6 +12,7 @@
 import {issueToIssueRef, issueRefToString} from 'shared/convertersV0.js';
 import {prpcClient} from 'prpc-client-instance.js';
 import {getSigninInstance} from 'shared/gapi-loader.js';
+import {migratedTypes} from 'shared/issue-fields.js';
 
 let prpcCall;
 let dispatch;
@@ -323,6 +324,48 @@
       {label: 'migrated-to-b-1234'},
       {label: 'migrated-to-b-6789'},
     ]})), '1234');
+
+    assert.equal(issueV0.migratedId(wrapIssue({labelRefs: [
+      {label: 'IgnoreThis'},
+      {label: 'IgnoreThis2'},
+      {label: 'migrated-to-launch-6789'},
+    ]})), '6789');
+
+    assert.equal(issueV0.migratedId(wrapIssue({labelRefs: [
+      {label: 'migrated-to-launch-1234'},
+    ]})), '1234');
+
+    // We assume there's only one migrated-to-* label.
+    assert.equal(issueV0.migratedId(wrapIssue({labelRefs: [
+      {label: 'migrated-to-launch-1234'},
+      {label: 'migrated-to-b-6789'},
+    ]})), '1234');
+  });
+
+  it('migratedType', () => {
+    assert.equal(issueV0.migratedType(wrapIssue()), migratedTypes.NONE);
+    assert.equal(issueV0.migratedType(wrapIssue({labelRefs: []})), migratedTypes.NONE);
+
+    assert.equal(issueV0.migratedType(wrapIssue({labelRefs: [
+      {label: 'IgnoreThis'},
+      {label: 'IgnoreThis2'},
+    ]})), migratedTypes.NONE);
+
+    assert.equal(issueV0.migratedType(wrapIssue({labelRefs: [
+      {label: 'IgnoreThis'},
+      {label: 'IgnoreThis2'},
+      {label: 'migrated-to-b-6789'},
+    ]})), migratedTypes.BUGANIZER_TYPE);
+
+    assert.equal(issueV0.migratedType(wrapIssue({labelRefs: [
+      {label: 'migrated-to-launch-1234'},
+    ]})), migratedTypes.LAUNCH_TYPE);
+
+    // We assume there's only one migrated-to-b-* label.
+    assert.equal(issueV0.migratedType(wrapIssue({labelRefs: [
+      {label: 'migrated-to-launch-1234'},
+      {label: 'migrated-to-b-6789'},
+    ]})), migratedTypes.LAUNCH_TYPE);
   });