init project

This commit is contained in:
Jasder
2020-03-09 00:40:16 +08:00
commit 2937b2a94d
6549 changed files with 7215173 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
module Gitea
class CreateFileInteractor
def self.call(user, params={})
interactor = new(user, params)
interactor.run
interactor
end
attr_reader :error, :result
def initialize(user, params)
@user = user
@params = params
end
def success?
@error.nil?
end
def result
@result
end
def run
Contents::CreateForm.new(valid_params).validate!
response = Gitea::Repository::Entries::CreateService.new(user, @params[:repo_identifier], @params[:filepath], file_params).call
render_result(response)
rescue Exception => exception
Rails.logger.info "Exception ===========> #{exception.message}"
fail!(exception.message)
end
private
attr_reader :params, :user
def fail!(error)
@error = error
end
def render_result(response)
@result = response
end
def valid_params
{
login: @params[:login],
repo_identifier: @params[:repo_identifier],
filepath: @params[:filepath],
branch: @params[:branch],
new_branch: @params[:new_branch]
}
end
def file_params
file_params = {}
file_params = file_params.merge(branch: @params[:branch]) unless @params[:branch].blank?
file_params = file_params.merge(new_branch: @params[:new_branch]) unless @params[:new_branch].blank?
file_params = file_params.merge(content: Base64.encode64(@params[:content]))
file_params = file_params.merge(message: @params[:message]) unless @params[:message].blank?
end
end
end

View File

@@ -0,0 +1,65 @@
module Gitea
class DeleteFileInteractor
def self.call(user, params={})
interactor = new(user, params)
interactor.run
interactor
end
attr_reader :error, :result
def initialize(user, params)
@user = user
@params = params
end
def success?
@error.nil?
end
def result
@result
end
def run
Contents::DeleteForm.new(valid_params).validate!
response = Gitea::Repository::Entries::DeleteService.new(user, @params[:repo_identifier], @params[:filepath], file_params).call
render_result(response)
rescue Exception => exception
fail!(exception.message)
end
private
attr_reader :params, :user
def fail!(error)
puts "[exception]: error"
@error = error
end
def render_result(response)
if response.status == 200
@result = JSON.parse(response.body)
end
end
def valid_params
{
login: @params[:login],
repo_identifier: @params[:repo_identifier],
filepath: @params[:filepath],
sha: @params[:sha]
}
end
def file_params
Hash.new.merge(
branch: @params[:branch],
sha: @params[:sha],
new_branch: @params[:new_branch],
message: @params[:message],
).compact
end
end
end

View File

@@ -0,0 +1,45 @@
module Gitea
class RegisterInteractor
def self.call(params)
interactor = new(params)
interactor.run
interactor
end
attr_reader :error, :result
def initialize(params)
@params = params
end
def success?
@error.nil?
end
def result
@result
end
def run
Gitea::UserForm.new(params).validate!
response = Gitea::User::RegisterService.new(params).call
render_result(response)
rescue Exception => exception
Rails.logger.info "Exception ===========> #{exception.message}"
fail!(exception.message)
end
private
attr_reader :params
def fail!(error)
@error = error
end
def render_result(response)
@result = response
end
end
end

View File

@@ -0,0 +1,35 @@
class Gitea::RepositoryInteractor
attr_reader :error
# params: token and repository
def self.call(token, repository)
interactor = new(token, repository)
interactor.run
interactor
end
def initialize(token, repository)
@token = token
@repository = repository
end
def success?
@error.nil?
end
def run
Gitea::RepositoryForm.new({name: repository&.name}).validate!
Gitea::Repository::CreateService.new(token, repository).call
rescue Exception => exception
puts exception.message
fail!(exception.message)
end
private
attr_reader :token, :repository
def fail!(error)
@error = error
end
end

View File

@@ -0,0 +1,69 @@
module Gitea
class UpdateFileInteractor
def self.call(user, params={})
interactor = new(user, params)
interactor.run
interactor
end
attr_reader :error, :result
def initialize(user, params)
@user = user
@params = params
end
def success?
@error.nil?
end
def result
@result
end
def run
Contents::UpdateForm.new(valid_params).validate!
response = Gitea::Repository::Entries::UpdateService.new(user, @params[:repo_identifier], @params[:filepath], file_params).call
render_result(response)
rescue Exception => exception
fail!(exception.message)
end
private
attr_reader :params, :user
def fail!(error)
puts "[exception]: error"
@error = error
end
def render_result(response)
if response.status == 200
@result = JSON.parse(response.body)
end
end
def valid_params
{
login: @params[:login],
repo_identifier: @params[:repo_identifier],
filepath: @params[:filepath],
branch: @params[:branch],
new_branch: @params[:new_branch],
sha: @params[:sha]
}
end
def file_params
Hash.new.merge(
branch: @params[:branch],
sha: @params[:sha],
new_branch: @params[:new_branch],
from_path: @params[:from_path],
message: @params[:message],
content: Base64.encode64(@params[:content])
).compact
end
end
end