Commit 8776d9a3 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'use-language-colours-for-graph' into 'master'

Use defined colour for a language when available

## What does this MR do?

This MR changes the colours of the different languages in the language graph.  It now uses the colour set in Linguist instead of the first six characters of the SHA256'd language name where possible.  If Linguist has no colour defined for a given language, it falls back to the old method of finding a colour.

I talked with @connorshea about creating this MR [on Twitter](https://twitter.com/connorjshea/status/784390886222286849) a few hours earlier. Here's also an older [tweet from May](https://twitter.com/nilsding/status/737018807223496708) where we discussed some possible improvements to the graph. 

## Are there points in the code the reviewer needs to double check?

Hopefully none ;)

## Why was this MR needed?

Aesthetics.

## Screenshots (if relevant)

Before:

![language_colours_before](/uploads/6b4bac784860da746d58708bdd6bba39/language_colours_before.png)

After:

![language_colours_after](/uploads/98818ebf48ffb47e6b785120e69b0b6c/language_colours_after.png)

## Does this MR meet the acceptance criteria?

- [ ] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added
- [ ] [Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)
- [ ] API support added
- Tests
  - [ ] Added for this feature/bug
  - [ ] All builds are passing
- [ ] Conform by the [merge request performance guides](http://docs.gitlab.com/ce/development/merge_request_performance_guidelines.html)
- [ ] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [ ] Branch has no merge conflicts with `master` (if it does - rebase it please)
- [ ] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)

## What are the relevant issue numbers?

- #12455

See merge request !6748
parents 4b889dbb 85324ff8
......@@ -57,6 +57,7 @@ v 8.13.0 (unreleased)
- Close open merge request without source project (Katarzyna Kobierska Ula Budziszewska)
- Fix that manual jobs would no longer block jobs in the next stage. !6604
- Add configurable email subject suffix (Fu Xu)
- Use defined colour for a language when available !6748 (nilsding)
- Added tooltip to fork count on project show page. (Justin DiPierro)
- Use a ConnectionPool for Rails.cache on Sidekiq servers
- Replace `alias_method_chain` with `Module#prepend`
......
......@@ -38,12 +38,12 @@ class Projects::GraphsController < Projects::ApplicationController
@languages = @languages.map do |language|
name, share = language
color = Digest::SHA256.hexdigest(name)[0...6]
color = Linguist::Language[name].color || "##{Digest::SHA256.hexdigest(name)[0...6]}"
{
value: (share.to_f * 100 / total).round(2),
label: name,
color: "##{color}",
highlight: "##{color}"
color: color,
highlight: color
}
end
......
require 'spec_helper'
describe Projects::GraphsController do
let(:project) { create(:project) }
let(:user) { create(:user) }
before do
sign_in(user)
project.team << [user, :master]
end
describe 'GET #languages' do
let(:linguist_repository) do
double(languages: {
'Ruby' => 1000,
'CoffeeScript' => 350,
'PowerShell' => 15
})
end
let(:expected_values) do
ps_color = "##{Digest::SHA256.hexdigest('PowerShell')[0...6]}"
[
# colors from Linguist:
{ label: "Ruby", color: "#701516", highlight: "#701516" },
{ label: "CoffeeScript", color: "#244776", highlight: "#244776" },
# colors from SHA256 fallback:
{ label: "PowerShell", color: ps_color, highlight: ps_color }
]
end
before do
allow(Linguist::Repository).to receive(:new).and_return(linguist_repository)
end
it 'sets the correct colour according to language' do
get(:languages, namespace_id: project.namespace.path, project_id: project.path, id: 'master')
expected_values.each do |val|
expect(assigns(:languages)).to include(a_hash_including(val))
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment