Correctly call BuildbucketV2Client with a change number

Without a change number, the JWT request in buildbucket auth returns a
404 so only public builds are queried. Include the change number so
auth works.

Bug: 1366456
Change-Id: I845d015bac6808069ba9d55c55dc5621e9a8ad29
diff --git a/web/binary-size.ts b/web/binary-size.ts
index 9586961..498ec10 100644
--- a/web/binary-size.ts
+++ b/web/binary-size.ts
@@ -12,6 +12,7 @@
 import {
   ChangeInfo,
   ChangeStatus,
+  NumericChangeId,
   PatchSetNum,
   RevisionKind,
 } from '@gerritcodereview/typescript-api/rest-api';
@@ -131,7 +132,7 @@
     if (!window.buildbucket) {
       console.error(
         'The "binary-size" plugin requires the "buildbucket" plugin for ' +
-        'searching builds. Please activate both.'
+          'searching builds. Please activate both.'
       );
       return false;
     }
@@ -144,7 +145,7 @@
       try {
         config = await this.plugin.restApi().get(path);
       } catch (e) {
-        console.log(`The binary-size plugin is not enabled on ${project}`);
+        console.warn(`The binary-size plugin is not enabled on ${project}`);
       }
       this.enabledCache.set(path, config);
     }
@@ -300,6 +301,7 @@
     const [tryBuilders, ciBuilders] = this.getUniqueTryAndCiBuilders();
 
     let tryBuilds = await this.getBuilds(
+      change._number,
       tryBuilders,
       this.gerritChanges(change, patchsets),
       []
@@ -314,6 +316,7 @@
       });
     });
     let ciBuilds = await this.getBuilds(
+      change._number,
       ciBuilders,
       [],
       this.revisionTags(tryBuildToBuilderPair, change)
@@ -366,7 +369,7 @@
    */
   revisionTags(
     tryBuildToBuilderPair: Map<BuildbucketBuild, BuilderPair>,
-    change: ChangeInfo,
+    change: ChangeInfo
   ): BuildbucketTag[] {
     const tags: Map<string, BuildbucketTag> = new Map();
     tryBuildToBuilderPair.forEach((builderPair, build) => {
@@ -386,6 +389,7 @@
    * Get builds that match any of the builders and any of the tags.
    */
   async getBuilds(
+    changeNumber: NumericChangeId,
     builders: BuildbucketBuilder[],
     gerritChanges: object[],
     tags: BuildbucketTag[]
@@ -396,7 +400,10 @@
     ) {
       return [];
     }
-    const bb = new window.buildbucket.BuildbucketV2Client(this.buildbucketHost);
+    const bb = new window.buildbucket.BuildbucketV2Client(
+      this.buildbucketHost,
+      changeNumber
+    );
     const fields = [
       'builder',
       'id',
diff --git a/web/binary-size_test.ts b/web/binary-size_test.ts
index 46550cd..5c215de 100644
--- a/web/binary-size_test.ts
+++ b/web/binary-size_test.ts
@@ -17,6 +17,7 @@
 import {
   ChangeInfo,
   ChangeStatus,
+  NumericChangeId,
   PatchSetNum,
   RevisionKind,
 } from '@gerritcodereview/typescript-api/rest-api';
@@ -93,7 +94,10 @@
       {project: 'project', bucket: 'some.bucket', builder: 'builder1'},
       {project: 'project', bucket: 'a.b.c', builder: 'builder2'},
     ];
-    assert.deepEqual(await fetcher.getBuilds(builders, [], []), []);
+    assert.deepEqual(
+      await fetcher.getBuilds(1 as NumericChangeId, builders, [], []),
+      []
+    );
   });
 
   test('getBuilds', async () => {
@@ -114,6 +118,7 @@
     ];
     assert.deepEqual(
       await fetcher.getBuilds(
+        1 as NumericChangeId,
         builders,
         [],
         [{key: 'buildset', value: 'foo/bar'}]
@@ -184,8 +189,14 @@
       [{output: {properties: {got_revision: 'beef'}}}, {ciBuilderRepo: ''}],
       [{output: {properties: {got_revision: 'a3ee'}}}, {ciBuilderRepo: ''}],
       [{output: {properties: {got_revision: 'beef'}}}, {ciBuilderRepo: ''}],
-      [{output: {properties: {got_revision: 'a3ee'}}}, {ciBuilderRepo: 'src/other'}],
-      [{output: {properties: {got_revision: 'a3ee'}}}, {ciBuilderGitHost: 'other-host'}],
+      [
+        {output: {properties: {got_revision: 'a3ee'}}},
+        {ciBuilderRepo: 'src/other'},
+      ],
+      [
+        {output: {properties: {got_revision: 'a3ee'}}},
+        {ciBuilderGitHost: 'other-host'},
+      ],
     ]) as Map<BuildbucketBuild, BuilderPair>;
     assert.deepEqual(fetcher.revisionTags(tryBuildToBuilderPair, change), [
       {key: 'buildset', value: 'commit/gitiles/host/src/+/beef'},