ADD protected branch Features

This commit is contained in:
Jasder
2020-12-03 15:24:40 +08:00
parent a24f0f8b45
commit 6a8ae5234b
40 changed files with 1252 additions and 11 deletions

View File

@@ -13,7 +13,7 @@ class Gitea::Repository::Branches::GetService < Gitea::ClientService
def call
response = get(url, params)
render_data(response)
render_200_response(response)
end
private

View File

@@ -8,7 +8,7 @@ class Gitea::Repository::Branches::ListService < Gitea::ClientService
def call
response = get(url, params)
render_data(response)
render_200_response(response)
end
private

View File

@@ -18,7 +18,8 @@ class Gitea::Repository::CreateService < Gitea::ClientService
end
def call
post(url, request_params)
response = post(url, request_params)
render_201_response(response)
end
private

View File

@@ -29,7 +29,9 @@ class Gitea::Repository::Entries::CreateService < Gitea::ClientService
end
def call
post(url, params)
response = post(url, params)
render_201_response(response)
end
private

View File

@@ -14,7 +14,9 @@ class Gitea::Repository::ForkService < Gitea::ClientService
end
def call
post(url, request_params)
response = post(url, request_params)
render_202_response(response)
end
private

View File

@@ -31,7 +31,9 @@ class Gitea::Repository::MigrateService < Gitea::ClientService
end
def call
post(url, request_params)
response = post(url, request_params)
render_201_response(response)
end
private

View File

@@ -0,0 +1,76 @@
# Create a branch protections for a repository
class Gitea::Repository::ProtectedBranches::CreateService < Gitea::ClientService
attr_reader :owner, :repo, :body, :token
# owner: owner of the repo
# repo: name of the repo
# body:
# {
# "approvals_whitelist_teams": [
# "string"
# ],
# "approvals_whitelist_username": [
# "string"
# ],
# "block_on_outdated_branch": true,
# "block_on_rejected_reviews": true,
# "branch_name": "string",
# "dismiss_stale_approvals": true,
# "enable_approvals_whitelist": true,
# "enable_merge_whitelist": true,
# "enable_push": true,
# "enable_push_whitelist": true,
# "enable_status_check": true,
# "merge_whitelist_teams": [
# "string"
# ],
# "merge_whitelist_usernames": [
# "string"
# ],
# "protected_file_patterns": "string",
# "push_whitelist_deploy_keys": true,
# "push_whitelist_teams": [
# "string"
# ],
# "push_whitelist_usernames": [
# "string"
# ],
# "require_signed_commits": true,
# "required_approvals": 0,
# "status_check_contexts": [
# "string"
# ]
# }
def initialize(owner, repo, body={}, token=nil)
@owner = owner
@repo = repo
@body = body
@token = token
end
def call
response = post(url, params)
status, message, body = render_response(response)
json_format(status, message, body)
end
private
def params
Hash.new.merge(token: token, data: body)
end
def url
"/repos/#{owner}/#{repo}/branch_protections".freeze
end
def json_format(status, message, body)
case status
when 201 then success(body)
else
error(message, status)
end
end
end

View File

@@ -0,0 +1,39 @@
# Delete a specific branch protection for the repository
class Gitea::Repository::ProtectedBranches::DestroyService < Gitea::ClientService
attr_reader :owner, :repo, :name, :token
# owner: owner of the repo
# repo: name of the repo
# name: name of protected branch
# eg:
# Gitea::Repository::ProtectedBranches::DestroyService.call(user.login, repo.identifier, branch_name, user.gitea_token)
def initialize(owner, repo, name, token=nil)
@owner = owner
@repo = repo
@name = name
@token = token
end
def call
response = delete(url, params)
status, message = render_response(response)
json_format(status, message)
end
private
def params
Hash.new.merge(token: token, data: name)
end
def url
"/repos/#{owner}/#{repo}/branch_protections/#{name}".freeze
end
def json_format(status, message)
case status
when 204 then success
when 404 then error(message, 404)
end
end
end

View File

@@ -0,0 +1,78 @@
# Edit a branch protections for a repository. Only fields that are set will be changed
class Gitea::Repository::ProtectedBranches::UpdateService < Gitea::ClientService
attr_reader :owner, :repo, :name, :body, :token
# owner: owner of the repo
# repo: name of the repo
# nmae: name of protected branch
# body:
# {
# "approvals_whitelist_teams": [
# "string"
# ],
# "approvals_whitelist_username": [
# "string"
# ],
# "block_on_outdated_branch": true,
# "block_on_rejected_reviews": true,
# "branch_name": "string",
# "dismiss_stale_approvals": true,
# "enable_approvals_whitelist": true,
# "enable_merge_whitelist": true,
# "enable_push": true,
# "enable_push_whitelist": true,
# "enable_status_check": true,
# "merge_whitelist_teams": [
# "string"
# ],
# "merge_whitelist_usernames": [
# "string"
# ],
# "protected_file_patterns": "string",
# "push_whitelist_deploy_keys": true,
# "push_whitelist_teams": [
# "string"
# ],
# "push_whitelist_usernames": [
# "string"
# ],
# "require_signed_commits": true,
# "required_approvals": 0,
# "status_check_contexts": [
# "string"
# ]
# }
# eq:
# Gitea::Repository::ProtectedBranches::UpdateService.call(user.login, repo.identifier, branch_name, body, user.gitea_token)
def initialize(owner, repo, name, body, token=nil)
@owner = owner
@repo = repo
@name = name
@body = body
@token = token
end
def call
response = patch(url, params)
status, message, body = render_response(response)
json_format(status, message, body)
end
private
def params
Hash.new.merge(token: token, data: body)
end
def url
"/repos/#{owner}/#{repo}/branch_protections/#{name}".freeze
end
def json_format(status, message, body)
case status
when 200 then success(body)
else
error(message, status)
end
end
end

View File

@@ -15,7 +15,9 @@ class Gitea::Repository::SyncMirroredService < Gitea::ClientService
end
def call
post(url, request_params)
response = post(url, request_params)
render_200_no_body(response)
end
private