Making landingwidget more configurable

Extending the widget configuration by adding param field for the
copytext and a url which has parameters that fit both the ChromeOS and
COS use cases. Along with these changes, there will be changes to the
config to account for the newly added variables in this file.

BUG=b/236752631

Change-Id: I5eba4699b3b5055b88a3b8c0db6f570d6f19c37f
diff --git a/src/main/java/com/googlesource/chromium/plugins/landingwidget/GetLandingWidgetConfig.java b/src/main/java/com/googlesource/chromium/plugins/landingwidget/GetLandingWidgetConfig.java
index 24975ea..9f7d31f 100644
--- a/src/main/java/com/googlesource/chromium/plugins/landingwidget/GetLandingWidgetConfig.java
+++ b/src/main/java/com/googlesource/chromium/plugins/landingwidget/GetLandingWidgetConfig.java
@@ -53,6 +53,8 @@
     r.disabled = cfg.getString(PROJECT, name, "disabled");
     r.instanceName = cfg.getString(PROJECT, name, "instanceName");
     r.serviceUrl = cfg.getString(PROJECT, name, "serviceUrl");
+    r.endpoint = cfg.getString(PROJECT, name, "endpoint");
+    r.copyText = cfg.getString(PROJECT, name, "copyText");
     return Response.ok(r);
   }
 
@@ -65,5 +67,11 @@
 
     @SerializedName("serviceUrl")
     String serviceUrl;
+
+    @SerializedName("endpoint")
+    String endpoint;
+
+    @SerializedName("copyText")
+    String copyText;
   }
 }
diff --git a/web/landingwidget.ts b/web/landingwidget.ts
index 9fc46b2..49bd7bb 100644
--- a/web/landingwidget.ts
+++ b/web/landingwidget.ts
@@ -1,4 +1,4 @@
-// Copyright 2021 The Chromium Authors. All rights reserved.
+// Copyright 2022 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -11,6 +11,8 @@
   disabled: boolean;
   instanceName: string;
   serviceUrl: string;
+  endpoint: string;
+  copyText: string;
   projectPatterns: string[];
 }
 
@@ -49,6 +51,9 @@
   @state()
   versions: LandingWidgetVersion[] = [];
 
+  @state()
+  copyText = 'Landed in';
+
   override update(changedProperties: PropertyValues) {
     if (changedProperties.has('change')) {
       this.onChange();
@@ -101,7 +106,7 @@
     );
     return html`
       <section>
-        <span class="title">Landed in</span>
+        <span class="title">${this.copyText}</span>
         <ul class="value">
           ${items}
         </ul>
@@ -129,13 +134,24 @@
       return;
     }
 
+    // Use default values of of copyText (Landed in) and
+    // endpoint (lookupFirstBuild) if not present in config.
+    if (config.copyText) {
+      this.copyText = config.copyText;
+    }
+    let endpoint:string = 'lookupFirstBuild';
+    if (config.endpoint) {
+      endpoint = config.endpoint;
+    }
+
     // Fetch the first build version that the change landed in.
     const changeNum = this.change._number;
     // We need to use fetch instead of restApi because we need to include
     // credentials.
+    const firstBuildUrl = `${config.serviceUrl}/${endpoint}` +
+      `?instance=${config.instanceName}&cl=${changeNum}`
     const response = (await this.fetchJSON(
-      `${config.serviceUrl}/lookupFirstBuild` +
-        `?instance=${config.instanceName}&cl=${changeNum}`,
+      firstBuildUrl,
       {credentials: 'include'}
     )) as LandingWidgetResponse;
     const versionsLink = `${config.serviceUrl}/cl?q=${config.instanceName}:${changeNum}`;
diff --git a/web/landingwidget_test.ts b/web/landingwidget_test.ts
index c883af6..5a0bd2c 100644
--- a/web/landingwidget_test.ts
+++ b/web/landingwidget_test.ts
@@ -17,8 +17,10 @@
   test('onChange sets element.versions', async () => {
     sinon.stub(element, 'getProjectConfig').returns(
       Promise.resolve({
-        instanceName: 'instance',
-        serviceUrl: 'service-url',
+        instanceName: 'chromium',
+        serviceUrl: 'https://crosland.corp.google.com',
+        endpoint: 'lookupFirstBuild',
+        copyText: 'Landed in',
         disabled: false,
         projectPatterns: [],
       })
@@ -43,16 +45,18 @@
     });
     await element.onChange();
     assert.deepEqual(element.versions, [
-      {text: 'version1', link: 'service-url/cl?q=instance:1'},
-      {text: 'version2', link: 'service-url/cl?q=instance:1'},
+      {text: 'version1', link: 'https://crosland.corp.google.com/cl?q=chromium:1'},
+      {text: 'version2', link: 'https://crosland.corp.google.com/cl?q=chromium:1'},
     ]);
     assert.strictEqual(element.hasVersionInfo, true);
   });
 
   test('getProjectConfig loads the LandingWidget config', async () => {
     const config = {
-      instanceName: 'instance',
-      serviceUrl: 'service-url',
+      instanceName: 'chromium',
+      serviceUrl: 'https://crosland.corp.google.com',
+      endpoint: 'lookupFirstBuild',
+      copyText: 'Landed in',
       disabled: false,
       projectPatterns: ['a', 'b'],
     };