summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-03-08 14:52:53 +0000
committerYorick Peterse <yorickpeterse@gmail.com>2016-03-08 14:52:53 +0000
commit36730e8e63c0ebe16785f33cb2b740f8d67b2b25 (patch)
tree7f025ea90feeba9bcda0a30cd3bb933708142469
parenta19a9faba94a6ea6367032cbd001bcc166160835 (diff)
parent49295924586d89eaff899a4efc83a336148f3862 (diff)
downloadgitlab-ce-36730e8e63c0ebe16785f33cb2b740f8d67b2b25.tar.gz
Merge branch 'master' into 'master'
adds language names to projects list [image attached] See merge request !3000
-rw-r--r--CHANGELOG1
-rw-r--r--app/models/repository.rb6
-rw-r--r--app/services/git_push_service.rb14
-rw-r--r--app/views/shared/projects/_project.html.haml3
-rw-r--r--db/migrate/20160229193553_add_main_language_to_repository.rb5
-rw-r--r--spec/models/repository_spec.rb12
-rw-r--r--spec/services/git_push_service_spec.rb17
7 files changed, 58 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG
index a9742d22015..a98bdd26f74 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -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)
diff --git a/app/models/repository.rb b/app/models/repository.rb
index c135ab61f6a..ff48f993d42 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -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
diff --git a/app/services/git_push_service.rb b/app/services/git_push_service.rb
index 9ba200f7bde..736b82e3571 100644
--- a/app/services/git_push_service.rb
+++ b/app/services/git_push_service.rb
@@ -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
diff --git a/app/views/shared/projects/_project.html.haml b/app/views/shared/projects/_project.html.haml
index 99e48e86e38..97cfb76cdb0 100644
--- a/app/views/shared/projects/_project.html.haml
+++ b/app/views/shared/projects/_project.html.haml
@@ -28,6 +28,9 @@
= project.name
.controls
+ - if project.main_language
+ %span
+ = project.main_language
- if ci_commit
%span
= render_ci_status(ci_commit)
diff --git a/db/migrate/20160229193553_add_main_language_to_repository.rb b/db/migrate/20160229193553_add_main_language_to_repository.rb
new file mode 100644
index 00000000000..b5446c6a447
--- /dev/null
+++ b/db/migrate/20160229193553_add_main_language_to_repository.rb
@@ -0,0 +1,5 @@
+class AddMainLanguageToRepository < ActiveRecord::Migration
+ def change
+ add_column :projects, :main_language, :string
+ end
+end
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index 1c7d66398cb..150422ac349 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -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
diff --git a/spec/services/git_push_service_spec.rb b/spec/services/git_push_service_spec.rb
index 994585fb32c..f5c51e46e8b 100644
--- a/spec/services/git_push_service_spec.rb
+++ b/spec/services/git_push_service_spec.rb
@@ -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