add: gitea api user

This commit is contained in:
viletyy 2022-05-05 14:28:35 +08:00
parent 467df5fa55
commit 2c4dab9d39
4 changed files with 166 additions and 3 deletions

View File

@ -3,6 +3,7 @@ require_relative 'api/issue'
require_relative 'api/repository'
require_relative 'api/settings'
require_relative 'api/user'
require_relative 'api/organization'
require_relative 'api/client'
require_relative 'api/config'
require_relative 'api/exception'

View File

@ -20,6 +20,7 @@ module Gitea
include Gitea::Api::Repository
include Gitea::Api::Settings
include Gitea::Api::User
include Gitea::Api::Organization
end
end # User
end # Gitea

View File

@ -53,14 +53,13 @@ module Gitea
headers['user-agent'] = get_user_agent
headers['date'] = Time.now.httpdate
headers['content-type'] ||= DEFAULT_CONTENT_TYPE
headers[TOKEN_HEADER] = @config.token if @config.token
if @config.username and @config.password
headers[TOKEN_HEADER] = 'Basic ' + Base64::Encoding(@config.username + ":" + @config.password)
headers[TOKEN_HEADER] = 'Basic ' + Base64::encode64(@config.username + ":" + @config.password)
end
headers[:params] = http_options[:query] || {}
headers[:params].merge!({access_token: @config.token}) if @config.token
logger.debug("Send HTTP request, verb: #{verb}, http_options: #{http_options}")
request = RestClient::Request.new(

View File

@ -0,0 +1,162 @@
module Gitea
module Api
module Organization
def get_orgs(opt={})
@http.get("/orgs", opt)
end
def post_orgs(opt={})
@http.post("/orgs", opt)
end
def get_orgs_by_org(org, opt={})
@http.get("/orgs/#{org}", opt)
end
def delete_orgs_by_org(org, opt={})
@http.delete("/orgs/#{org}", opt)
end
def patch_orgs_by_org(org, opt={})
@http.patch("/orgs/#{org}", opt)
end
def get_orgs_hooks_by_org(org, opt={})
@http.get("/orgs/#{org}/hooks", opt)
end
def post_orgs_hooks_by_org(org, opt={})
@http.post("/orgs/#{org}/hooks", opt)
end
def get_orgs_hooks_by_org_id(org, id, opt={})
@http.get("/orgs/#{org}/hooks/#{id}", opt)
end
def delete_orgs_hooks_by_org_id(org, id, opt={})
@http.delete("/orgs/#{org}/hooks/#{id}", opt)
end
def patch_orgs_hooks_by_org_id(org, id, opt={})
@http.patch("/orgs/#{org}/hooks/#{id}", opt)
end
def get_orgs_labels_by_org(org, opt={})
@http.get("/orgs/#{org}/labels", opt)
end
def post_orgs_labels_by_org(org, opt={})
@http.post("/orgs/#{org}/labels", opt)
end
def get_orgs_labels_by_org_id(org, id, opt={})
@http.get("/orgs/#{org}/labels/#{id}", opt)
end
def delete_orgs_labels_by_org_id(org, id, opt={})
@http.delete("/orgs/#{org}/labels/#{id}", opt)
end
def patch_orgs_labels_by_org_id(org, id, opt={})
@http.patch("/orgs/#{org}/labels/#{id}", opt)
end
def get_orgs_members_by_org(org, opt={})
@http.get("/orgs/#{org}/members", opt)
end
def get_orgs_members_by_org_username(org, username, opt={})
@http.get("/orgs/#{org}/members/#{username}", opt)
end
def delete_orgs_members_by_org_username(org, username, opt={})
@http.delete("/orgs/#{org}/members/#{username}", opt)
end
def get_orgs_public_members_by_org(org, opt={})
@http.get("/orgs/#{org}/public_members", opt)
end
def get_orgs_public_members_by_org_username(org, username, opt={})
@http.get("/orgs/#{org}/public_members/#{username}", opt)
end
def put_orgs_public_members_by_org_username(org, username, opt={})
@http.put("/orgs/#{org}/public_members/#{username}", opt)
end
def delete_orgs_public_members_by_org_username(org, username, opt={})
@http.delete("/orgs/#{org}/public_members/#{username}", opt)
end
def get_orgs_repos_by_org(org, opt={})
@http.get("/orgs/#{org}/repos", opt)
end
def post_orgs_repos_by_org(org, opt={})
@http.post("/orgs/#{org}/repos", opt)
end
def get_orgs_teams_by_org(org, opt={})
@http.get("/orgs/#{org}/teams", opt)
end
def post_orgs_teams_by_org(org, opt={})
@http.post("/orgs/#{org}/teams", opt)
end
def get_orgs_temas_search_by_org(org, opt={})
@http.get("/orgs/#{org}/teams/search", opt)
end
def get_teams_by_id(id, opt={})
@http.get("/teams/#{id}", opt)
end
def delete_teams_by_id(id, opt={})
@http.delete("/teams/#{id}", opt)
end
def patch_teams_by_id(id, opt={})
@http.patch("/teams/#{id}", opt)
end
def get_teams_members_by_id(id, opt={})
@http.get("/teams/#{id}/members", opt)
end
def get_teams_members_by_id_username(id, username, opt={})
@http.get("/teams/#{id}/members/#{username}", opt)
end
def put_teams_members_by_id_username(id, username, opt={})
@http.put("/teams/#{id}/members/#{username}", opt)
end
def delete_teams_members_by_id_username(id, username, opt={})
@http.delete("/teams/#{id}/members/#{username}", opt)
end
def get_teams_repos_by_id(id, opt={})
@http.get("/teams/#{id}/repos", opt)
end
def put_teams_repos_by_id_org_repo(id, org, repo, opt={})
@http.put("/teams/#{id}/repos/#{org}/#{repo}", opt)
end
def delete_teams_repos_by_id_org_repo(id, org, repo, opt={})
@http.delete("/teams/#{id}/repos/#{org}/#{repo}", opt)
end
def get_user_orgs(opt={})
@http.get("/user/orgs", opt)
end
def get_users_orgs_by_username(username, opt={})
@http.get("/users/#{usernmae}/orgs", opt)
end
end # Organization
end # Api
end # Gitea