blob: 3f5e9caae456e4d08d1b19ae410115e979031e0f [file] [log] [blame]
// Copyright 2018 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.
import '@gerritcodereview/typescript-api/gerrit';
import {initAuth} from './auth';
import {CacheObject} from './cache-object';
import {ResultDbV1Client} from './resultdb-client';
import {BuildbucketV2Client} from './buildbucket-client';
import {ChecksFetcher} from './checks-fetcher';
import {installChecksResult} from './checks-result';
import {
compareBuildIds,
convertLegacyBucket,
identicalBucket,
} from './buildbucket-utils';
import {PluginApi} from '@gerritcodereview/typescript-api/plugin';
const platformJsElement = document.createElement('script');
platformJsElement.setAttribute('src', 'https://apis.google.com/js/platform.js');
document.head.appendChild(platformJsElement);
window.Gerrit.install(async (plugin: PluginApi): Promise<void> => {
initAuth(plugin, platformJsElement);
const buildbucketHost = 'cr-buildbucket.appspot.com';
const fetcher = new ChecksFetcher(plugin, buildbucketHost, 100);
// TODO(aravindvasudev): Update to @gerritcodereview/typescript-api/checks implementation once Gerrit updates their API.
plugin
.checks()
.register(
{fetch: changeData => fetcher.fetch(changeData) as any},
{fetchPollingIntervalSeconds: 10}
);
plugin.hook('check-result-expanded').onAttached(installChecksResult);
});
// Export clients/functions to global space so other plugins can use them.
// TODO(https://crbug.com/1087585): remove global variables
window.buildbucket = window.buildbucket || {};
Object.assign(window.buildbucket, {
BuildbucketV2Client,
CacheObject,
ResultDbV1Client,
compareBuildIds,
convertLegacyBucket,
identicalBucket,
});