diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 62b076754..8187055be 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -239,17 +239,18 @@ class AccountController < ApplicationController end def resendmail - status = 1 + result = {:status=>1, :email=>""} user = User.find(params[:user]) if params[:user] + result[:email] = user.mail token = Token.new(:user => user, :action => "register") if token.save # Mailer.run.register(token) Mailer.register(token).deliver else yield if block_given? - status = 0 + result[:status] = 0 end - render :json => status + render :json => result end def email_activation diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 960bc61e6..a6b5f09cf 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -612,7 +612,7 @@ class AttachmentsController < ApplicationController @attachment.container.board.course) @course = @attachment.container.board.course else - unless @attachment.container_type == 'Bid' || @attachment.container_type == 'Organization' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication' || @attachment.container_type == 'PhoneAppVersion' || @attachment.container_type == 'StudentWorksScore'|| @attachment.container_type == 'StudentWork' + unless @attachment.container_type == 'Syllabus' || @attachment.container_type == 'Bid' || @attachment.container_type == 'Organization' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication' || @attachment.container_type == 'PhoneAppVersion' || @attachment.container_type == 'StudentWorksScore'|| @attachment.container_type == 'StudentWork' @project = @attachment.project end end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 8664a1372..cb86f1165 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -653,12 +653,12 @@ class ProjectsController < ApplicationController def update @project.safe_attributes = params[:project] @project.organization_id = params[:organization_id] - params[:project][:is_public] ? @project.is_public = 1 : @project.is_public = 0 - params[:project][:hidden_repo] ? @project.hidden_repo = 1 : @project.hidden_repo = 0 + params[:project][:is_public] == "on" ? @project.is_public = 1 : @project.is_public = 0 + params[:project][:hidden_repo] == "on" ? @project.hidden_repo = 1 : @project.hidden_repo = 0 # 更新公开私有时同步gitlab公开私有 - if !@project.gpid.nil? && @project.is_public != (params[:project][:is_public] == "on" ? true : false) + if !@project.gpid.nil? && @project.is_public != (params[:project][:is_public] == "on" ? 1 : 0) g = Gitlab.client - params[:project][:is_public] ? g.edit_project(@project.gpid, 20, params[:branch]) : g.edit_project(@project.gpid, 0, params[:branch]) + params[:project][:is_public] == "on" ? g.edit_project(@project.gpid, 20, params[:branch]) : g.edit_project(@project.gpid, 0, params[:branch]) end # end if validate_parent_id && @project.save diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb index a9b93269a..bec66aeff 100644 --- a/app/controllers/quality_analysis_controller.rb +++ b/app/controllers/quality_analysis_controller.rb @@ -1,9 +1,11 @@ class QualityAnalysisController < ApplicationController before_filter :find_project_by_project_id#, :except => [:getattachtype] + before_filter :find_quality_analysis, :only => [:edit, :update_jenkins_job] before_filter :authorize - before_filter :connect_jenkins, :only => [:create] + before_filter :connect_jenkins, :only => [:create, :edit, :update_jenkins_job, :index] layout "base_projects" include ApplicationHelper + include QualityAnalysisHelper require 'jenkins_api_client' require 'nokogiri' require 'json' @@ -13,12 +15,14 @@ class QualityAnalysisController < ApplicationController end + # params 说明:{identifier:版本库名} def create begin user_name = User.find(params[:user_id]).try(:login) identifier = params[:identifier] rep_id = params[:rep_id] - # REDO + + # job_name and sonar_name 前者为job名字,后者为jenkins配置名 job_name = "#{user_name}-#{rep_id}" sonar_name = "#{user_name}:#{rep_id}" @@ -38,25 +42,43 @@ class QualityAnalysisController < ApplicationController sonar.sourceEncoding=utf-8" git_url = @gitlab_address.to_s+"/"+@project.owner.to_s+"/"+ identifier + "."+"git" - # modify config.yml + # 替换配置文件 @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 - # return '200' if successed + # jenkins job创建 jenkins_job = @client.job.create("#{job_name}", @doc.to_xml) + logger.info("Jenkins status of create ==> #{jenkins_job}") - # replace gitlab hook + # 将地址作为hook值添加到gitlab @g.add_project_hook(@project.gpid, @jenkins_address + "/project/#{job_name}") - # build job - logger.error("Jenkins status of create ==> #{jenkins_job}") - # return '201' if build successed + # job创建完成后自动运行job,如果运行成功则返回‘200’ code = @client.job.build("#{job_name}") logger.error("build result ==> #{code}") - d = @client.delete("#{job_name}") if jenkins_job == '200' && code != '201' + + # 判断调用sonar分析是否成功 + # 等待启动时间处理, 最长时间为30分钟 + for i in 0..60 do + sleep(60) + @current_build_status = @client.job.get_current_build_status("#{job_name}") + if (@current_build_status != "not_run" || @current_build_status != "running") + break + if i == 60 + @build_console_result = false + break + end + end + end + + @console_build = @client.job.get_console_output("#{job_name}", build_num = 0, start = 0, mode = 'text') + logger.info("@current_build_status is ==> #{@current_build_status}") + logger.info("@console_build is ==> #{@console_build}") + + d = @client.job.delete("#{job_name}") if jenkins_job == '200' && code != '201' logger.error("delete result ==> #{code}") - if qa.blank? && code == '201' + if qa.blank? && @current_build_status == "success" QualityAnalysis.create(:project_id => @project.id, :author_login => user_name, :rep_identifier => identifier, :sonar_version => version, :path => path, :branch => branch, :language => language, :sonar_name => "#{user_name}:#{rep_id}") else @@ -66,10 +88,10 @@ class QualityAnalysisController < ApplicationController rescue => e puts e end - # respond_to do |format| - # #format.html{redirect_to project_quality_analysis_path(:project_id => @project.id, :resource_id => sonar_name, :branch => branch)} - # format.js - # end + respond_to do |format| + format.html{redirect_to project_quality_analysis_path(:project_id => @project.id, :resource_id => sonar_name, :branch => branch, :current_build_status => @current_build_status, :job_name => job_name)} + # format.js{redirect_to project_quality_analysis_path(:project_id => @project.id, :resource_id => sonar_name, :branch => branch)} + end end # get language type @@ -85,11 +107,68 @@ class QualityAnalysisController < ApplicationController end end + def edit + @g = Gitlab.client + gitlab_branches = @g.branches(@project.gpid) + @branch_names = gitlab_branches.map{|b| b.name} + @gitlab_default_branch = @g.project(@project.gpid).default_branch + end + + # 更新Jenkins job,主要包括相关配置文件参数的更新,Trustie平台数据的更新 + def update_jenkins_job + begin + rep_id = Repository.where(:project_id => @project.id).first.try(:id) + logger.error("#############################===>666") + sonar_name = @quality_analysis.sonar_name + job_name = "#{@quality_analysis.author_login}-#{rep_id}" + version = @quality_analysis.sonar_version + path = params[:path].blank? ? "./" : params[:path] + language = swith_language_type(params[:language]) + branch = params[:branch] + identifier = @quality_analysis.rep_identifier + properties = "sonar.projectKey=#{sonar_name} + sonar.projectName=#{sonar_name} + sonar.projectVersion=#{version} + sonar.sources=#{path} + sonar.language=#{language.downcase} + sonar.sourceEncoding=utf-8" + git_url = @gitlab_address.to_s+"/"+@project.owner.to_s+"/"+ identifier + "."+"git" + + # modify config.yml + @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 + + # update成功则返回 ‘200’ + jenkins_job = @client.job.update("#{job_name}", @doc.to_xml) + get_current_build_status = @client.job.get_current_build_status("Hjqreturn-1280") + logger.error("Failed to update job: ==> #{jenkins_job}") unless jenkins_job == '200' + + # 数据更新到Trustie数据库 + if jenkins_job == '200' + logger.info("quality_ananlysis will be updated: ==> #{jenkins_job}") + @quality_analysis.path = path + @quality_analysis.language = language + @quality_analysis.branch = branch + @quality_analysis.save + end + rescue Exception => e + logger.error("Update jenkins job: #{e}") + end + respond_to do |format| + format.html{redirect_to project_quality_analysis_path(:project_id => @project.id)} + format.js + end + end + # resource_id: login + @repository.id def index begin + @branch = params[:branch] @resource_id = params[:resource_id] @sonar_address = Redmine::Configuration['sonar_address'] + @jenkins_address = Redmine::Configuration['jenkins_address'] if params[:resource_id].nil? @name_flag = true projects_date = open(@sonar_address + "/api/projects/index").read @@ -97,6 +176,10 @@ class QualityAnalysisController < ApplicationController @quality_analyses = QualityAnalysis.where(:project_id => @project.id).select{|qa| arr.include?(qa.sonar_name)} else + if params[:current_build_status] == "failure" + job_name = params[:job_name] + @console_build = @client.job.get_console_output("#{job_name}", build_num = 0, start = 0, mode = 'text')["output"] + end complexity_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=sqale_rating,function_complexity,duplicated_lines_density,comment_lines_density,sqale_index,lines,file_line,files,functions,classes,directories").read @complexity =JSON.parse(complexity_date).first issue_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=blocker_violations,critical_violations,major_violations,minor_violations,info_violations,violations").read @@ -115,6 +198,14 @@ class QualityAnalysisController < ApplicationController render_404 end + def find_quality_analysis + begin + @quality_analysis = QualityAnalysis.find(params[:id]) + rescue + render_404 + end + end + # Authorize the user for the requested action def authorize(ctrl = params[:controller], action = params[:action], global = false) unless @project.archived? && @project.gpid.nil? diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 7c3acb2cc..d0904ddf5 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -360,11 +360,6 @@ update end def show - # sonar_address = Redmine::Configuration['sonar_address'] - # projects_date = open(sonar_address + "/api/projects/index").read - # arr = JSON.parse(projects_date).map {|m| m["nm"]} - # arr.map - ## TODO: the below will move to filter, done. if !User.current.member_of?(@project) && @project.hidden_repo render_403 @@ -379,7 +374,7 @@ update @changesets = g.commits(@project.gpid, :ref_name => @rev) g_project = g.project(@project.gpid) # 总的提交数 - @changesets_all_count = @project.gpid.nil? ? 0 : g_project.commit_count + @changesets_all_count = @project.gpid.nil? ? 0 : commit_count(@project, @rev) @g_default_branch = g_project.default_branch.nil? ? "master" : g_project.default_branch # 访问该页面的是会后则刷新 if @project.project_score.nil? diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1d79d45ce..f29981999 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -803,22 +803,22 @@ module ApplicationHelper end # 获取Gitlab版本库提交总数 - def commit_count(project) + def commit_count(project, branch) g = Gitlab.client #add by hx - if g.commits(project.gpid , :page=>200).count > 0 + if g.commits(project.gpid, :ref_name => @rev , :page=>200).count > 0 count = 4020 - elsif g.commits(project.gpid , :page=>25).count==0 + elsif g.commits(project.gpid , :page=>25, :ref_name => branch).count==0 count = count_commits(project.gpid , 0 , 25) - elsif g.commits(project.gpid , :page=>50).count ==0 + elsif g.commits(project.gpid , :page=>50, :ref_name => branch).count ==0 count = count_commits(project.gpid , 25 , 50)+ 25 * 20 - elsif g.commits(project.gpid , :page=>75).count ==0 + elsif g.commits(project.gpid , :page=>75, :ref_name => branch).count ==0 count = count_commits(project.gpid , 50 , 75)+ 50 * 20 - elsif g.commits(project.gpid , :page=>100).count== 0 + elsif g.commits(project.gpid , :page=>100, :ref_name => branch).count== 0 count = count_commits(project.gpid , 75 , 100) + 75 * 20 - elsif g.commits(project.gpid , :page=>125).count==0 + elsif g.commits(project.gpid , :page=>125, :ref_name => branch).count==0 count = count_commits(project.gpid , 100 , 125) + 100 * 20 - elsif g.commits(project.gpid , :page=>150).count==0 + elsif g.commits(project.gpid , :page=>150, :ref_name => branch).count==0 count = count_commits(project.gpid , 125 , 150) + 125 * 20 else count = count_commits(project.gpid , 150 ,200) + 150 * 20 @@ -832,7 +832,7 @@ module ApplicationHelper if $g.commits(project_id,:page => page).count == 0 break else - count = count + $g.commits(project_id,:page => page).count + count = count + $g.commits(project_id, :ref_name => @rev, :page => page).count end end return count diff --git a/app/helpers/organizations_helper.rb b/app/helpers/organizations_helper.rb index cb06bd688..48b5f068b 100644 --- a/app/helpers/organizations_helper.rb +++ b/app/helpers/organizations_helper.rb @@ -23,7 +23,7 @@ module OrganizationsHelper when 'activity' then return '动态' when 'course' then - return '课程' + return '班级' when 'project' then return '项目' end diff --git a/app/helpers/syllabuses_helper.rb b/app/helpers/syllabuses_helper.rb index 00331e0dc..7e815950b 100644 --- a/app/helpers/syllabuses_helper.rb +++ b/app/helpers/syllabuses_helper.rb @@ -48,17 +48,17 @@ module SyllabusesHelper option6 = [] option1 << "请选择" - option1 << 1 + option1 << 0 option2 << "公共必修课" - option2 << 2 + option2 << 1 option3 << "学科必修课" - option3 << 3 + option3 << 2 option4 << "专业选修课" - option4 << 4 + option4 << 3 option5 << "实践必修课" - option5 << 5 + option5 << 4 option6 << "实践选修课" - option6 << 6 + option6 << 5 type << option1 type << option2 diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index f6bf59af0..f59beb7e5 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -324,15 +324,15 @@ class CoursesService define_error [ 0, '加入成功', 1, '密码错误', - 2, '课程已过期 请联系课程管理员重启课程。', - 3, '您已经加入了课程', - 4, '您加入的课程不存在', + 2, '班级已过期 请联系班级管理员重启班级。', + 3, '您已经加入了班级', + 4, '您加入的班级不存在', 5, '您还未登录', 6, '申请成功,请等待审核完毕', 7, '您已经发送过申请了,请耐心等待', - 8, '您已经是该课程的教师了', - 9, '您已经是该课程的教辅了', - 10, '您已经是该课程的管理员了', + 8, '您已经是该班级的教师了', + 9, '您已经是该班级的教辅了', + 10, '您已经是该班级的管理员了', '未知错误,请稍后再试' ] end diff --git a/app/views/account/email_activation.html.erb b/app/views/account/email_activation.html.erb index d625e7fc9..9655efcf4 100644 --- a/app/views/account/email_activation.html.erb +++ b/app/views/account/email_activation.html.erb @@ -23,9 +23,15 @@ url, {user: id }, function (data) { - console.log("1111111111"); - console.log(data); - $(".email_verify_btn").replaceWith("
激活邮件已发送至您的注册邮箱,请及时登录邮箱进行验证。
"); + //邮箱@之前用a**b格式显示 + var mail = data.email; + var pos = mail.indexOf("@"); + var restr = mail.substring(1,pos-1); + if( mail.split("@")[0].length > 2 ){ + mail = mail.replace(restr,"***"); + } + + $(".email_verify_btn").replaceWith("激活邮件已发送至您的注册邮箱("+mail+"),请及时登录邮箱进行验证。
"); } ); } @@ -37,16 +43,16 @@ pop_up_box(htmlvalue,580,30,50); return; } - $.get( - url, - {user:user,text:$(".email_prompt_mes").val() }, - function (data) { - console.log("2222222"); - console.log(data); - var htmlvalue = "我们将尽快处理好,并通过邮件通知您。感谢您的反馈!
我们将尽快处理好,并通过邮件通知您。感谢您的反馈!
<%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'upload_filename readonly', :readonly=>'readonly')%> <%#= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") %> <%#= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false, :class => 'is_public_checkbox')%> - <%= link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %> + <%= link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "#{i+1}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload', :containerid => "2") %> <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> -
+ <% end %> <% else %> <% container.attachments.each_with_index do |attachment, i| %> - + <% end %> <% end %> <% end %> diff --git a/app/views/courses/join.js.erb b/app/views/courses/join.js.erb index 04a77f87b..ac8b717d1 100644 --- a/app/views/courses/join.js.erb +++ b/app/views/courses/join.js.erb @@ -10,12 +10,12 @@ window.location.href= "<%= Setting.protocol%>://"+"<%= Setting.host_name%>"+"/co <% elsif @state == 1 %> alert("密码错误"); <% elsif @state == 2 %> -alert("课程已过期\n请联系课程管理员重启课程。(在配置课程处)"); +alert("班级已过期\n请联系班级管理员重启班级。(在配置班级处)"); <% elsif @state == 3 %> -alert("您已经加入了课程"); +alert("您已经加入了班级"); window.location.href= "<%= Setting.protocol%>://"+"<%= Setting.host_name%>"+"/courses/" + "<%= @course.id%>" <% elsif @state == 4 %> -alert("您加入的课程不存在"); +alert("您加入的班级不存在"); <% elsif @state == 5 %> alert("您还未登录"); <% elsif @state == 6 %> @@ -25,15 +25,15 @@ hidden_join_course_form(); alert("您已经发送过申请了,请耐心等待"); hidden_join_course_form(); <% elsif @state == 8%> -alert("您已经是该课程的教师了"); +alert("您已经是该班级的教师了"); hidden_join_course_form(); window.location.href= "<%= Setting.protocol%>://"+"<%= Setting.host_name%>"+"/courses/" + "<%= @course.id%>" <% elsif @state == 9%> -alert("您已经是该课程的教辅了"); +alert("您已经是该班级的教辅了"); hidden_join_course_form(); window.location.href= "<%= Setting.protocol%>://"+"<%= Setting.host_name%>"+"/courses/" + "<%= @course.id%>" <% elsif @state == 10%> -alert("您已经是该课程的管理员了"); +alert("您已经是该班级的管理员了"); hidden_join_course_form(); window.location.href= "<%= Setting.protocol%>://"+"<%= Setting.host_name%>"+"/courses/" + "<%= @course.id%>" <% else %> diff --git a/app/views/courses/private_or_public.js.erb b/app/views/courses/private_or_public.js.erb index 4e512a6a0..82180c452 100644 --- a/app/views/courses/private_or_public.js.erb +++ b/app/views/courses/private_or_public.js.erb @@ -9,9 +9,9 @@ } <% else %> <% if @course.is_public? %> - $("#show_course_<%= @course.id %>").attr("title","公开课程:<%= @course.name %>(<%= @course.time.to_s+ @course.term %>)"); + $("#show_course_<%= @course.id %>").attr("title","公开班级:<%= @course.name %>(<%= @course.time.to_s+ @course.term %>)"); <% else %> - $("#show_course_<%= @course.id %>").attr("title","私有课程:<%= @course.name %>(<%= @course.time.to_s+ @course.term %>)"); + $("#show_course_<%= @course.id %>").attr("title","私有班级:<%= @course.name %>(<%= @course.time.to_s+ @course.term %>)"); <% end %> $("#set_course_public_<%= @course.id %>").replaceWith('<%= escape_javascript(link_to @course.is_public == 0 ? "设为公开" : "设为私有", {:controller => "courses", :action => "private_or_public", :id => @course,:user_page => true}, :id => "set_course_public_#{@course.id.to_s}",:remote=>true,:confirm=>"您确定要设置为"+(@course.is_public == 0 ? "公开" : "私有")+"吗") %>'); diff --git a/app/views/layouts/_syllabus_base_info.html.erb b/app/views/layouts/_syllabus_base_info.html.erb index cf4926d82..ae6da2ac3 100644 --- a/app/views/layouts/_syllabus_base_info.html.erb +++ b/app/views/layouts/_syllabus_base_info.html.erb @@ -4,7 +4,7 @@ <% end %>质量等级
@@ -43,25 +43,26 @@+
<%= l(:label_tags_user_name) %><%= link_to ("#{user.name}"),
:controller => "users",:action => "show",:id => user.id%>
diff --git a/app/views/tags/index.html.erb b/app/views/tags/index.html.erb
index 947366eeb..038768a41 100644
--- a/app/views/tags/index.html.erb
+++ b/app/views/tags/index.html.erb
@@ -16,7 +16,7 @@
<% content_for :content do %>