diff --git a/app/controllers/projects/project/project_controller.rb b/app/controllers/projects/project/project_controller.rb index 15e0b4762..29daadb8a 100644 --- a/app/controllers/projects/project/project_controller.rb +++ b/app/controllers/projects/project/project_controller.rb @@ -1,6 +1,9 @@ class Projects::Project::ProjectController < Projects::Project::BaseController def index - authorize @project (render :error_github) if not @project.github_data end + + def commit + redirect_to @project.github_data.html_url + "/commit/" + params[:sha] + end end \ No newline at end of file diff --git a/app/controllers/projects/projects_controller.rb b/app/controllers/projects/projects_controller.rb index 007d04d76..e80d2f32a 100644 --- a/app/controllers/projects/projects_controller.rb +++ b/app/controllers/projects/projects_controller.rb @@ -7,7 +7,6 @@ class Projects::ProjectsController < Projects::BaseController def index authorize :project - Project.fetch_github_data_on_find = false @projects = ProjectPolicy::Scope.new(current_user, Project).membered.search(params[:search]) respond_to do |format| format.html { diff --git a/app/helpers/build_lists_helper.rb b/app/helpers/build_lists_helper.rb index 98dbb726f..1d8b2714d 100644 --- a/app/helpers/build_lists_helper.rb +++ b/app/helpers/build_lists_helper.rb @@ -271,10 +271,10 @@ module BuildListsHelper branches_kind = I18n.t('layout.git.repositories.branches') tags_kind = I18n.t('layout.git.repositories.tags') res = [] - project.repo.branches.each do |br| + project.github_branches.each do |br| res << { name: br.name, kind: branches_kind } end - project.repo.tags.each do |t| + project.github_tags.each do |t| res << { name: t.name, kind: tags_kind } end res.sort_by { |e| e[:name] } diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 562474285..1a111918c 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -87,12 +87,6 @@ class BuildList < ActiveRecord::Base before_validation :prepare_extra_build_lists, on: :create before_validation :prepare_extra_params, on: :create before_validation :prepare_auto_publish_status, on: :create - after_validation -> { - errors.each do |x, y| - puts x - puts y - end - } LIVE_TIME = 4.week # for unpublished MAX_LIVE_TIME = 3.month # for published diff --git a/app/models/concerns/commit_and_version.rb b/app/models/concerns/commit_and_version.rb index e2a965841..c57ce3d1b 100644 --- a/app/models/concerns/commit_and_version.rb +++ b/app/models/concerns/commit_and_version.rb @@ -4,7 +4,7 @@ module CommitAndVersion included do validate -> { - if project && (commit_hash.blank? || project.repo.commit(commit_hash).blank?) + if project && (commit_hash.blank? || (not project.github_get_commit(commit_hash))) errors.add :commit_hash, I18n.t('flash.build_list.wrong_commit_hash', commit_hash: commit_hash) end } @@ -17,7 +17,21 @@ module CommitAndVersion def set_commit_and_version if project && project_version.present? && commit_hash.blank? - self.commit_hash = project.repo.commits(project_version).try(:first).try(:id) + res = "" + project.github_branches.each do |br| + if br.name == project_version + res = br.commit.sha + end + end + if res.empty? + project.github_tags.each do |br| + if br.name == project_version + res = br.commit.sha + end + end + end + self.commit_hash = res + #self.commit_hash = project.repo.commits(project_version).try(:first).try(:id) elsif project_version.blank? && commit_hash.present? self.project_version = commit_hash end diff --git a/app/models/concerns/project/github_api.rb b/app/models/concerns/project/github_api.rb new file mode 100644 index 000000000..20c5a0297 --- /dev/null +++ b/app/models/concerns/project/github_api.rb @@ -0,0 +1,25 @@ +module Project::GithubApi + extend ActiveSupport::Concern + + def github_data + Github.repos.get user: org, repo: name rescue nil + end + + def github_branches + Github.repos.branches user: org, repo: name rescue nil + end + + def github_tags + Github.repos.tags user: org, repo: name rescue nil + end + + def github_get_commit(hash) + Github.repos.commits.list user: org, repo: name, sha: hash rescue nil + end + + private + + def org + github_organization || APP_CONFIG["github_organization"] + end +end \ No newline at end of file diff --git a/app/models/project.rb b/app/models/project.rb index 0a85611cc..b0f5c73ad 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -9,6 +9,7 @@ class Project < ActiveRecord::Base include EventLoggable include Project::DefaultBranch include Project::Finders + include Project::GithubApi VISIBILITIES = ['open', 'hidden'] MAX_OWN_PROJECTS = 32000 @@ -67,15 +68,6 @@ class Project < ActiveRecord::Base Project.perform_later :low, :run_mass_import, url, srpms_list, visibility, owner, add_to_repository_id end - def github_data - org = github_organization || APP_CONFIG["github_organization"] - begin - Github.repos.get user: org, repo: name - rescue - nil - end - end - def name_with_owner "#{owner_uname || owner.uname}/#{name}" end @@ -129,9 +121,10 @@ class Project < ActiveRecord::Base end def git_project_address auth_user - opts = default_url_options - opts.merge!({user: auth_user.authentication_token, password: ''}) unless self.public? - Rails.application.routes.url_helpers.project_url(self.name_with_owner, opts) + '.git' + github_data.git_url + #opts = default_url_options + #opts.merge!({user: auth_user.authentication_token, password: ''}) unless self.public? + #Rails.application.routes.url_helpers.project_url(self.name_with_owner, opts) + '.git' #path #share by NFS end diff --git a/app/policies/project_policy.rb b/app/policies/project_policy.rb index 80d63bff3..73e8c407f 100644 --- a/app/policies/project_policy.rb +++ b/app/policies/project_policy.rb @@ -14,6 +14,8 @@ class ProjectPolicy < ApplicationPolicy return true if record.owner.is_a?(Group) && user_group_ids.include?(record.owner_id) local_reader? end + + alias_method :commit?, :show? alias_method :read?, :show? alias_method :archive?, :show? alias_method :get_id?, :show? diff --git a/config/initializers/redis.rb b/config/initializers/redis.rb index 848b630a2..443b16b4d 100644 --- a/config/initializers/redis.rb +++ b/config/initializers/redis.rb @@ -1,5 +1,7 @@ class Redis def self.connect! + puts ENV["REDIS_URL"] + puts ENV["REDIS_URL"].presence url = ENV["REDIS_URL"].presence || "redis://localhost:6379/#{::Rails.env.test? ? 1 : 0}" opts = { url: url } diff --git a/config/routes.rb b/config/routes.rb index da5c57851..a0e3cbff7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -322,6 +322,8 @@ Rails.application.routes.draw do delete '/remove_user' => 'projects#remove_user', as: :remove_user_project get '/' => 'project/project#index', as: :project + get '/commit/:sha' => 'project/project#commit', as: :commit + get '/tree' => 'project/project#index', as: :tree get '/tree2' => 'project/project#index', as: :project_issues get '/tree3' => 'project/project#index', as: :project_pull_requests