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,35 @@
# Check if a pull request has been merged
class Gitea::PullRequest::CheckService < Gitea::ClientService
attr_reader :user, :repo, :pull_request_id
# user: 用户
# repo: 仓库名称/标识
# pull_request_id: pull request主键id
def initialize(user, repo, pull_request_id)
super({token: user.gitea_token})
@user = user
@repo = repo
@pull_request_id = pull_request_id
end
def call
response = get(url, params)
render_response(response)
end
private
def params
Hash.new.merge(token: user.gitea_token)
end
def url
"/repos/#{user.login}/#{repo}/pulls/#{pull_request_id}/merge".freeze
end
def render_response(response)
case response.status
when 204 then true
when 404 then false
end
end
end

View File

@@ -0,0 +1,34 @@
class Gitea::PullRequest::CreateService < Gitea::ClientService
attr_reader :user, :repo, :params
# params ex:
# {
# title: 'pull request title',
# body: 'pull request content',
# head: 'develop', // from branch 源分支
# base: 'master' // to branch 目标分支
# }
# 以上列子说明从develop分支合并到master分支
# repo: 仓库名称
def initialize(user, repo, params={})
@user = user
@repo = repo
@params = params
end
def call
post(url, request_params)
end
private
def url
"/repos/#{@user.login}/#{@repo}/pulls".freeze
end
def request_params
Hash.new.merge(token: @user.gitea_token, data: @params)
end
end

View File

@@ -0,0 +1,37 @@
# Get a pull request
class Gitea::PullRequest::GetService < Gitea::ClientService
attr_reader :user, :repo, :pull_request_id
# user: 用户
# repo: 仓库名称/标识
# pull_request_id: pull request主键id
def initialize(user, repo, pull_request_id)
super({token: user.gitea_token})
@user = user
@repo = repo
@pull_request_id = pull_request_id
end
def call
response = get(url, params)
render_result(response)
end
private
def params
Hash.new.merge(token: user.gitea_token)
end
def url
"/repos/#{user.login}/#{repo}/pulls/#{pull_request_id}".freeze
end
def render_result(response)
case response.status
when 200
JSON.parse(response.body)
else
nil
end
end
end

View File

@@ -0,0 +1,34 @@
# Get a list of all commits from a repository
class Gitea::PullRequest::ListService < Gitea::ClientService
attr_reader :user, :repo
# sha: SHA or branch to start listing commits from (usually 'master')
def initialize(user, repo)
@user = user
@repo = repo
end
def call
response = get(url, params)
render_result(response)
end
private
def params
Hash.new.merge(token: user.gitea_token)
end
def url
"/repos/#{@user.try(:login)}/#{@repo}/pulls".freeze
end
def render_result(response)
body = JSON.parse(response.body)
case response.status
when 200
body
else
{status: -1, message: "#{body['message']}"}
end
end
end

View File

@@ -0,0 +1,31 @@
# Merge a pull request
class Gitea::PullRequest::MergeService < Gitea::ClientService
attr_reader :user, :repo, :pull_request_id, :params
# parameters:
# repo: name of the repo
# pull_request_id: index of the pull request to merge
# params:
# title: merge标题
# message: merge说明
def initialize(user, repo, pull_request_id, params={})
@user = user
@repo = repo
@params = params
@pull_request_id = pull_request_id
end
def call
post(url, request_params)
end
private
def url
"/repos/#{user.login}/#{repo}/pulls/#{pull_request_id}/merge"
end
def request_params
Hash.new.merge(token: user.gitea_token, data: params)
end
end

View File

@@ -0,0 +1,26 @@
class Gitea::PullRequest::UpdateService < Gitea::ClientService
attr_reader :user, :repo, :params,:pull_request_id
def initialize(user, repo, params,pull_request_id)
@user = user
@repo = repo
@params = params
@pull_request_id = pull_request_id
end
def call
put(url, request_params)
end
private
def request_params
Hash.new.merge(token: @user.gitea_token, data: @params)
end
def url
"/repos/#{@user.try(:login)}/#{@repo}/pulls/#{@pull_request_id}".freeze
end
end