diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb index 21e094407..77acdfd05 100644 --- a/app/controllers/quality_analysis_controller.rb +++ b/app/controllers/quality_analysis_controller.rb @@ -30,20 +30,20 @@ class QualityAnalysisController < ApplicationController sonar.sources=#{path} sonar.language=#{language.downcase} sonar.sourceEncoding=utf-8" - git_url = gitlab_address.to_s+"/"+@project.owner.to_s+"/"+ identifier+"."+"git" + git_url = gitlab_address.to_s+"/"+@project.owner.to_s+"/"+ identifier + "."+"git" - - # # modify config + # # # modify config @doc = Nokogiri::XML(File.open(File.join(Rails.root, 'tmp', 'config.xml'))) @doc.at_xpath("//hudson.plugins.git.UserRemoteConfig/url").content = git_url @doc.at_xpath("//hudson.plugins.git.BranchSpec/name").content = "*/#{branch}" @doc.at_xpath("//hudson.plugins.sonar.SonarRunnerBuilder/properties").content = properties #sonar-properties - + # # replace config.xml of jenkins @client = @client.job.create("#{user_name}_#{identifier}", @doc.to_xml) # relace gitlab hook # genkins address @g.add_project_hook(@project.gpid,"http://123.59.135.93:8890/project/#{user_name}_#{identifier}") + QualityAnalysis.create(:project_id => @project.id, :author_login => user_name, :rep_identifier => identifier) end def index diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 3f630ce51..cbb5b2f69 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -30,13 +30,13 @@ class RepositoriesController < ApplicationController menu_item :settings, :only => [:new, :create, :edit, :update, :destroy, :committers] default_search_scope :changesets - before_filter :find_project_by_project_id, :only => [:new, :create, :newrepo, :stats, :quality_analyses] + before_filter :find_project_by_project_id, :only => [:new, :create, :newrepo, :stats, :quality_analysis] before_filter :find_repository, :only => [:edit, :update, :destroy, :committers] before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo, :to_gitlab, :forked, :project_archive] before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue] - before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :commit_diff, :project_archive, :quality_analyses] + before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :commit_diff, :project_archive, :quality_analysis] # 链接gitlab - before_filter :connect_gitlab, :only => [:quality_analyses] + before_filter :connect_gitlab, :only => [:quality_analysis] accept_rss_auth :revisions # hidden repositories filter // 隐藏代码过滤器 before_filter :check_hidden_repo, :only => [:show, :stats, :revisions, :revision, :diff ] @@ -309,7 +309,7 @@ update end end - def quality_analyses + def quality_analysis gitlab_branches = @g.branches(@project.gpid) @branch_names = gitlab_branches.map{|b| b.name} @gitlab_default_branch = @g.project(@project.gpid).default_branch diff --git a/app/models/quality_analysis.rb b/app/models/quality_analysis.rb new file mode 100644 index 000000000..45778ff3f --- /dev/null +++ b/app/models/quality_analysis.rb @@ -0,0 +1,3 @@ +class QualityAnalysis < ActiveRecord::Base + attr_accessible :author_login, :project_id, :rep_identifier +end diff --git a/app/views/repositories/_quality_analyses.html.erb b/app/views/repositories/_quality_analysis.html.erb similarity index 77% rename from app/views/repositories/_quality_analyses.html.erb rename to app/views/repositories/_quality_analysis.html.erb index bf45ba167..64dd837b7 100644 --- a/app/views/repositories/_quality_analyses.html.erb +++ b/app/views/repositories/_quality_analysis.html.erb @@ -1,4 +1,4 @@ -<%= form_tag( url_for(:controller => 'quality_analysis', :action => 'create', :project_id => @project.id), :remote => true , :class => 'resourcesSearchloadBox mt10', :id => 'quality_analyses_form') do %> +<%= form_tag( url_for(:controller => 'quality_analysis', :action => 'create', :project_id => @project.id, :user_id => User.current.id, :identifier => @repository.identifier), :remote => true , :class => 'resourcesSearchloadBox mt10', :id => 'quality_analyses_form') do %> <%= select_tag :branch, options_for_select(["#{@gitlab_default_branch}"]+ @branch_names, @rev), :id => 'branch' %> <%= select_tag :language, options_for_select(["Java","C","PHP", "Web"]), :id => 'branch' %> diff --git a/app/views/repositories/quality_analyses.js.erb b/app/views/repositories/quality_analysis.js.erb similarity index 89% rename from app/views/repositories/quality_analyses.js.erb rename to app/views/repositories/quality_analysis.js.erb index 89d8685cf..c9427c246 100644 --- a/app/views/repositories/quality_analyses.js.erb +++ b/app/views/repositories/quality_analysis.js.erb @@ -1,4 +1,4 @@ -$('#ajax-modal').html('<%= escape_javascript( render :partial => 'repositories/quality_analyses', :locals => {}) %>'); +$('#ajax-modal').html('<%= escape_javascript( render :partial => 'repositories/quality_analysis', :locals => {}) %>'); showModal('ajax-modal', '615px'); $('#ajax-modal').siblings().remove(); $('#ajax-modal').before(""); diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb index d1c041d73..1e874544a 100644 --- a/app/views/repositories/show.html.erb +++ b/app/views/repositories/show.html.erb @@ -2,7 +2,7 @@

<%= render :partial => 'breadcrumbs', :locals => {:path => @path, :kind => 'dir', :revision => @rev} %>

ZIP下载 - <%= link_to "质量分析", quality_analyses_path(:id => @project.id, :repository_id => @repository.identifier), :remote => true, :class => "btn_zipdown fr" %> + <%= link_to "质量分析", quality_analysis_path(:id => @project.id, :repository_id => @repository.identifier), :remote => true, :class => "btn_zipdown fr" %>
diff --git a/db/migrate/20160622015019_create_quality_analyses.rb b/db/migrate/20160622015019_create_quality_analyses.rb new file mode 100644 index 000000000..6316d5764 --- /dev/null +++ b/db/migrate/20160622015019_create_quality_analyses.rb @@ -0,0 +1,11 @@ +class CreateQualityAnalyses < ActiveRecord::Migration + def change + create_table :quality_analyses do |t| + t.integer :project_id + t.string :author_login + t.string :rep_identifier + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index e8e7e25cb..51e0682d0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20160613065840) do +ActiveRecord::Schema.define(:version => 20160622015019) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -1833,6 +1833,14 @@ ActiveRecord::Schema.define(:version => 20160613065840) do add_index "protected_branches", ["project_id"], :name => "index_protected_branches_on_project_id" + create_table "quality_analyses", :force => true do |t| + t.integer "project_id" + t.string "author_login" + t.string "rep_identifier" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "queries", :force => true do |t| t.integer "project_id" t.string "name", :default => "", :null => false diff --git a/spec/factories/quality_analyses.rb b/spec/factories/quality_analyses.rb new file mode 100644 index 000000000..a48e6e33f --- /dev/null +++ b/spec/factories/quality_analyses.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :quality_analyasis, class: 'QualityAnalysis' do + project_id 1 + author_login "MyString" + rep_identifier "MyString" + end +end diff --git a/spec/models/quality_analysis_spec.rb b/spec/models/quality_analysis_spec.rb new file mode 100644 index 000000000..d18ede452 --- /dev/null +++ b/spec/models/quality_analysis_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe QualityAnalysis, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end