Commit 36730e8e authored by Yorick Peterse's avatar Yorick Peterse

Merge branch 'master' into 'master'

adds language names to projects list [image attached]

See merge request !3000
parents a19a9fab 49295924
......@@ -18,6 +18,7 @@ v 8.6.0 (unreleased)
- Don't show Issues/MRs from archived projects in Groups view
- Increase the notes polling timeout over time (Roberto Dip)
- Show labels in dashboard and group milestone views
- Add main language of a project in the list of projects (Tiago Botelho)
v 8.5.4
- Do not cache requests for badges (including builds badge)
......
......@@ -812,6 +812,12 @@ class Repository
raw_repository.ls_files(actual_ref)
end
def main_language
unless empty?
Linguist::Repository.new(rugged, rugged.head.target_id).language
end
end
private
def cache
......
......@@ -14,6 +14,7 @@ class GitPushService < BaseService
# 3. Recognizes cross-references from commit messages
# 4. Executes the project's web hooks
# 5. Executes the project's services
# 6. Checks if the project's main language has changed
#
def execute
@project.repository.after_push_commit(branch_name)
......@@ -42,11 +43,24 @@ class GitPushService < BaseService
@push_commits = @project.repository.commits_between(params[:oldrev], params[:newrev])
process_commit_messages
end
# Checks if the main language has changed in the project and if so
# it updates it accordingly
update_main_language
# Update merge requests that may be affected by this push. A new branch
# could cause the last commit of a merge request to change.
update_merge_requests
end
def update_main_language
current_language = @project.repository.main_language
unless current_language == @project.main_language
return @project.update_attributes(main_language: current_language)
end
true
end
protected
def update_merge_requests
......
......@@ -28,6 +28,9 @@
= project.name
.controls
- if project.main_language
%span
= project.main_language
- if ci_commit
%span
= render_ci_status(ci_commit)
......
class AddMainLanguageToRepository < ActiveRecord::Migration
def change
add_column :projects, :main_language, :string
end
end
......@@ -595,4 +595,16 @@ describe Repository, models: true do
repository.after_remove_branch
end
end
describe "#main_language" do
it 'shows the main language of the project' do
expect(repository.main_language).to eq("Ruby")
end
it 'returns nil when the repository is empty' do
allow(repository).to receive(:empty?).and_return(true)
expect(repository.main_language).to be_nil
end
end
end
......@@ -155,6 +155,23 @@ describe GitPushService, services: true do
end
end
describe "Updates main language" do
context "before push" do
it { expect(project.main_language).to eq(nil) }
end
context "after push" do
before do
@service = execute_service(project, user, @oldrev, @newrev, @ref)
end
it { expect(@service.update_main_language).to eq(true) }
it { expect(project.main_language).to eq("Ruby") }
end
end
describe "Web Hooks" do
context "execute web hooks" do
it "when pushing a branch for the first time" do
......
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