Class: Pindo::GiteeClient
- Inherits:
-
Object
- Object
- Pindo::GiteeClient
- Defined in:
- lib/pindo/client/giteeclient.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#base_url ⇒ Object
Returns the value of attribute base_url.
Instance Method Summary collapse
- #gitee_create_repo(owner: nil, repo_name: nil, public_type: 0) ⇒ Object
-
#initialize(access_token: nil) ⇒ GiteeClient
constructor
A new instance of GiteeClient.
Constructor Details
#initialize(access_token: nil) ⇒ GiteeClient
Returns a new instance of GiteeClient.
12 13 14 15 |
# File 'lib/pindo/client/giteeclient.rb', line 12 def initialize(access_token:nil) @base_url = "https://gitee.com" @access_token = access_token end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
10 11 12 |
# File 'lib/pindo/client/giteeclient.rb', line 10 def access_token @access_token end |
#base_url ⇒ Object
Returns the value of attribute base_url.
9 10 11 |
# File 'lib/pindo/client/giteeclient.rb', line 9 def base_url @base_url end |
Instance Method Details
#gitee_create_repo(owner: nil, repo_name: nil, public_type: 0) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/pindo/client/giteeclient.rb', line 19 def gitee_create_repo(owner:nil, repo_name:nil, public_type:0) body_params = { access_token:access_token, name:repo_name, path:repo_name, org:owner, public:public_type, # private:true, has_issues:true, has_wiki:true, auto_init:false, gitignore_template:"C", license_template:"AGPL-3.0" } puts body_params # repao_name_str = %Q{"name": "#{repo_name}",} # body_str = '{ "access_token": "' + access_token + '",' + repao_name_str + '"has_issues": true, "has_wiki": true, "private": "true", "auto_init":false, "gitignore_template":"C", "license_template":"AGPL-3.0"' + '}' body_str = body_params.to_json url = @base_url + "/api/v5/orgs/#{owner}/repos" # puts body_str con = Faraday.new res = con.post do |req| req.url url req.headers['Content-Type'] = 'application/json' req.body = body_str end # 解析 JSON 响应 begin response_body = JSON.parse(res.body) rescue JSON::ParserError => e puts "[❌] Gitee API 响应解析失败: #{e.message}" puts "响应内容: #{res.body}" return false end # 检查响应状态 if response_body['error'].nil? && response_body['message'].nil? puts "[✔] Gitee 仓库创建成功: #{repo_name}" return true else error_msg = response_body['error'] || response_body['message'] || '未知错误' puts "[❌] Gitee 仓库创建失败: #{error_msg}" puts "响应详情: #{response_body}" if ENV['PINDO_DEBUG'] return false end end |