summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/sourcegraph/index.js
blob: 487a565b1526e722b7e59193f2114e0ba7cf8204 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function loadScript(path) {
  const script = document.createElement('script');
  script.type = 'application/javascript';
  script.src = path;
  script.defer = true;
  document.head.appendChild(script);
}

/**
 * Loads the Sourcegraph integration for support for Sourcegraph extensions and
 * code intelligence.
 */
export default function initSourcegraph() {
  const { url } = gon.sourcegraph || {};

  if (!url) {
    return;
  }

  const assetsUrl = new URL(process.env.SOURCEGRAPH_PUBLIC_PATH, window.location.href);
  const scriptPath = new URL('scripts/integration.bundle.js', assetsUrl).href;

  window.SOURCEGRAPH_ASSETS_URL = assetsUrl.href;
  window.SOURCEGRAPH_URL = url;
  window.SOURCEGRAPH_INTEGRATION = 'gitlab-integration';

  loadScript(scriptPath);
}