Merge branch 'dev_trustie' of http://gitea.trustie.net/jasder/forgeplus into dev_trustie
This commit is contained in:
commit
81d46405a4
|
@ -1,7 +1,8 @@
|
|||
class ProjectsController < ApplicationController
|
||||
include ApplicationHelper
|
||||
include OperateProjectAbilityAble
|
||||
before_action :require_login, except: %i[index branches group_type_list]
|
||||
include ProjectsHelper
|
||||
before_action :require_login, except: %i[index branches group_type_list simple]
|
||||
before_action :find_project_with_id, only: %i[show branches update destroy fork_users praise_users watch_users]
|
||||
before_action :authorizate_user_can_edit_project!, only: %i[update]
|
||||
before_action :project_public?, only: %i[fork_users praise_users watch_user]
|
||||
|
@ -98,6 +99,12 @@ class ProjectsController < ApplicationController
|
|||
@fork_users = paginate(fork_users)
|
||||
end
|
||||
|
||||
def simple
|
||||
project = Project.includes(:owner).select(:id, :name, :identifier, :user_id).find params[:id]
|
||||
|
||||
json_response(project)
|
||||
end
|
||||
|
||||
private
|
||||
def project_params
|
||||
params.permit(:user_id, :name, :description, :repository_name,
|
||||
|
|
|
@ -8,14 +8,11 @@ class RepositoriesController < ApplicationController
|
|||
before_action :find_repository_by_id, only: %i[commit sync_mirror tags]
|
||||
before_action :authorizate_user_can_edit_repo!, only: %i[sync_mirror]
|
||||
before_action :get_ref, only: %i[entries sub_entries]
|
||||
before_action :get_latest_commit, :get_ref, only: %i[entries sub_entries]
|
||||
before_action :get_statistics, only: %i[entries sub_entries]
|
||||
|
||||
def show
|
||||
@user = current_user
|
||||
@branches_count = Gitea::Repository::Branches::ListService.new(@project.owner, @project.identifier).call&.size
|
||||
@commits_count = Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier,
|
||||
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call[:total_count]
|
||||
@tags_count = Gitea::Repository::Tags::ListService.new(current_user&.gitea_token, @project.owner.login, @project.identifier).call&.size
|
||||
@repo = @project.repository
|
||||
@result = Gitea::Repository::GetService.new(@project.owner, @project.identifier).call
|
||||
@project_fork_id = @project.try(:forked_from_project_id)
|
||||
if @project_fork_id.present?
|
||||
|
@ -96,11 +93,13 @@ class RepositoriesController < ApplicationController
|
|||
end
|
||||
|
||||
def repo_hook
|
||||
|
||||
|
||||
end
|
||||
|
||||
def sync_mirror
|
||||
@repo&.mirror.set_status!(Mirror.statuses[:waiting])
|
||||
return render_error("正在镜像中..") if @repo.mirror.warning?
|
||||
|
||||
@repo.sync_mirror!
|
||||
SyncMirroredRepositoryJob.perform_later(@repo.id, current_user.id)
|
||||
render_ok
|
||||
end
|
||||
|
@ -124,9 +123,17 @@ class RepositoriesController < ApplicationController
|
|||
|
||||
# TODO 获取最新commit信息
|
||||
def get_latest_commit
|
||||
@latest_commit = Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier,
|
||||
Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier,
|
||||
sha: get_ref, page: 1, limit: 1, token: current_user&.gitea_token).call
|
||||
@latest_commit = @latest_commit.blank? ? nil : @latest_commit[:body][0]
|
||||
end
|
||||
|
||||
def get_statistics
|
||||
@branches_count = Gitea::Repository::Branches::ListService.new(@project.owner, @project.identifier).call&.size
|
||||
@tags_count = Gitea::Repository::Tags::ListService.new(current_user&.gitea_token, @project.owner.login, @project.identifier).call&.size
|
||||
|
||||
latest_commit = get_latest_commit
|
||||
@latest_commit = latest_commit[:body][0]
|
||||
@commits_count = latest_commit[:total_count]
|
||||
end
|
||||
|
||||
def get_ref
|
||||
|
|
|
@ -27,4 +27,18 @@ module ProjectsHelper
|
|||
def find_user_by_login_or_mail(identifier)
|
||||
(User.find_by_login identifier) || (User.find_by_mail identifier)
|
||||
end
|
||||
|
||||
def json_response(project)
|
||||
json = {
|
||||
identifier: project.identifier,
|
||||
name: project.name,
|
||||
id: project.id,
|
||||
author: {
|
||||
login: project.owner.login,
|
||||
name: project.owner.real_name,
|
||||
image_url: url_to_avatar(project.owner)
|
||||
}
|
||||
}
|
||||
render json: json
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class Mirror < ApplicationRecord
|
||||
|
||||
# 0 - succeeded, 1 - waiting, 2 - failed
|
||||
# 0: 同步镜像成功;1: 正在同步镜像;2: 同步失败,默认值为0
|
||||
# 0: 同步镜像成功;1: 正在同步镜像;2: 同步失败; 默认值为0
|
||||
enum status: { succeeded: 0, waiting: 1, failed: 2 }
|
||||
|
||||
belongs_to :repository, foreign_key: :repo_id
|
||||
|
|
|
@ -15,4 +15,22 @@ class Repository < ApplicationRecord
|
|||
def set_mirror!
|
||||
self.build_mirror(status: Mirror.statuses[:waiting]).save
|
||||
end
|
||||
|
||||
def mirror_status
|
||||
self&.mirror&.numerical_for_status
|
||||
end
|
||||
|
||||
def mirror_num
|
||||
self&.mirror&.sync_num
|
||||
end
|
||||
|
||||
def first_sync?
|
||||
self&.mirror&.sync_num === 1
|
||||
end
|
||||
|
||||
def sync_mirror!
|
||||
repo_mirror = self.mirror
|
||||
repo_mirror.set_status!(Mirror.statuses[:waiting])
|
||||
repo_mirror.increment!(:sync_num)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ class Repositories::MigrateService < ApplicationService
|
|||
def call
|
||||
@repository = Repository.new(repository_params)
|
||||
if @repository.save!
|
||||
@repository.set_mirror! if wrapper_mirror
|
||||
@repository.set_mirror!
|
||||
MigrateRemoteRepositoryJob.perform_later(@repository.id, user.gitea_token, gitea_repository_params)
|
||||
end
|
||||
@repository
|
||||
|
|
|
@ -5,6 +5,9 @@ json.last_commit do
|
|||
json.nil!
|
||||
end
|
||||
end
|
||||
json.tags_count @tags_count
|
||||
json.branches_count @branches_count
|
||||
json.commits_count @commits_count
|
||||
json.zip_url render_zip_url(@project, @ref)
|
||||
json.tar_url render_tar_url(@project, @ref)
|
||||
json.entries do
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
json.identifier @project.identifier
|
||||
json.name @project.name
|
||||
json.project_id @project.id
|
||||
json.repo_id @project.repository.id
|
||||
json.repo_id @repo.id
|
||||
json.issues_count @project.issues_count.to_i - @project.pull_requests_count.to_i
|
||||
json.pull_requests_count @project.pull_requests_count
|
||||
json.project_identifier @project.identifier
|
||||
|
@ -12,14 +12,17 @@ json.versions_count @project.versions_count #里程碑数量
|
|||
json.version_releases_count @project.releases_size(@user.try(:id), "all")
|
||||
json.version_releasesed_count @project.releases_size(@user.try(:id), "released") #已发行的版本
|
||||
json.contributor_users_count @project.contributor_users
|
||||
json.issue_tags_count @tags_count
|
||||
json.branches_count @branches_count
|
||||
json.commits_count @commits_count
|
||||
json.permission @project.get_premission(@user)
|
||||
json.mirror_url @project&.repository.mirror_url
|
||||
json.mirror @project&.repository.mirror_url.present?
|
||||
json.type @project.numerical_for_project_type
|
||||
json.mirror_status @project.repository&.mirror&.numerical_for_status if @project.sync_mirror?
|
||||
|
||||
unless @project.common?
|
||||
json.mirror_status @repo.mirror_status
|
||||
json.mirror_num @repo.mirror_num
|
||||
json.first_sync @repo.first_sync?
|
||||
end
|
||||
|
||||
json.watched @project.watched_by? @user
|
||||
json.praised @project.praised_by? @user
|
||||
json.status @project.status
|
||||
|
@ -32,12 +35,14 @@ json.fork_info do
|
|||
end
|
||||
end
|
||||
|
||||
json.size replace_bytes_to_b(number_to_human_size(@result['size'].to_i*1024))
|
||||
json.ssh_url @result['ssh_url']
|
||||
json.clone_url @result['clone_url']
|
||||
json.default_branch @result['default_branch']
|
||||
json.empty @result['empty']
|
||||
json.full_name @result['full_name']
|
||||
if @result
|
||||
json.size replace_bytes_to_b(number_to_human_size(@result['size'].to_i*1024))
|
||||
json.ssh_url @result['ssh_url']
|
||||
json.clone_url @result['clone_url']
|
||||
json.default_branch @result['default_branch']
|
||||
json.empty @result['empty']
|
||||
json.full_name @result['full_name']
|
||||
json.private @result['private']
|
||||
end
|
||||
|
||||
json.private @result['private']
|
||||
json.partial! 'author', locals: { user: @project.owner }
|
||||
|
|
|
@ -6,6 +6,9 @@ json.last_commit do
|
|||
json.nil!
|
||||
end
|
||||
end
|
||||
json.tags_count @tags_count
|
||||
json.branches_count @branches_count
|
||||
json.commits_count @commits_count
|
||||
json.entries do
|
||||
json.array! @sub_entries do |entry|
|
||||
json.partial! 'repositories/simple_entry', locals: { entry: entry }
|
||||
|
|
|
@ -32,8 +32,8 @@ Rails.application.routes.draw do
|
|||
delete 'commons/delete', to: 'commons#delete'
|
||||
|
||||
resources :issues, except: [:index, :new,:create, :update, :edit, :destroy] do
|
||||
resources :journals, only: [:index, :create, :destroy, :edit, :update] do
|
||||
member do
|
||||
resources :journals, only: [:index, :create, :destroy, :edit, :update] do
|
||||
member do
|
||||
get :get_children_journals
|
||||
end
|
||||
end
|
||||
|
@ -120,6 +120,7 @@ Rails.application.routes.draw do
|
|||
get :watch_users
|
||||
get :praise_users
|
||||
get :fork_users
|
||||
get :simple
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddSyncNumToMirrors < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :mirrors, :sync_num, :integer, default: 1
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue