forked from Gitlink/forgeplus
增加上链操作及修改webhook
This commit is contained in:
parent
4595cac2d9
commit
27cc8ab96d
|
@ -381,7 +381,12 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
def current_user
|
||||
User.current
|
||||
if Rails.env.development?
|
||||
User.find(1)
|
||||
else
|
||||
User.current
|
||||
end
|
||||
# User.current
|
||||
end
|
||||
|
||||
## 默认输出json
|
||||
|
|
|
@ -16,6 +16,7 @@ class ProjectsController < ApplicationController
|
|||
ActiveRecord::Base.transaction do
|
||||
Projects::CreateForm.new(project_params).validate!
|
||||
@project = Projects::CreateService.new(current_user, project_params).call
|
||||
|
||||
end
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
|
|
|
@ -123,6 +123,10 @@ class RepositoriesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def repo_hook
|
||||
Rails.logger.info("#####______222________########")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_project
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
class ProjectCreateChainJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(owner_login, reponame)
|
||||
status = 0
|
||||
|
||||
5.times do |i|
|
||||
if status == 200
|
||||
Rails.logger.info("########_repository__#{reponame}______create_chain_success__try:_#{i+1}_")
|
||||
break
|
||||
else
|
||||
Rails.logger.info("########_repository__#{reponame}______start_to_create_chain__try:_#{i+1}_")
|
||||
create_chain = system("chain trustieCreate #{owner_login} #{reponame}")
|
||||
status = create_chain[:status].to_i
|
||||
Rails.logger.info("########_repository__#{reponame}__create_chain:___#{create_chain}____failed_to_create_chain__")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,23 @@
|
|||
class Gitea::Repository::Hooks::CreateService < Gitea::ClientService
|
||||
attr_reader :user, :repo_name, :body
|
||||
|
||||
def initialize(user, repo_name, body)
|
||||
@user = user
|
||||
@repo_name = repo_name
|
||||
@body = body
|
||||
end
|
||||
|
||||
def call
|
||||
response = post(url, params)
|
||||
end
|
||||
|
||||
private
|
||||
def params
|
||||
body.merge(token: user.gitea_token)
|
||||
end
|
||||
|
||||
def url
|
||||
"/repos/#{user.login}/#{repo_name}/hooks".freeze
|
||||
end
|
||||
|
||||
end
|
|
@ -14,6 +14,24 @@ class Repositories::CreateService < ApplicationService
|
|||
gitea_repository = Gitea::Repository::CreateService.new(user.gitea_token, gitea_repository_params).call
|
||||
sync_project(@repository, gitea_repository)
|
||||
sync_repository(@repository, gitea_repository)
|
||||
Rails.logger.info("#######________reuqest_domain____#########{EduSetting.get("host_name")}")
|
||||
#if project.project_type == "common"
|
||||
#hook_params = {
|
||||
# active: true,
|
||||
# type: "gitea"
|
||||
# branch_filter: "",
|
||||
# config: {
|
||||
# content_type: "application/json",
|
||||
# url: "#{EduSetting.get("host_name")}/repositories/#{project.id}/repo_hooks",
|
||||
# http_method: "post"
|
||||
#},
|
||||
#events: ["create", "pull", "push"],
|
||||
#}
|
||||
#Gitea::Repository::Hooks::CreateService.new(user, @repository.try(:identifier), hook_params).call
|
||||
#end
|
||||
|
||||
# 托管项目创建上链操作
|
||||
ProjectCreateChainJob.perform_later(user.try(:login), @repository.try(:identifier)) if project.project_type == "common"
|
||||
end
|
||||
@repository
|
||||
end
|
||||
|
|
|
@ -8,8 +8,8 @@ json.projects @projects do |project|
|
|||
json.name project.name
|
||||
json.description Nokogiri::HTML(project.description).text
|
||||
json.visits project.visits
|
||||
json.praises_count project.praises_count
|
||||
json.forked_count project.forked_count
|
||||
json.praises_count project.praises_count.to_i
|
||||
json.forked_count project.forked_count.to_i
|
||||
json.is_public project.is_public
|
||||
json.mirror_url project.repository&.mirror_url
|
||||
json.last_update_time render_unix_time(project.updated_on)
|
||||
|
|
|
@ -192,6 +192,7 @@ Rails.application.routes.draw do
|
|||
post :create_file
|
||||
put :update_file
|
||||
delete :delete_file
|
||||
post :repo_hook
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue