diff options
Diffstat (limited to 'app/assets/javascripts/sourcegraph/index.js')
-rw-r--r-- | app/assets/javascripts/sourcegraph/index.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/app/assets/javascripts/sourcegraph/index.js b/app/assets/javascripts/sourcegraph/index.js new file mode 100644 index 00000000000..796e90bf08e --- /dev/null +++ b/app/assets/javascripts/sourcegraph/index.js @@ -0,0 +1,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('/assets/webpack/sourcegraph/', 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); +} |