Commit c2c5572e authored by tiagonbotelho's avatar tiagonbotelho Committed by Yorick Peterse

adds swp and swo to gitignore and improves migration for project main_language

parent dc31aff3
......@@ -89,12 +89,8 @@ class Project < ActiveRecord::Base
# checks if the language main language of the project changed
before_save :check_main_language
def check_main_language
if !repository.empty? && self.changed?
language = Linguist::Repository.new(
repository.rugged,
repository.rugged.head.target_id).language
self.main_language = language
if commit_count.changed?
self.main_language = repository.main_language
end
end
......@@ -957,4 +953,14 @@ class Project < ActiveRecord::Base
def wiki
@wiki ||= ProjectWiki.new(self, self.owner)
end
def main_language
language = read_attributes(:main_language)
return language if language
update_attributes(main_language: repository.main_language)
read_attributes(:main_language)
end
end
......@@ -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
......
class AddMainLanguageToRepository < ActiveRecord::Migration
require 'rugged'
require 'linguist'
def up
add_column :projects, :main_language, :string, default: nil
Project.all.each do |project|
unless project.repository.empty?
language = Linguist::Repository.new(
project.repository.rugged,
project.repository.rugged.head.target_id).language
project.update_attributes(main_language: language)
end
end
end
def down
remove_column :projects, :main_language
def change
add_column :projects, :main_language, :string
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