diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 491699cd3..d1f3ffa7f 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -34,16 +34,18 @@ class RepositoriesController < ApplicationController 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, :export_rep_static] + # 连接gitlab + # before_filter :connect_gitlab, :only => [:quality_analysis, :commit_diff] + 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_analysis] - # 链接gitlab - before_filter :connect_gitlab, :only => [:quality_analysis, :show, :commit_diff, :find_project_repository] # 版本库新增权限 before_filter :show_rep, :only => [:show] accept_rss_auth :revisions # hidden repositories filter // 隐藏代码过滤器 - before_filter :check_hidden_repo, :only => [:show, :stats, :revisions, :revision, :diff ] + before_filter :check_hidden_repo, :only => [:stats, :revisions, :revision, :diff ] helper :repositories include RepositoriesHelper helper :project_score @@ -329,7 +331,7 @@ update 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 + @gitlab_default_branch = @g_project.default_branch # language = params[:language] # branch = params[:branch] # path = params[:path] @@ -375,7 +377,23 @@ update end def show - ## TODO: the below will move to filter, done. + # 获取版本库目录结构 + @entries = @repository.entries(@path, @rev) + @changesets_latest_coimmit = @g.commits(@project.gpid, :ref_name => @rev)[0] + + # 总的提交数 + @changesets_all_count = @g.user_static(@project.gpid, :rev => @rev).count + + # 获取默认分支 + @g_default_branch = @g_project.default_branch.nil? ? "master" : @g_project.default_branch + + @creator = @project.owner.to_s + gitlab_address = Redmine::Configuration['gitlab_address'] + # REDO:需优化,仅测试用 + @zip_path = Gitlab.endpoint.to_s + "/projects/" + @project.gpid.to_s + "/repository/archive?&private_token=" + Gitlab.private_token + @repos_url = gitlab_address.to_s+"/" + @creator + "/" + @repository.identifier+"."+"git" + + # 一些数据的异步同步更新 # 访问版本庫后更新project_score表数据;changeset_num为提交总数 project_score = @project.project_score if project_score.nil? @@ -387,26 +405,7 @@ update update_commits_date(@project, @changesets_latest_coimmit) end - # 获取版本库目录结构 - #@entries = @repository.entries(@path, @rev) - if request.xhr? - #@entries ? render(:partial => 'dir_list_content') : render(:nothing => true) - else - @changesets = @g.commits(@project.gpid, :ref_name => @rev) - # 最近一次提交 - @changesets_latest_coimmit = @changesets[0] - g_project = @g.project(@project.gpid) - # 总的提交数 - @changesets_all_count = @g.user_static(@project.gpid, :rev => @rev).count - # 获取默认分支 - @g_default_branch = g_project.default_branch.nil? ? "master" : g_project.default_branch - @creator = @project.owner.to_s - gitlab_address = Redmine::Configuration['gitlab_address'] - # REDO:需优化,仅测试用 - @zip_path = Gitlab.endpoint.to_s + "/projects/" + @project.gpid.to_s + "/repository/archive?&private_token=" + Gitlab.private_token - @repos_url = gitlab_address.to_s+"/" + @creator + "/" + @repository.identifier+"."+"git" - render :layout => 'base_projects' - end + render :layout => 'base_projects' end alias_method :browse, :show @@ -662,7 +661,7 @@ update @g_project = @g.project(@project.gpid) end rescue => e - logger.error("failed to connect gitlab ==> #{e}") + logger.error("connect gitlab failed ==> #{e}") end end @@ -681,31 +680,19 @@ update end REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i + REP_TYPE = "Repository::Gitlab" + # 获取项目、版本库、路劲、默认分支 def find_project_repository @project = Project.find(params[:id]) - if params[:repository_id].present? - @repository = @project.repositories.find_by_identifier_param(params[:repository_id]) - else - # 多版本库,如果一个版本库为空则去下一个 - rep_count = @project.repositories.count - if @project.repository.nil? - for i in 0..rep_count - unless @project.repositories[i].nil? - @repository = @project.repositories[i] - break - end - end - else - @repository = @project.repository - end - end - (render_404; return false) unless @repository + @repository = Repository.where(:type => REP_TYPE, :project_id => @project).first + (render_404; return false) unless (@repository || @project.gpid) @path = params[:path].is_a?(Array) ? params[:path].join('/') : params[:path].to_s + @g = Gitlab.client + @g_project = @g.project(@project.gpid) + @g_default_branch = @g_project.default_branch # gitlab端获取默认分支 - g = Gitlab.client - gitlab_branchs = g.project(@project.gpid).default_branch - @project.gpid.nil? ? (@rev = params[:rev].blank? ? @repository.default_branch : params[:rev].to_s.strip) : (@rev = params[:rev].blank? ? gitlab_branchs : params[:rev].to_s.strip) + @rev = params[:rev].blank? ? @g_default_branch : params[:rev].to_s.strip @rev_to = params[:rev_to] unless @rev.to_s.match(REV_PARAM_RE) && @rev_to.to_s.match(REV_PARAM_RE) if @repository.branches.blank?