This commit is contained in:
duratarskeyk 2015-12-15 06:27:57 +00:00
parent eb89b7d653
commit 98e4dc1730
10 changed files with 58 additions and 24 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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] }

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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?

View File

@ -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 }

View File

@ -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