MVC: Expose count of Source Lines of Code (SLoC) per project in the API and in the Repository Analytics UI
### Release notes for the MVC Source lines of code (SLoC) are a great metric for the size of a code project. GitLab now shows SLoC per language under **Analytics > Repository**. This way you can quickly decide if you can contribute to a project, given your programming talents in different languages. ### Release notes for the intermediate drop with the API improvement The [Project Languages API](https://docs.gitlab.com/ee/api/projects.html#languages) now also exposes source lines of code per language to help you understand the size of a project and the prevalent languages. ### Problem to solve When first confronted with a repo, I want to know the prevalent languages and the dimension of the source code, so that I can get a quick sense of whether I can contribute given my talents. ### Intended users - [Sasha (Software Developer)](https://about.gitlab.com/handbook/marketing/product-marketing/roles-personas/#sasha-software-developer) ### Proposal #### Extend the Project Languages API to expose also lines of code per language - Extend the [Project Languages API](https://docs.gitlab.com/ee/api/projects.html#languages) to expose also lines of code per language (and size in kB per language if that is no extra effort). - Base the measurement on the default branch only. - Non-functional requirement: the exposed data should not be older two weeks - Improve the documentation - explain the units that apply for the different responses (i.e. %, SLoC, kB) - explain that the data is based on the default branch only - explain the freshness of the data #### Change the frontend to expose SLoC in those places that currently only provide percentage values - Change the [Repository Analytics - Programming languages used in this repository](https://gitlab.com/gitlab-org/gitlab/-/graphs/master/charts) to also show lines of code per language (in addition to the percentages). - Existing graph may be used and just the tool tip could be adjusted or the y-axis could be changed to show the count of SLoC rather than the percentage (remains to be seen). - Likewise, use the count of SLoC per language in addition to the percent per language in the tooltip when hovering over the [colored language distribution bar on the top of the project main page](https://gitlab.com/gitlab-org/gitlab). ### Technical approach Two potential approaches: - Replacing `go-enry` with `SCC` seems rather straightforward given this discussion [here](https://gitlab.com/gitlab-org/gitlab/-/issues/373712#note_1174360882). - (See if there are synergies with the search team: https://gitlab.com/groups/gitlab-org/-/epics/6853+.) #### Tentative effort estimation (base on first technical approach above) 1. Add `scc` support into Gitaly (weight: 2-3) 1. Add support for the changed Gitaly endpoint into the Rails application (weight: 1) 1. Migrate Rails to use `scc` (weight: 2) 1. **NOT NECESSARY FOR THE MVP**: Extend the language API to expose lines of code received from Gitaly `scc` endpoint (weight: 2) 1. Frontend to include the SLoC in the existing [Repository Analytics - Programming languages used in this repository](https://gitlab.com/gitlab-org/gitlab/-/graphs/master/charts) (weight: 3 (Refactoring to use API)) or (weight 1: if data is available through Ruby in HAML) 1. Frontend to include the SLoC in the existing [colored language distribution bar on the top of the project main page](https://gitlab.com/gitlab-org/gitlab). (weight: 3 (Refactoring to use API)) or (weight 1: if data is available through same Ruby method) #### Tentative risk assessment (base on first technical approach above) The risk seems `Low`. For details see discussion: https://gitlab.com/groups/gitlab-org/-/epics/9692#note_1244584288.
epic