Fix api annonymous access, add fail reason field to build lists and mass builds

This commit is contained in:
Wedge 2016-03-24 18:59:12 +03:00
parent d5180f73d7
commit 455d0d267b
31 changed files with 184 additions and 498 deletions

View File

@ -1,4 +1,5 @@
class Api::V1::ArchesController < Api::V1::BaseController
skip_before_action :check_auth if APP_CONFIG['anonymous_access']
before_action :authenticate_user! unless APP_CONFIG['anonymous_access']
def index

View File

@ -9,6 +9,7 @@ class Api::V1::BuildListsController < Api::V1::BaseController
rerun_tests
show
)
skip_before_action :check_auth, only: %i(show index) if APP_CONFIG['anonymous_access']
skip_before_action :authenticate_user!, only: %i(show index) if APP_CONFIG['anonymous_access']
def show

View File

@ -1,6 +1,7 @@
class Api::V1::GroupsController < Api::V1::BaseController
before_action :authenticate_user!
skip_before_action :check_auth, only: [:show] if APP_CONFIG['anonymous_access']
skip_before_action :authenticate_user!, only: [:show] if APP_CONFIG['anonymous_access']
before_action :load_group, except: %i(index create)

View File

@ -1,4 +1,5 @@
class Api::V1::MaintainersController < Api::V1::BaseController
skip_before_action :check_auth if APP_CONFIG['anonymous_access']
before_action :authenticate_user! unless APP_CONFIG['anonymous_access']
def index

View File

@ -1,5 +1,7 @@
class Api::V1::PlatformsController < Api::V1::BaseController
before_action :authenticate_user!
skip_before_action :check_auth, only: :allowed if APP_CONFIG['anonymous_access']
skip_before_action :check_auth, only: [:show, :platforms_for_build, :members] if APP_CONFIG['anonymous_access']
skip_before_action :authenticate_user!, only: :allowed
skip_before_action :authenticate_user!, only: [:show, :platforms_for_build, :members] if APP_CONFIG['anonymous_access']
before_action :load_platform, except: [:index, :allowed, :platforms_for_build, :create]

View File

@ -1,5 +1,6 @@
class Api::V1::ProductBuildListsController < Api::V1::BaseController
before_action :authenticate_user!
skip_before_action :check_auth, only: [:index, :show] if APP_CONFIG['anonymous_access']
skip_before_action :authenticate_user!, only: [:index, :show] if APP_CONFIG['anonymous_access']
before_action :load_product, only: :index

View File

@ -1,5 +1,6 @@
class Api::V1::ProductsController < Api::V1::BaseController
before_action :authenticate_user!
skip_before_action :check_auth, only: [:index, :show] if APP_CONFIG['anonymous_access']
skip_before_action :authenticate_user!, only: [:index, :show] if APP_CONFIG['anonymous_access']
before_action :load_product, except: :create

View File

@ -1,7 +1,8 @@
class Api::V1::ProjectsController < Api::V1::BaseController
before_action :authenticate_user!
skip_before_action :authenticate_user!, only: [:get_id, :show, :refs_list] if APP_CONFIG['anonymous_access']
skip_before_action :check_auth, only: [:get_id, :show] if APP_CONFIG['anonymous_access']
skip_before_action :authenticate_user!, only: [:get_id, :show] if APP_CONFIG['anonymous_access']
before_action :load_project, except: [:index, :create, :get_id]
@ -55,23 +56,6 @@ class Api::V1::ProjectsController < Api::V1::BaseController
update_member_in_subject @project
end
def fork(is_alias = false)
owner = (Group.find params[:group_id] if params[:group_id].present?) || current_user
authorize @project, :show?
authorize owner, :write? if owner.is_a?(Group)
if forked = @project.fork(owner, new_name: params[:fork_name], is_alias: is_alias) and forked.valid?
render_json_response forked, 'Project has been forked successfully'
else
render_validation_error forked, 'Project has not been forked'
end
end
def alias
authorize @project
fork(true)
end
private
# Private: before_action hook which loads Project.

View File

@ -2,6 +2,7 @@ class Api::V1::RepositoriesController < Api::V1::BaseController
respond_to :csv, only: :packages
before_action :authenticate_user!
skip_before_action :check_auth, only: [:show, :projects] if APP_CONFIG['anonymous_access']
skip_before_action :authenticate_user!, only: [:show, :projects] if APP_CONFIG['anonymous_access']
before_action :load_repository

View File

@ -1,6 +1,7 @@
class Api::V1::UsersController < Api::V1::BaseController
before_action :authenticate_user!
skip_before_action :check_auth, only: [:show] if APP_CONFIG['anonymous_access']
skip_before_action :authenticate_user!, only: [:show] if APP_CONFIG['anonymous_access']
before_action :load_user, only: %i(show)
before_action :set_current_user, except: :show

View File

@ -4,7 +4,7 @@ class Platforms::MassBuildsController < Platforms::BaseController
before_action :authenticate_user!
skip_before_action :authenticate_user!, only: [:index, :get_list] if APP_CONFIG['anonymous_access']
before_action :find_mass_build, only: %i(show publish cancel get_list)
before_action :find_mass_build, only: %i(show publish cancel get_list show_fail_reason)
def new
if params[:mass_build_id].present?
@ -69,6 +69,27 @@ class Platforms::MassBuildsController < Platforms::BaseController
render text: text
end
def show_fail_reason
@build_lists = @mass_build.build_lists.where(status: 666).page(params[:page])
data = @build_lists.pluck(:id, :project_id, :arch_id, :fail_reason)
arches = {}
Arch.all.map do |arch|
arches[arch.id] = arch.name
end
projects = {}
@items = data.map do |item|
if projects[item[1]]
item[1] = projects[item[1]]
else
project_name_with_owner = Project.find(item[1]).name_with_owner
projects[item[1]] = project_name_with_owner
item[1] = project_name_with_owner
end
item[2] = arches[item[2]]
item
end
end
private
# Private: before_action hook which loads MassBuild.

View File

@ -34,6 +34,10 @@ module AbfWorker
subject.update_attribute(:hostname, options['hostname'])
end
if options['fail_reason']
subject.update_attribute(:fail_reason, options['fail_reason'])
end
if options['commit_hash']
item.update_attribute(:version, options['commit_hash'])
subject.update_attribute(:commit_hash, options['commit_hash'])

View File

@ -5,7 +5,7 @@ class MassBuildPolicy < ApplicationPolicy
end
alias_method :read?, :show?
alias_method :get_list?, :show?
alias_method :show_fail_reason?, :show?
def create?
is_admin? || owner?(record.save_to_platform) || local_admin?(record.save_to_platform)
end

View File

@ -126,7 +126,6 @@
= link_to_list @platform, @mass_build, 'tests_failed_builds_list'
| &nbsp;
= link_to_list @platform, @mass_build, 'success_builds_list'
.buttons_block
- if policy(@mass_build).publish?
- unless @mass_build.auto_publish_status == BuildList::AUTO_PUBLISH_STATUS_DEFAULT
@ -153,3 +152,8 @@
= link_to t('layout.mass_builds.recreate'),
new_platform_mass_build_path(@platform, mass_build_id: @mass_build.id),
class: 'btn btn-primary'
- if policy(@mass_build).show_fail_reason? && @mass_build.build_error_count > 0
hr
= link_to t('layout.mass_builds.show_fail_reason_link'),
show_fail_reason_platform_mass_build_path,
class: 'btn btn-info'

View File

@ -0,0 +1,35 @@
= render 'submenu'
.col-xs-12.col-md-10.col-md-offset-1
.row
h3
= t('layout.mass_builds.show_fail_reason.title')
= link_to t('layout.mass_builds.show_fail_reason.return'), platform_mass_build_path
.row
-if !@items.empty?
table.table.table-condensed
thead
tr
th
= t("activerecord.attributes.build_list.id")
th
= t("activerecord.attributes.build_list.project")
th
= t("activerecord.attributes.build_list.arch")
th
= t("activerecord.attributes.build_list.fail_reason")
tbody
- @items.each do |item|
tr
td
= link_to item[0], build_list_path(item[0])
td
= link_to item[1], project_path(item[1])
td
= item[2]
td
= item[3]
-else
= t('layout.mass_builds.show_fail_reason.no_failed_builds')
.row
=will_paginate @build_lists

View File

@ -112,6 +112,11 @@ row[ ng-controller='BuildListController'
td= t('activerecord.attributes.build_list.hostname')
td= @build_list.hostname
tr ng-show = 'build_list.fail_reason'
td= t('activerecord.attributes.build_list.fail_reason')
td
| {{build_list.fail_reason}}
tr
td= t('activerecord.attributes.build_list.updated_at')
td

View File

@ -21,6 +21,8 @@ json.build_list do
json.can_publish_in_future can_publish_in_future?(@build_list)
json.can_publish_into_repository @build_list.can_publish_into_repository?
json.fail_reason @build_list.fail_reason if @build_list.fail_reason.present?
json.container_path container_url if @build_list.container_published?
json.publisher do

View File

@ -22,6 +22,7 @@ en:
arch_short: Arch
arch: Architecture
hostname: Hostname
fail_reason: Fail reason
new_core: New core
is_circle: Recurrent build
updated_at: Notified at

View File

@ -21,6 +21,7 @@ ru:
arch_id: Архитектура
arch: Архитектура
hostname: Хост
fail_reason: Причина провала сборки
arch_short: Архит-ра
new_core: Новое ядро
is_circle: Циклическая сборка

View File

@ -2,6 +2,7 @@ en:
layout:
mass_builds:
new: New mass build
show_fail_reason_link: List of failed builds with reasons
recreate: Recreate mass build
publish_success: Publish success builds
publish_test_failed: Publish test failed builds
@ -16,6 +17,10 @@ en:
cancel_confirm: Are you sure you want to cancel mass build?
projects_list: Projects list
missed_projects_list: 'Missed projects: '
show_fail_reason:
title: Build Lists with fail reason
no_failed_builds: No failed builds
return: Return to mass build
placeholder:
description: Description

View File

@ -2,6 +2,7 @@ ru:
layout:
mass_builds:
new: Новая массовая сборка
show_fail_reason_link: Список упавших сборок с причинами
recreate: Пересоздать массовую сборку
publish_success: Опубликовать успешные сборки
publish_test_failed: Опубликовать сборки с проваленными тестами
@ -16,6 +17,10 @@ ru:
cancel_confirm: Вы уверены, что хотите отменить массовую сборку?
projects_list: Проекты
missed_projects_list: 'Несуществующие проекты: '
show_fail_reason:
title: Сборки с причиной провала
no_failed_builds: Нет сборок с ошибкой
return: Вернутся к массовой сборке
placeholder:
description: Описание

View File

@ -73,9 +73,6 @@ Rails.application.routes.draw do
resources :projects, only: [:index, :show, :update, :create, :destroy] do
collection { get :get_id }
member {
post :fork
post :alias
get :refs_list
get :members
put :add_member
delete :remove_member
@ -166,6 +163,7 @@ Rails.application.routes.draw do
member do
post :cancel
post :publish
get 'show_fail_reason(/:page)' => 'mass_builds#show_fail_reason', as: :show_fail_reason, page: /[0-9]+/, defaults: { page: '1' }
get '/:kind' => "mass_builds#get_list", as: :get_list, kind: /failed_builds_list|missed_projects_list|projects_list|tests_failed_builds_list|success_builds_list/
end
end

View File

@ -0,0 +1,5 @@
class AddFailReasonToBuildLists < ActiveRecord::Migration
def change
add_column :build_lists, :fail_reason, :string
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150601043133) do
ActiveRecord::Schema.define(version: 20160323122230) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -28,27 +28,6 @@ ActiveRecord::Schema.define(version: 20150601043133) do
t.integer "creator_id", index: {name: "index_activity_feeds_on_creator_id"}
end
create_table "advisories", force: :cascade do |t|
t.string "advisory_id", index: {name: "index_advisories_on_advisory_id", unique: true}
t.text "description", default: ""
t.text "references", default: ""
t.text "update_type", default: "", index: {name: "index_advisories_on_update_type"}
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "advisories_platforms", id: false, force: :cascade do |t|
t.integer "advisory_id", index: {name: "index_advisories_platforms_on_advisory_id"}
t.integer "platform_id", index: {name: "index_advisories_platforms_on_platform_id"}
end
add_index "advisories_platforms", ["advisory_id", "platform_id"], name: "advisory_platform_index", unique: true
create_table "advisories_projects", id: false, force: :cascade do |t|
t.integer "advisory_id", index: {name: "index_advisories_projects_on_advisory_id"}
t.integer "project_id", index: {name: "index_advisories_projects_on_project_id"}
end
add_index "advisories_projects", ["advisory_id", "project_id"], name: "advisory_project_index", unique: true
create_table "arches", force: :cascade do |t|
t.string "name", null: false, index: {name: "index_arches_on_name", unique: true}
t.datetime "created_at"
@ -82,8 +61,8 @@ ActiveRecord::Schema.define(version: 20150601043133) do
t.string "version"
t.string "release"
t.string "package_type"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "actual", default: false, index: {name: "index_build_list_packages_on_actual_and_platform_id", with: ["platform_id"]}
t.string "sha1"
t.integer "epoch"
@ -112,7 +91,6 @@ ActiveRecord::Schema.define(version: 20150601043133) do
t.integer "priority", default: 0, null: false
t.datetime "started_at"
t.integer "duration"
t.integer "advisory_id", index: {name: "index_build_lists_on_advisory_id"}
t.integer "mass_build_id", index: {name: "index_build_lists_on_mass_build_id_and_status", with: ["status"]}
t.integer "save_to_repository_id"
t.text "results"
@ -132,64 +110,16 @@ ActiveRecord::Schema.define(version: 20150601043133) do
t.boolean "use_cached_chroot", default: false, null: false
t.boolean "use_extra_tests", default: true, null: false
t.boolean "save_buildroot", default: false, null: false
t.string "hostname"
t.string "fail_reason"
end
add_index "build_lists", ["project_id", "save_to_repository_id", "build_for_platform_id", "arch_id"], name: "maintainer_search_index"
create_table "projects", force: :cascade do |t|
t.string "name", index: {name: "index_projects_on_name_and_owner_id_and_owner_type", with: ["owner_id", "owner_type"], unique: true, case_sensitive: false}
t.datetime "created_at"
t.datetime "updated_at"
t.integer "owner_id"
t.string "owner_type"
t.string "visibility", default: "open"
t.text "description"
t.string "ancestry"
t.boolean "has_issues", default: true
t.string "srpm_file_name"
t.integer "srpm_file_size"
t.datetime "srpm_updated_at"
t.string "srpm_content_type"
t.boolean "has_wiki", default: false
t.string "default_branch", default: "master"
t.boolean "is_package", default: true, null: false
t.integer "maintainer_id"
t.boolean "publish_i686_into_x86_64", default: false
t.string "owner_uname", null: false
t.boolean "architecture_dependent", default: false, null: false
t.integer "autostart_status"
t.integer "alias_from_id", index: {name: "index_projects_on_alias_from_id"}
end
create_table "build_scripts", force: :cascade do |t|
t.integer "project_id", null: false, index: {name: "fk__build_scripts_project_id"}, foreign_key: {references: "projects", name: "fk_build_scripts_project_id", on_update: :no_action, on_delete: :no_action}
t.string "treeish", null: false
t.string "commit"
t.string "sha1"
t.string "status"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "build_scripts", ["project_id", "treeish"], name: "index_build_scripts_on_project_id_and_treeish", unique: true
create_table "comments", force: :cascade do |t|
t.string "commentable_type", index: {name: "index_comments_on_commentable_type"}
t.integer "user_id"
t.text "body"
t.datetime "created_at"
t.datetime "updated_at"
t.decimal "commentable_id", precision: 50, index: {name: "index_comments_on_commentable_id"}
t.integer "project_id"
t.text "data"
t.boolean "automatic", default: false, index: {name: "index_comments_on_automatic"}
t.decimal "created_from_commit_hash", precision: 50, index: {name: "index_comments_on_created_from_commit_hash"}
t.integer "created_from_issue_id", index: {name: "index_comments_on_created_from_issue_id"}
end
create_table "event_logs", force: :cascade do |t|
t.integer "user_id"
t.integer "user_id", index: {name: "index_event_logs_on_user_id"}
t.string "user_name"
t.integer "eventable_id"
t.string "eventable_type"
t.string "eventable_type", index: {name: "index_event_logs_on_eventable_type_and_eventable_id", with: ["eventable_id"]}
t.string "eventable_name"
t.string "ip"
t.string "kind"
@ -206,8 +136,8 @@ ActiveRecord::Schema.define(version: 20150601043133) do
t.text "body_en", null: false
t.string "status", null: false
t.boolean "published", default: true, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "groups", force: :cascade do |t|
@ -224,36 +154,14 @@ ActiveRecord::Schema.define(version: 20150601043133) do
t.string "default_branch"
end
create_table "hooks", force: :cascade do |t|
t.text "data"
t.integer "project_id"
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "issues", force: :cascade do |t|
t.integer "serial_id"
t.integer "project_id", index: {name: "index_issues_on_project_id_and_serial_id", with: ["serial_id"], unique: true}
t.integer "assignee_id"
t.string "title"
t.text "body"
t.string "status", default: "open"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id", index: {name: "index_issues_on_user_id"}
t.datetime "closed_at"
t.integer "closed_by"
end
create_table "key_pairs", force: :cascade do |t|
t.text "public", null: false
t.text "encrypted_secret", null: false
t.string "key_id", null: false
t.integer "user_id", null: false
t.integer "repository_id", null: false, index: {name: "index_key_pairs_on_repository_id", unique: true}
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "key_pairs_backup", force: :cascade do |t|
@ -261,30 +169,15 @@ ActiveRecord::Schema.define(version: 20150601043133) do
t.integer "user_id", null: false
t.string "key_id", null: false
t.text "public", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "labelings", force: :cascade do |t|
t.integer "label_id", null: false
t.integer "issue_id", index: {name: "index_labelings_on_issue_id"}
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "labels", force: :cascade do |t|
t.string "name", null: false
t.string "color", null: false
t.integer "project_id", index: {name: "index_labels_on_project_id"}
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "mass_builds", force: :cascade do |t|
t.integer "build_for_platform_id", null: false
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at"
t.datetime "updated_at"
t.string "arch_names"
t.integer "user_id"
t.integer "build_lists_count", default: 0, null: false
@ -308,56 +201,13 @@ ActiveRecord::Schema.define(version: 20150601043133) do
t.string "external_nodes"
end
create_table "users", force: :cascade do |t|
t.string "name"
t.string "email", default: "", null: false, index: {name: "index_users_on_email", unique: true}
t.string "encrypted_password", limit: 128, default: "", null: false
t.string "reset_password_token", index: {name: "index_users_on_reset_password_token", unique: true}
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.datetime "created_at"
t.datetime "updated_at"
t.text "ssh_key"
t.string "uname", index: {name: "index_users_on_uname", unique: true}
t.string "role"
t.string "language", default: "en"
t.integer "own_projects_count", default: 0, null: false
t.text "professional_experience"
t.string "site"
t.string "company"
t.string "location"
t.string "avatar_file_name"
t.string "avatar_content_type"
t.integer "avatar_file_size"
t.datetime "avatar_updated_at"
t.integer "failed_attempts", default: 0
t.string "unlock_token", index: {name: "index_users_on_unlock_token", unique: true}
t.datetime "locked_at"
t.string "confirmation_token", index: {name: "index_users_on_confirmation_token", unique: true}
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "authentication_token", index: {name: "index_users_on_authentication_token"}
t.integer "build_priority", default: 50
t.boolean "sound_notifications", default: true
t.boolean "hide_email", default: true, null: false
end
create_table "node_instructions", force: :cascade do |t|
t.integer "user_id", null: false, index: {name: "fk__node_instructions_user_id"}, foreign_key: {references: "users", name: "fk_node_instructions_user_id", on_update: :no_action, on_delete: :no_action}
t.text "encrypted_instruction", null: false
t.text "output"
t.string "status"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "platform_arch_settings", force: :cascade do |t|
t.integer "platform_id", null: false, index: {name: "index_platform_arch_settings_on_platform_id_and_arch_id", with: ["arch_id"], unique: true}
t.integer "arch_id", null: false
t.integer "time_living", null: false
t.boolean "default"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "platforms", force: :cascade do |t|
@ -371,7 +221,7 @@ ActiveRecord::Schema.define(version: 20150601043133) do
t.string "owner_type"
t.string "visibility", default: "open", null: false
t.string "platform_type", default: "main", null: false
t.string "distrib_type", null: false
t.string "distrib_type"
t.integer "status"
t.datetime "last_regenerated_at"
t.integer "last_regenerated_status"
@ -427,18 +277,8 @@ ActiveRecord::Schema.define(version: 20150601043133) do
t.integer "build_count", default: 0, null: false
t.integer "arch_id", null: false
t.integer "project_id", null: false, index: {name: "index_project_statistics_on_project_id_and_arch_id", with: ["arch_id"], unique: true}
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "project_tags", force: :cascade do |t|
t.integer "project_id"
t.string "commit_id"
t.string "sha1"
t.string "tag_name"
t.integer "format_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "project_to_repositories", force: :cascade do |t|
@ -449,27 +289,27 @@ ActiveRecord::Schema.define(version: 20150601043133) do
t.hstore "autostart_options"
end
create_table "pull_requests", force: :cascade do |t|
t.integer "issue_id", null: false, index: {name: "index_pull_requests_on_issue_id"}
t.integer "to_project_id", null: false, index: {name: "index_pull_requests_on_base_project_id"}
t.integer "from_project_id", null: false, index: {name: "index_pull_requests_on_head_project_id"}
t.string "to_ref", null: false
t.string "from_ref", null: false
t.string "from_project_owner_uname"
t.string "from_project_name"
end
create_table "register_requests", force: :cascade do |t|
t.string "name"
t.string "email", index: {name: "index_register_requests_on_email", unique: true, case_sensitive: false}
t.string "token", index: {name: "index_register_requests_on_token", unique: true, case_sensitive: false}
t.boolean "approved", default: false
t.boolean "rejected", default: false
create_table "projects", force: :cascade do |t|
t.string "name", index: {name: "index_projects_on_name_and_owner_id_and_owner_type", with: ["owner_id", "owner_type"], unique: true, case_sensitive: false}
t.datetime "created_at"
t.datetime "updated_at"
t.string "interest"
t.text "more"
t.string "language"
t.integer "owner_id"
t.string "owner_type"
t.string "visibility", default: "open"
t.string "ancestry"
t.string "srpm_file_name"
t.string "srpm_content_type"
t.integer "srpm_file_size"
t.datetime "srpm_updated_at"
t.string "default_branch", default: "master"
t.boolean "is_package", default: true, null: false
t.integer "maintainer_id"
t.boolean "publish_i686_into_x86_64", default: false
t.string "owner_uname", null: false
t.boolean "architecture_dependent", default: false, null: false
t.integer "autostart_status"
t.integer "alias_from_id", index: {name: "index_projects_on_alias_from_id"}
t.string "github_organization"
end
create_table "relations", force: :cascade do |t|
@ -499,35 +339,18 @@ ActiveRecord::Schema.define(version: 20150601043133) do
t.integer "status", default: 0
t.datetime "last_regenerated_at"
t.integer "last_regenerated_status"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at"
t.datetime "updated_at"
t.string "last_regenerated_log_sha1"
end
create_table "settings_notifiers", force: :cascade do |t|
t.integer "user_id", null: false
t.boolean "can_notify", default: true
t.boolean "new_comment", default: true
t.boolean "new_comment_reply", default: true
t.boolean "new_issue", default: true
t.boolean "issue_assign", default: true
t.integer "user_id", null: false
t.boolean "can_notify", default: true
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "new_comment_commit_owner", default: true
t.boolean "new_comment_commit_repo_owner", default: true
t.boolean "new_comment_commit_commentor", default: true
t.boolean "new_build", default: true
t.boolean "new_associated_build", default: true
t.boolean "update_code", default: false
end
create_table "ssh_keys", force: :cascade do |t|
t.string "name"
t.text "key", null: false
t.string "fingerprint", null: false, index: {name: "index_ssh_keys_on_fingerprint", unique: true}
t.integer "user_id", null: false, index: {name: "index_ssh_keys_on_user_id"}
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "new_build", default: true
t.boolean "new_associated_build", default: true
end
create_table "statistics", force: :cascade do |t|
@ -546,16 +369,6 @@ ActiveRecord::Schema.define(version: 20150601043133) do
add_index "statistics", ["user_id", "key", "activity_at"], name: "index_statistics_on_user_id_and_key_and_activity_at"
add_index "statistics", ["user_id", "project_id", "key", "activity_at"], name: "index_statistics_on_all_keys", unique: true
create_table "subscribes", force: :cascade do |t|
t.string "subscribeable_type"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "status", default: true
t.integer "project_id"
t.decimal "subscribeable_id", precision: 50
end
create_table "tokens", force: :cascade do |t|
t.integer "subject_id", null: false, index: {name: "index_tokens_on_subject_id_and_subject_type", with: ["subject_type"]}
t.string "subject_type", null: false
@ -564,8 +377,8 @@ ActiveRecord::Schema.define(version: 20150601043133) do
t.string "status", default: "active"
t.text "description"
t.string "authentication_token", null: false, index: {name: "index_tokens_on_authentication_token", unique: true}
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "user_builds_settings", force: :cascade do |t|
@ -574,4 +387,37 @@ ActiveRecord::Schema.define(version: 20150601043133) do
t.string "external_nodes"
end
create_table "users", force: :cascade do |t|
t.string "name"
t.string "email", default: "", null: false, index: {name: "index_users_on_email", unique: true}
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token", index: {name: "index_users_on_reset_password_token", unique: true}
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.datetime "created_at"
t.datetime "updated_at"
t.string "uname", index: {name: "index_users_on_uname", unique: true}
t.string "role"
t.string "language", default: "en"
t.integer "own_projects_count", default: 0, null: false
t.string "confirmation_token", index: {name: "index_users_on_confirmation_token", unique: true}
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.text "professional_experience"
t.string "site"
t.string "company"
t.string "location"
t.string "avatar_file_name"
t.string "avatar_content_type"
t.integer "avatar_file_size"
t.datetime "avatar_updated_at"
t.integer "failed_attempts", default: 0
t.string "unlock_token", index: {name: "index_users_on_unlock_token", unique: true}
t.datetime "locked_at"
t.string "authentication_token", index: {name: "index_users_on_authentication_token"}
t.integer "build_priority", default: 50
t.boolean "sound_notifications", default: true
t.boolean "hide_email", default: true, null: false
end
end

View File

@ -1,70 +0,0 @@
require 'highline/import'
require 'open-uri'
namespace :add_branch do
desc 'Fork project branch'
task :fork_branch, :path, :src_branch, :dst_branch do |t, args|
tmp_path = File.join Dir.tmpdir, "#{Time.now.to_i}#{rand(1000)}"
system("git clone #{args[:path]} #{tmp_path}")
system("cd #{tmp_path} && git push origin :#{args[:dst_branch]}")
system("cd #{tmp_path} && git checkout remotes/origin/#{args[:src_branch]} || git checkout master")
system("cd #{tmp_path} && git checkout -b #{args[:dst_branch]} && git push origin HEAD")
FileUtils.rm_rf tmp_path
end
desc "Add branch for group projects"
task group: :environment do
src_branch = ENV['SRC_BRANCH']
dst_branch = ENV['DST_BRANCH']
group = ENV['GROUP']
say "START add branch #{dst_branch} from #{src_branch} in #{group} group"
Group.find_by(uname: group).projects.find_each do |p|
next if p.repo.branches.map(&:name).include?(dst_branch)
next if p.repo.branches.map(&:name).exclude?(src_branch)
say "===== Process #{p.name} project"
Rake::Task['add_branch:fork_branch'].execute(path: p.path, src_branch: src_branch, dst_branch: dst_branch)
end
say 'DONE'
end
desc "Add branch for platform projects"
task platform: :environment do
src_branch = ENV['SRC_BRANCH'] || 'import_mandriva2011'
dst_branch = ENV['DST_BRANCH'] || 'rosa2012lts'
say "START add branch #{dst_branch} from #{src_branch}"
Platform.find_by(name: dst_branch).repositories.each do |r|
say "=== Process #{r.name} repo"
r.projects.find_each do |p|
next if p.repo.branches.map(&:name).include?(dst_branch)
say "===== Process #{p.name} project"
Rake::Task['add_branch:fork_branch'].execute(path: p.path, src_branch: src_branch, dst_branch: dst_branch)
end
end
say 'DONE'
end
desc "Add branch for owner projects by list"
task list: :environment do
source = ENV['SOURCE'] || 'https://dl.dropbox.com/u/984976/texlive.txt'
owner = User.find_by(uname: ENV['OWNER']) || Group.find_by!(uname: ENV['OWNER'] || 'import')
platform = Platform.find_by!(name: ENV['PLATFORM'] || 'rosa2012.1')
repo = platform.repositories.find_by!(name: ENV['REPO'] || 'main')
src_branch = ENV['SRC_BRANCH'] || 'import_cooker'
dst_branch = ENV['DST_BRANCH'] || 'rosa2012.1'
say "START fork from #{src_branch} to #{dst_branch} branch using #{source} for #{owner.uname}. Add to repo '#{platform.name}/#{repo.name}'."
open(source).readlines.each do |name|
name.chomp!; name.strip!
print "Fork branch for '#{name}'... "
if p = Project.find_by_owner_and_name(owner.uname, name)
# Rake::Task['add_branch:fork_branch'].execute(path: p.path, src_branch: src_branch, dst_branch: dst_branch)
system "bundle exec rake add_branch:fork_branch[#{p.path},#{src_branch},#{dst_branch}] -s RAILS_ENV=#{Rails.env} > /dev/null 2>&1"
print 'Ok!'
repo.projects << p rescue print ' Add to repo failed!'
else
print 'Not Found!'
end
puts
end
say 'DONE'
end
end

View File

@ -1,73 +0,0 @@
namespace :buildlist do
namespace :clear do
desc 'Remove outdated BuildLists and MassBuilds'
task outdated: :environment do
say "[#{Time.zone.now}] Removing outdated BuildLists"
say "[#{Time.zone.now}] There are #{BuildList.outdated.count} outdated BuildLists"
counter = 0
BuildList.outdated.find_each(batch_size: 100) do |bl|
bl.destroy && (counter += 1) if bl.id != bl.last_published.first.try(:id)
end
say "[#{Time.zone.now}] #{counter} outdated BuildLists have been removed"
say "[#{Time.zone.now}] Removing outdated MassBuilds"
say "[#{Time.zone.now}] There are #{MassBuild.outdated.count} outdated MassBuilds"
counter = 0
MassBuild.outdated.find_each do |mb|
mb.destroy && (counter += 1) if mb.build_lists.count == 0
end
say "[#{Time.zone.now}] #{counter} outdated MassBuilds have been removed"
say "[#{Time.zone.now}] Outdated BuildLists and MassBuilds was successfully removed"
end
desc 'Remove outdated BuildLists with status BUILD_CANCELING'
task outdated_canceling: :environment do
say "[#{Time.zone.now}] Removing outdated BuildLists"
scope = BuildList.for_status(BuildList::BUILD_CANCELING).
for_notified_date_period(nil, Time.zone.now - 3.hours)
say "[#{Time.zone.now}] There are #{scope.count} outdated BuildLists"
counter = 0
scope.find_each do |bl|
bl.destroy && (counter += 1)
end
say "[#{Time.zone.now}] #{counter} outdated BuildLists have been removed"
say "[#{Time.zone.now}] Outdated BuildLists were successfully removed"
end
end
namespace :packages do
# TODO Maybe do it in migration, because it's just a single query?
desc 'Actualize packages for all platforms'
task actualize: :environment do
say "Updating packages"
packages = BuildList::Package.joins( %q{
JOIN (
SELECT
name AS j_pn,
package_type AS j_pt,
platform_id AS j_plid,
MAX(created_at) AS j_ca
FROM
build_list_packages
GROUP BY
j_pn, j_pt, j_plid
) AS lastmaints
ON
j_pn = name
AND j_pt = package_type
AND j_plid = platform_id
AND j_ca = created_at
} ).update_all(actual: true)
say "'Actual' setted to #{packages} packages"
end
end
end

View File

@ -1,13 +0,0 @@
namespace :project do
desc 'Change HEAD at projects where default branch is not master'
task git_change_head: :environment do
projects = Project.where("default_branch <> 'master'")
say "Find #{projects.count} project(s) without master HEAD"
say "Start working..."
projects.each do |project|
`cd #{project.path} && git symbolic-ref HEAD refs/heads/#{project.default_branch}` if project.repo.branches.map(&:name).include?(project.default_branch)
end
say 'Done!'
end
end

View File

@ -1,34 +0,0 @@
namespace :repositories do
desc "Migrate repositories from fs"
task migrate: :environment do
repo_dirs = Dir["/root/mandriva_main_git/*.git"]
total = repo_dirs.length
cooker = Platform.find_by! name: "cooker"
main = cooker.repositories.find_by! name: "main"
repo_dirs.each_with_index do |repo_dir, index|
project_name = File.basename(repo_dir, ".git")
puts "Creating project(#{index}/#{total}): #{project_name}"
if main.projects.find_by name: project_name
puts "\t Already created. Skipping"
next
end
project = main.projects.create(name: project_name)
puts "Executing: 'rm -rf #{project.path}'"
`rm -rf #{project.path}`
puts "Executing: 'cp -a #{repo_dir} #{project.path}'"
`cp -a #{repo_dir} #{project.path}`
puts ""
end
end
end

View File

@ -1,14 +0,0 @@
namespace :product_build_list do
namespace :clear do
desc 'Remove outdated ProductBuildLists'
task outdated: :environment do
say "[#{Time.zone.now}] Removing outdated ProductBuildLists"
say "[#{Time.zone.now}] There are #{ProductBuildList.outdated.count} outdated ProductBuildLists"
ProductBuildList.outdated.destroy_all
say "[#{Time.zone.now}] Outdated BuildLists have been removed"
end
end
end

View File

@ -1,30 +0,0 @@
namespace :remove_branch do
desc "Remove branch for group projects"
task group: :environment do
branch = ENV['BRANCH']
group = ENV['GROUP']
say "START remove branch #{branch} from #{group} group"
Group.find_by(uname: group).projects.find_each do |p|
next if p.repo.branches.map(&:name).exclude?(branch)
say "===== Process #{p.name} project"
p.repo.git.native(:branch, {}, '-D', branch)
end
say 'DONE'
end
desc "Remove branch for platform projects"
task platform: :environment do
branch = ENV['BRANCH']
platform = ENV['PLATFORM']
say "START remove branch #{branch} from #{platform} platform"
Platform.find_by(name: platform).repositories.each do |r|
say "=== Process #{r.name} repo"
r.projects.find_each do |p|
next if p.repo.branches.map(&:name).exclude?(branch)
say "===== Process #{p.name} project"
p.repo.git.native(:branch, {}, '-D', branch)
end
end
say 'DONE'
end
end

View File

@ -1,6 +0,0 @@
namespace :sudo_test do
desc "Test sudo from web"
task projects: :environment do
system "sudo touch /root/sudo_#{Time.now.to_i}.txt"
end
end