debian-mirror-gitlab/doc/integration/sourcegraph.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

112 lines
5.3 KiB
Markdown
Raw Normal View History

2019-12-26 22:10:19 +05:30
---
2020-10-24 23:57:45 +05:30
stage: Create
group: Source Code
2022-11-25 23:54:43 +05:30
info: "To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments"
2019-12-26 22:10:19 +05:30
type: reference, how-to
---
2023-04-23 21:23:45 +05:30
# Sourcegraph **(FREE)**
2019-12-26 22:10:19 +05:30
2022-03-02 08:16:31 +05:30
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/16556) in GitLab 12.5 [with a flag](../administration/feature_flags.md) named `sourcegraph`. Disabled by default.
> - Enabled on GitLab.com in GitLab 12.5.
> - [Enabled on self-managed](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/73116) in GitLab 14.8.
FLAG:
On self-managed GitLab, by default this feature is available. To hide the feature, ask an administrator to [disable the feature flag](../administration/feature_flags.md) named `sourcegraph`.
On GitLab.com, this feature is available for public projects only.
2019-12-26 22:10:19 +05:30
[Sourcegraph](https://sourcegraph.com) provides code intelligence features, natively integrated into the GitLab UI.
For GitLab.com users, see [Sourcegraph for GitLab.com](#sourcegraph-for-gitlabcom).
![Sourcegraph demo](img/sourcegraph_demo_v12_5.png)
<i class="fa fa-youtube-play youtube" aria-hidden="true"></i>
For an overview, watch the video [Sourcegraph's new GitLab native integration](https://www.youtube.com/watch?v=LjVxkt4_sEA).
2021-02-22 17:27:13 +05:30
NOTE:
2019-12-26 22:10:19 +05:30
This feature requires user opt-in. After Sourcegraph has been enabled for your GitLab instance,
you can choose to enable Sourcegraph [through your user preferences](#enable-sourcegraph-in-user-preferences).
2021-03-11 19:13:27 +05:30
## Set up for self-managed GitLab instances **(FREE SELF)**
2019-12-26 22:10:19 +05:30
2021-03-11 19:13:27 +05:30
Before you can enable Sourcegraph code intelligence in GitLab you must:
2022-03-02 08:16:31 +05:30
configure a Sourcegraph instance with your GitLab instance as an external service.
2019-12-26 22:10:19 +05:30
2022-03-02 08:16:31 +05:30
### Set up a self-managed Sourcegraph instance **(FREE SELF)**
2019-12-26 22:10:19 +05:30
If you are new to Sourcegraph, head over to the [Sourcegraph installation documentation](https://docs.sourcegraph.com/admin) and get your instance up and running.
2021-03-11 19:13:27 +05:30
If you are using an HTTPS connection to GitLab, you must [configure HTTPS](https://docs.sourcegraph.com/admin/http_https_configuration) for your Sourcegraph instance.
2021-02-22 17:27:13 +05:30
2019-12-26 22:10:19 +05:30
### Connect your Sourcegraph instance to your GitLab instance
2022-07-16 23:28:13 +05:30
1. Navigate to the site Admin Area in Sourcegraph.
2019-12-26 22:10:19 +05:30
1. [Configure your GitLab external service](https://docs.sourcegraph.com/admin/external_service/gitlab).
You can skip this step if you already have your GitLab repositories searchable in Sourcegraph.
1. Validate that you can search your repositories from GitLab in your Sourcegraph instance by running a test query.
1. Add your GitLab instance URL to the [`corsOrigin` setting](https://docs.sourcegraph.com/admin/config/site_config#corsOrigin) in your site configuration.
### Configure your GitLab instance with Sourcegraph
2022-10-11 01:57:18 +05:30
1. On the top bar, select **Main menu > Admin**.
2021-11-11 11:23:49 +05:30
1. On the left sidebar, select **Settings > General**.
2019-12-26 22:10:19 +05:30
1. Expand the **Sourcegraph** configuration section.
1. Check **Enable Sourcegraph**.
2021-03-11 19:13:27 +05:30
1. Set the Sourcegraph URL to your Sourcegraph instance, such as `https://sourcegraph.example.com`.
2019-12-26 22:10:19 +05:30
2021-03-11 19:13:27 +05:30
![Sourcegraph administration settings](img/sourcegraph_admin_v12_5.png)
2019-12-26 22:10:19 +05:30
## Enable Sourcegraph in user preferences
If a GitLab administrator has enabled Sourcegraph, you can enable this feature in your user preferences.
2021-03-11 19:13:27 +05:30
In GitLab:
2023-04-23 21:23:45 +05:30
1. In the upper-right corner, select your avatar.
2021-03-11 19:13:27 +05:30
1. Select **Preferences**.
1. In the **Integrations** section, select the checkbox under **Sourcegraph**.
1. Select **Save changes**.
2019-12-26 22:10:19 +05:30
![Sourcegraph user preferences](img/sourcegraph_user_preferences_v12_5.png)
## Using Sourcegraph code intelligence
2021-03-11 19:13:27 +05:30
Once enabled, participating projects display a code intelligence popover available in
2019-12-26 22:10:19 +05:30
the following code views:
- Merge request diffs
- Commit view
- File view
When visiting one of these views, you can now hover over a code reference to see a popover with:
- Details on how this reference was defined.
- **Go to definition**, which navigates to the line of code where this reference was defined.
2020-03-13 15:44:24 +05:30
- **Find references**, which navigates to the configured Sourcegraph instance, showing a list of references to the highlighted code.
2019-12-26 22:10:19 +05:30
![Sourcegraph demo](img/sourcegraph_popover_v12_5.png)
## Sourcegraph for GitLab.com
2020-05-24 23:13:21 +05:30
Sourcegraph powered code intelligence is available for all public projects on GitLab.com.
2019-12-26 22:10:19 +05:30
2021-03-11 19:13:27 +05:30
Support for private projects is not yet available for GitLab.com;
2020-04-22 19:07:51 +05:30
follow the epic [&2201](https://gitlab.com/groups/gitlab-org/-/epics/2201)
for updates.
2019-12-26 22:10:19 +05:30
2020-04-22 19:07:51 +05:30
## Troubleshooting
### Sourcegraph isn't working
2023-04-23 21:23:45 +05:30
If you enabled Sourcegraph for your project but it isn't working, Sourcegraph may not have indexed the project yet. You can check if Sourcegraph is available for your project by visiting `https://sourcegraph.com/gitlab.com/<project-path>`replacing `<project-path>` with the path to your GitLab project.
2019-12-26 22:10:19 +05:30
## Sourcegraph and Privacy
2023-04-23 21:23:45 +05:30
From the Sourcegraph [extension documentation](https://docs.sourcegraph.com/integration/browser_extension#privacy) which is the
2019-12-26 22:10:19 +05:30
engine behind the native GitLab integration:
> Sourcegraph integrations never send any logs, pings, usage statistics, or telemetry to Sourcegraph.com.
2021-03-11 19:13:27 +05:30
> They connect only to Sourcegraph.com as required to provide code intelligence or other functionality on public code.
2019-12-26 22:10:19 +05:30
> As a result, no private code, private repository names, usernames, or any other specific data is sent to Sourcegraph.com.