From 72e8faa988ad684b5cfc014e8db9f61da336bf88 Mon Sep 17 00:00:00 2001 From: Wedge Date: Tue, 29 Dec 2015 22:22:17 +0300 Subject: [PATCH] Increase release tag on github(wip) --- Gemfile | 5 +- Gemfile.lock | 10 +--- app/models/build_list.rb | 9 ++- app/models/concerns/commit_and_version.rb | 1 - app/models/concerns/git.rb | 12 ++-- app/models/concerns/project/default_branch.rb | 54 +---------------- app/models/concerns/project/github_api.rb | 28 +++++++++ app/models/mass_build.rb | 1 + app/models/project.rb | 60 +------------------ app/views/projects/base/_submenu.html.slim | 2 +- config/application.rb | 1 - 11 files changed, 49 insertions(+), 134 deletions(-) diff --git a/Gemfile b/Gemfile index 05e6eb8dc..1b3f940c4 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source 'https://rubygems.org' +source 'http://rubygems.org' gem 'rails' @@ -95,12 +95,11 @@ gem 'sitemap_generator' gem 'codemirror-rails', '~> 4.5' -source 'https://rails-assets.org' do +source 'http://rails-assets.org' do gem 'rails-assets-notifyjs' end gem 'rack-utf8_sanitizer' -gem 'web-console', '~> 2.0' #github api gem 'github_api' diff --git a/Gemfile.lock b/Gemfile.lock index ae491e402..c6ba884f1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -43,8 +43,8 @@ GIT posix-spawn (~> 0.3.6) GEM - remote: https://rubygems.org/ - remote: https://rails-assets.org/ + remote: http://rubygems.org/ + remote: http://rails-assets.org/ specs: RedCloth (4.2.9) actionmailer (4.2.2) @@ -649,11 +649,6 @@ GEM rack (>= 1.0.0) warden (1.2.3) rack (>= 1.0) - web-console (2.2.1) - activemodel (>= 4.0) - binding_of_caller (>= 0.7.2) - railties (>= 4.0) - sprockets-rails (>= 2.0, < 4.0) webmock (1.21.0) addressable (>= 2.3.6) crack (>= 0.3.2) @@ -775,7 +770,6 @@ DEPENDENCIES timecop uglifier underscore-rails - web-console (~> 2.0) webmock whenever wikicloth diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 1a111918c..06987d252 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -562,12 +562,11 @@ class BuildList < ActiveRecord::Base include_repos_hash["container_#{bl.id}"] = insert_token_to_path(path, bl.save_to_platform) end - git_project_address = project.git_project_address user - # git_project_address.gsub!(/^http:\/\/(0\.0\.0\.0|localhost)\:[\d]+/, 'https://abf.rosalinux.ru') unless Rails.env.production? - + git_project_address = project.git_project_address cmd_params = { - 'GIT_PROJECT_ADDRESS' => git_project_address, + 'PACKAGE' => project.name, + 'GIT_REPO' => git_project_address, 'COMMIT_HASH' => commit_hash, 'USE_EXTRA_TESTS' => use_extra_tests?, 'SAVE_BUILDROOT' => save_buildroot?, @@ -584,7 +583,7 @@ class BuildList < ActiveRecord::Base sha1 = build_for_platform.cached_chroot(arch.name) cmd_params.merge!('CACHED_CHROOT_SHA1' => sha1) if sha1.present? end - cmd_params = cmd_params.map{ |k, v| "#{k}='#{v}'" }.join(' ') + #cmd_params = cmd_params.map{ |k, v| "#{k}='#{v}'" }.join(' ') { id: id, diff --git a/app/models/concerns/commit_and_version.rb b/app/models/concerns/commit_and_version.rb index c57ce3d1b..e2d120da1 100644 --- a/app/models/concerns/commit_and_version.rb +++ b/app/models/concerns/commit_and_version.rb @@ -31,7 +31,6 @@ module CommitAndVersion 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/git.rb b/app/models/concerns/git.rb index 2509b762f..d426d56e4 100644 --- a/app/models/concerns/git.rb +++ b/app/models/concerns/git.rb @@ -34,13 +34,13 @@ module Git repo.tags.map(&:name) + repo.branches.map(&:name) end - def find_blob_and_raw_of_spec_file(project_version) - blob = repo.tree(project_version).contents.find{ |n| n.is_a?(Grit::Blob) && n.name =~ /.spec$/ } - return unless blob + #def find_blob_and_raw_of_spec_file(project_version) + # blob = repo.tree(project_version).contents.find{ |n| n.is_a?(Grit::Blob) && n.name =~ /.spec$/ } + # return unless blob - raw = Grit::GitRuby::Repository.new(repo.path).get_raw_object_by_sha1(blob.id) - [blob, raw] - end + # raw = Grit::GitRuby::Repository.new(repo.path).get_raw_object_by_sha1(blob.id) + # [blob, raw] + #end def create_branch(new_ref, from_ref, user) return false if new_ref.blank? || from_ref.blank? || !(from_commit = repo.commit(from_ref)) diff --git a/app/models/concerns/project/default_branch.rb b/app/models/concerns/project/default_branch.rb index bb0aaf902..5f5224be7 100644 --- a/app/models/concerns/project/default_branch.rb +++ b/app/models/concerns/project/default_branch.rb @@ -6,12 +6,6 @@ module Project::DefaultBranch include DefaultBranchable - included do - validate :check_default_branch - - after_update :set_new_git_head - end - ###################################### # Instance methods # ###################################### @@ -19,10 +13,8 @@ module Project::DefaultBranch # Public: Get default branch according to owner configs. # # Returns found String branch name. + def resolve_default_branch - return default_branch unless owner.is_a?(Group) && owner.default_branch.present? - return default_branch unless repo.branches.map(&:name).include?(owner.default_branch) - return owner.default_branch unless default_branch.present? default_branch == 'master' ? owner.default_branch : default_branch end @@ -33,47 +25,7 @@ module Project::DefaultBranch # # Returns found String branch name. def project_version_for(save_to_platform, build_for_platform) - if repo.commits("#{save_to_platform.default_branch}").try(:first).try(:id) - save_to_platform.default_branch - elsif repo.commits("#{build_for_platform.default_branch}").try(:first).try(:id) - build_for_platform.default_branch - else - resolve_default_branch - end + return save_to_platform.default_branch if save_to_platform.name != build_for_platform.name + build_for_platform.default_branch end - - # Public: Finds default head. - # - # treeish - The String treeish. - # - # Returns found String head. - def default_head(treeish = nil) # maybe need change 'head'? - # Attention! - # repo.commit(nil) => - # repo.commit(nil.to_s) => nil - return treeish if treeish.present? && repo.commit(treeish).present? - if repo.branches_and_tags.map(&:name).include?(treeish || resolve_default_branch) - treeish || resolve_default_branch - else - repo.branches_and_tags[0].try(:name) || resolve_default_branch - end - end - - protected - - # Private: Set git head. - def set_new_git_head - if default_branch_changed? && repo.branches.map(&:name).include?(default_branch) - repo.git.send(:'symbolic-ref', {}, 'HEAD', "refs/heads/#{default_branch}") - Project.project_aliases(self).update_all default_branch: default_branch - end - end - - # Private: Validation for checking that the default branch is exist. - def check_default_branch - if self.repo.branches.count > 0 && self.repo.branches.map(&:name).exclude?(self.default_branch) - errors.add :default_branch, I18n.t('activerecord.errors.project.default_branch') - end - end - end diff --git a/app/models/concerns/project/github_api.rb b/app/models/concerns/project/github_api.rb index 36fbe760c..225714f1a 100644 --- a/app/models/concerns/project/github_api.rb +++ b/app/models/concerns/project/github_api.rb @@ -1,3 +1,5 @@ +require 'base64' + module Project::GithubApi extend ActiveSupport::Concern @@ -13,10 +15,36 @@ module Project::GithubApi Github.repos.tags user: github_get_organization, repo: name rescue nil end + def github_branch(branch_name) + Github.repos.branch user: github_get_organization, repo: name, branch: branch_name rescue nil + end + def github_get_commit(hash) Github.repos.commits.list user: github_get_organization, repo: name, sha: hash rescue nil end + def github_tree(hash) + Github.git_data.trees.get user: github_get_organization, repo: name, sha: hash rescue nil + end + + def find_blob_and_raw_of_spec_file(project_version) + return unless branch = github_branch(project_version) + commit_sha = branch.commit.sha + return unless root_tree = github_tree(commit_sha) + spec_file = root_tree.tree.select do |item| + item.type=="blob" and item.path =~ /.spec$/ + end + return if spec_file.empty? + spec_file_sha = spec_file[0].sha + blob_data = Github.git_data.blobs.get user: github_get_organization, repo: name, sha: spec_file_sha rescue return nil + content = Base64.decode64(blob_data.content).gsub('\n', "\n") + [spec_file_sha, content] + end + + def update_file(path, data, options = {}) + + end + def github_get_organization return github_organization if github_organization.presence APP_CONFIG['github_organization'] diff --git a/app/models/mass_build.rb b/app/models/mass_build.rb index 3e53e6f31..bff902ea1 100644 --- a/app/models/mass_build.rb +++ b/app/models/mass_build.rb @@ -86,6 +86,7 @@ class MassBuild < ActiveRecord::Base return unless start # later with resque arches_list = arch_names ? Arch.where(name: arch_names.split(', ')) : Arch.all + projects_list.lines.each do |name| next if name.blank? name.chomp!; name.strip! diff --git a/app/models/project.rb b/app/models/project.rb index 9db122f98..8434695d9 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -61,7 +61,6 @@ class Project < ActiveRecord::Base before_save -> { self.owner_uname = owner.uname if owner_uname.blank? || owner_id_changed? || owner_type_changed? } before_create :set_maintainer after_save :attach_to_personal_repository - after_update -> { update_path_to_project(name_was) }, if: :name_changed? attr_accessor :url, :srpms_list, :mass_import, :add_to_repository_id, :mass_create @@ -101,12 +100,6 @@ class Project < ActiveRecord::Base @platforms ||= repositories.map(&:platform).uniq end - def in_main_platform? - platforms.map do |platform| - platform.platform_type - end.include?('main') - end - def admins admins = self.collaborators.where("relations.role = 'admin'") grs = self.groups.where("relations.role = 'admin'") @@ -125,12 +118,8 @@ class Project < ActiveRecord::Base owner == user end - def git_project_address auth_user - 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 + def git_project_address + "git://github.com/" + github_get_organization + "/" + name + ".git" end def build_for(mass_build, repository_id, arch = Arch.find_by(name: 'i586'), priority = 0, increase_rt = false) @@ -170,30 +159,6 @@ class Project < ActiveRecord::Base build_list.save end - def get_project_tag_sha1(tag, format) - format_id = ProjectTag::FORMATS["#{tag_file_format(format)}"] - project_tag = project_tags.where(tag_name: tag.name, format_id: format_id).first - - return project_tag.sha1 if project_tag && project_tag.commit_id == tag.commit.id && FileStoreService::File.new(sha1: project_tag.sha1).exist? - - archive = archive_by_treeish_and_format tag.name, format - sha1 = FileStoreService::File.new(data: archive).save - return nil if sha1.blank? - - if project_tag - project_tag.destroy_files_from_file_store(project_tag.sha1) - project_tag.update_attributes(sha1: sha1) - else - project_tags.create( - tag_name: tag.name, - format_id: format_id, - commit_id: tag.commit.id, - sha1: sha1 - ) - end - return sha1 - end - def archive_by_treeish_and_format(treeish, format) @archive ||= create_archive treeish, format end @@ -319,25 +284,4 @@ class Project < ActiveRecord::Base end end - def update_path_to_project(old_name) - new_name, new_path = name, path - self.name = old_name - old_path = path - self.name = new_name - FileUtils.mv old_path, new_path, force: true if Dir.exists?(old_path) - - pull_requests_old_path = File.join(APP_CONFIG['git_path'], 'pull_requests', owner.uname, old_name) - if Dir.exists?(pull_requests_old_path) - FileUtils.mv pull_requests_old_path, - File.join(APP_CONFIG['git_path'], 'pull_requests', owner.uname, new_name), - force: true - end - - PullRequest.where(from_project_id: id).update_all(from_project_name: new_name) - - PullRequest.where(from_project_id: id).each{ |p| p.update_relations(old_name) } - pull_requests.where('from_project_id != to_project_id').each(&:update_relations) - end - later :update_path_to_project, queue: :middle - end diff --git a/app/views/projects/base/_submenu.html.slim b/app/views/projects/base/_submenu.html.slim index f4c214baf..ff7e6cf7f 100644 --- a/app/views/projects/base/_submenu.html.slim +++ b/app/views/projects/base/_submenu.html.slim @@ -1,5 +1,5 @@ - content_for :submenu do - - act = action_name.to_sym; contr = controller_name.to_sym; treeish = @project.default_head(params[:treeish]) + - act = action_name.to_sym; contr = controller_name.to_sym; - github_success = @project.github_data != nil - github_base_url = @project.github_data.html_url unless not github_success nav.navbar.navbar-default role='navigation' diff --git a/config/application.rb b/config/application.rb index 1ba712598..d1193cd41 100644 --- a/config/application.rb +++ b/config/application.rb @@ -67,6 +67,5 @@ module Rosa config.log_redis = false config.angular_templates.ignore_prefix = 'angularjs/templates/' - config.web_console.whitelisted_ips = '127.0.0.0/24' end end