gitea-client 1.4.6 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c9bf960c8397bbfa3d3f653e4eb3ec561cee1d855907a1185986af4557d3aef
4
- data.tar.gz: b9783266c48dc655f215d72449032392adc56631e76e1d338a709198628a75e0
3
+ metadata.gz: 3834af0c17b279bc9664771bab2a2da7e96a86ee0cf28d95217cc639c3e516ff
4
+ data.tar.gz: e6e1a73e61ea258ad1b16a1d762668b50b5c55c53cde900116f6ac79f78fabdc
5
5
  SHA512:
6
- metadata.gz: c1945dfcb48db6b8c4b491221aa24e7747d8bd4a6ab244cec0d6179a033f59168bdb20f77d2b67466209fbff63162ea7fdd70d4c9ca4175512681c07918f55d3
7
- data.tar.gz: b7cdd6f65aef90f3a781068ce63b95ec1f14a1d6871f1ad67a531c21845e77b577711e3146e9187368b3111d004cd7885e79a9a14cb52eaadc3f81b26fea1a3e
6
+ metadata.gz: 86d7db185d6028ef1874310f0e4a7f575afcbf463870e77ab044a8b8bddea61d6a58410f24705a78ae3a7d252120c7c33739418ca62c9eb40b1d543e4616a740
7
+ data.tar.gz: 9d7fc586d9f5af93bca7e994005fcedc56d6f0942296d4aad9e6d8ae1c0da4d013392ff4c7cc1eb2b09bdc4fe466d9bc888e573300de0c520d27da8a20e7e0a1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gitea-client (1.4.5)
4
+ gitea-client (1.4.0)
5
5
  rest-client (~> 2.1.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -2,14 +2,12 @@
2
2
 
3
3
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gitea`. To experiment with that code, run `bin/console` for an interactive prompt.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
5
  ## Installation
8
6
 
9
7
  Add this line to your application's Gemfile:
10
8
 
11
9
  ```ruby
12
- gem 'gitea-client'
10
+ gem 'gitea-client', '~> 1.4.0'
13
11
  ```
14
12
 
15
13
  And then execute:
@@ -20,7 +18,7 @@ Or install it yourself as:
20
18
 
21
19
  $ gem install gitea-client
22
20
 
23
- ## Usage
21
+ ## Usage Example
24
22
 
25
23
  ```ruby
26
24
  require 'gitea-client'
@@ -31,6 +29,7 @@ client.get_users_search({query: {q: 'viletyy'}})
31
29
 
32
30
  ```
33
31
 
32
+
34
33
  ## Development
35
34
 
36
35
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -7,6 +7,7 @@ module Gitea
7
7
  def initialize(response)
8
8
  @http_code = response.code
9
9
  @attrs = JSON.parse(response.body) rescue {}
10
+ @message = @attrs['message']
10
11
  end
11
12
 
12
13
  def to_s
data/lib/gitea/api.rb CHANGED
@@ -11,10 +11,3 @@ require_relative 'api/client'
11
11
  require_relative 'api/config'
12
12
  require_relative 'api/exception'
13
13
  require_relative 'api/http'
14
- require_relative 'api/hat/repository'
15
- require_relative 'api/hat/organization'
16
- require_relative 'api/hat/users'
17
- require_relative 'api/hat/admin'
18
- require_relative 'api/hat/client'
19
- require_relative 'api/hat/config'
20
- require_relative 'api/hat/http'
data/lib/gitea/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gitea
4
- VERSION = "1.4.6"
4
+ VERSION = "1.5.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitea-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.6
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - viletyy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-04 00:00:00.000000000 Z
11
+ date: 2024-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -49,13 +49,6 @@ files:
49
49
  - lib/gitea/api/client.rb
50
50
  - lib/gitea/api/config.rb
51
51
  - lib/gitea/api/exception.rb
52
- - lib/gitea/api/hat/admin.rb
53
- - lib/gitea/api/hat/client.rb
54
- - lib/gitea/api/hat/config.rb
55
- - lib/gitea/api/hat/http.rb
56
- - lib/gitea/api/hat/organization.rb
57
- - lib/gitea/api/hat/repository.rb
58
- - lib/gitea/api/hat/users.rb
59
52
  - lib/gitea/api/http.rb
60
53
  - lib/gitea/api/issue.rb
61
54
  - lib/gitea/api/miscellaneous.rb
@@ -92,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
85
  - !ruby/object:Gem::Version
93
86
  version: '0'
94
87
  requirements: []
95
- rubygems_version: 3.2.3
88
+ rubygems_version: 3.4.10
96
89
  signing_key:
97
90
  specification_version: 4
98
91
  summary: Gitea API 库
@@ -1,13 +0,0 @@
1
- module Gitea
2
- module Api
3
- module Hat
4
- module Admin
5
-
6
- def patch_admin_users_by_username(username, opt = {})
7
- @http.patch("/admin/users/#{username}", opt)
8
- end
9
-
10
- end # Admin
11
- end # Hat
12
- end # Api
13
- end # Gitea
@@ -1,48 +0,0 @@
1
- module Gitea
2
- module Api
3
- module Hat
4
- class Client
5
-
6
- # 构造Api client,用于操作Api数据
7
- # @param opts [Hash] 构造client时的参数选项
8
- # @option opts [string] domain [必填] gitea服务地址
9
- # @option opts [string] hat_base_url [必填] api相对路径
10
- # @option opts [string] admin_username [必填] 管理员账号
11
- # @option opts [string] admin_password [必填] 管理员密码
12
- # @option opts [string] username [选填] 用户账号
13
- # @option opts [string] password [选填] 用户密码
14
- # @option opts [string] gitea_token [选填] 用户token
15
- def initialize(opts)
16
- @config = Config.new(opts)
17
- Gitea::Common::Logging.set_log_file(@config.log_filepath)
18
- @http = Http.new(@config)
19
- end
20
-
21
- def config
22
- @config
23
- end
24
-
25
- def config=(config)
26
- unless config.is_a?(Gitea::Api::Hat::Config)
27
- fail Exception, "load config failure!"
28
- end
29
- @config = config
30
- @http = Http.new(config)
31
- end
32
-
33
- def token
34
- @config.token
35
- end
36
-
37
- def token=(token)
38
- @config.token = token
39
- end
40
-
41
- include Gitea::Api::Hat::Repository
42
- include Gitea::Api::Hat::Users
43
- include Gitea::Api::Hat::Organization
44
- include Gitea::Api::Hat::Admin
45
- end
46
- end # Hat
47
- end # Api
48
- end # Gitea
@@ -1,36 +0,0 @@
1
- module Gitea
2
- module Api
3
-
4
- module Hat
5
- class Config < Common::Struct::Base
6
- attrs :domain, :hat_base_url, :username, :password, :token, :open_timeout, :read_timeout, :log_filepath
7
-
8
- def initialize(opts = {})
9
- super(opts)
10
-
11
- valid!
12
- normalize_domain
13
- end
14
-
15
- private
16
- def valid!
17
- if @domain.nil? || @hat_base_url.nil?
18
- fail Exception, "@domain, @hat_base_url not permit blank."
19
- end
20
- end
21
-
22
- def normalize_domain
23
- uri = URI.parse(domain)
24
- uri = URI.parse(domain)
25
- uri = URI.parse("http://#{domain}") unless uri.scheme
26
-
27
- if uri.scheme != 'http' and uri.scheme != 'https'
28
- fail ClientError, "Only HTTP and HTTPS domain are accepted."
29
- end
30
-
31
- @domain = uri
32
- end
33
- end
34
- end # Hat
35
- end # Api
36
- end # Gitea
@@ -1,132 +0,0 @@
1
- require 'base64'
2
- require 'json'
3
-
4
- module Gitea
5
- module Api
6
- module Hat
7
- class Http
8
- DEFAULT_CONTENT_TYPE = 'application/json'
9
- TOKEN_HEADER = 'Authorization'
10
- OPEN_TIMEOUT = 10
11
- READ_TIMEOUT = 120
12
-
13
-
14
- def initialize(config)
15
- @config = config
16
- end
17
-
18
- include Gitea::Common::Logging
19
-
20
- def get_request_url(api_url)
21
- url = @config.domain.dup
22
- url.query = nil
23
- url.fragment = nil
24
- [url.to_s, @config.hat_base_url, api_url].join('')
25
- end
26
-
27
- def get(api_url = '', http_options = {}, &block)
28
- do_request('GET', api_url, http_options, &block)
29
- end
30
-
31
- def put(api_url = '', http_options = {}, &block)
32
- do_request('PUT', api_url, http_options, &block)
33
- end
34
-
35
- def patch(api_url = '', http_options = {}, &block)
36
- do_request('PATCH', api_url, http_options, &block)
37
- end
38
-
39
- def post(api_url = '', http_options = {}, &block)
40
- do_request('POST', api_url, http_options, &block)
41
- end
42
-
43
- def delete(api_url = '', http_options = {}, &block)
44
- do_request('DELETE', api_url, http_options, &block)
45
- end
46
-
47
- def head(api_url = '', http_options = {}, &block)
48
- do_request('HEAD', api_url, http_options, &block)
49
- end
50
-
51
- def options(api_url = '', http_options = {}, &block)
52
- do_request('OPTIONS', api_url, http_options, &block)
53
- end
54
-
55
- private
56
- # Do Http request
57
- def do_request(verb, api_url, http_options = {}, &block)
58
-
59
- headers = http_options[:headers] || {}
60
- headers['user-agent'] = get_user_agent
61
- headers['date'] = Time.now.httpdate
62
- headers['content-type'] ||= DEFAULT_CONTENT_TYPE
63
-
64
- if @config.username and @config.password
65
- headers[TOKEN_HEADER] = 'Basic ' + Base64::encode64(@config.username + ":" + @config.password)
66
- end
67
-
68
- headers[:params] = http_options[:query] || {}
69
- headers[:params].merge!({access_token: @config.token}) if @config.token
70
- logger.info("Gitea Hat Client Begin a Request!...")
71
- logger.info("Send HTTP request, verb: #{verb}, http_options: #{http_options}")
72
- logger.info("Relative Url: #{api_url}")
73
- logger.info("Headers: #{headers}")
74
- request = RestClient::Request.new(
75
- :method => verb,
76
- :url => get_request_url(api_url),
77
- :headers => headers,
78
- :payload => http_options[:body],
79
- :open_timeout => @config.open_timeout || OPEN_TIMEOUT,
80
- :read_timeout => @config.read_timeout || READ_TIMEOUT
81
- )
82
-
83
-
84
- response = request.execute do |resp, &blk|
85
- if resp.code >= 300
86
- e = Gitea::Api::ServerError.new(resp)
87
- logger.error(e.to_s)
88
- raise e
89
- else
90
- resp.return!(&blk)
91
- end
92
- end
93
-
94
- # If streaming read_body is used, we need to create the
95
- # RestClient::Response ourselves
96
- unless response.is_a?(RestClient::Response)
97
- if response.code.to_i >= 300
98
- body = response.body
99
- if RestClient::version < '2.1.0'
100
- body = RestClient::Request.decode(response['content-encoding'], response.body)
101
- end
102
- response = RestClient::Response.create(body, response, request)
103
- e = Gitea::Api::ServerError.new(response)
104
- logger.error(e.to_s)
105
- raise e
106
- end
107
- response = RestClient::Response.create(nil, response, request)
108
- response.return!
109
- end
110
-
111
- begin
112
- if response.headers.has_key?(:x_total) || response.headers.has_key?(:x_total_count)
113
- return {data: JSON.parse(response), total_data: response.headers[:x_total_count]}
114
- else
115
- return JSON.parse(response)
116
- end
117
- rescue => e
118
- logger.error(e.to_s)
119
- return {}
120
- end
121
-
122
- logger.info("Gitea Hat Client Success End a Request!...")
123
- end
124
-
125
- def get_user_agent
126
- "gitea-client/#{VERSION}"
127
- end
128
-
129
- end
130
- end # Hat
131
- end # Common
132
- end # Gitea
@@ -1,25 +0,0 @@
1
- module Gitea
2
- module Api
3
- module Hat
4
- module Organization
5
-
6
- def patch_orgs_by_org(org, opt = {})
7
- @http.patch("/orgs/#{org}", opt)
8
- end
9
-
10
- def post_orgs(opt = {})
11
- @http.post("/orgs", opt)
12
- end
13
-
14
- def put_teams_repos_by_id_org(id, org, opt = {})
15
- @http.put("/teams/#{id}/repos/#{org}", opt)
16
- end
17
-
18
- def delete_teams_repos_by_id_org(id, org, opt = {})
19
- @http.delete("/teams/#{id}/repos/#{org}", opt)
20
- end
21
-
22
- end # Organization
23
- end # Hat
24
- end # Api
25
- end # Gitea
@@ -1,181 +0,0 @@
1
- module Gitea
2
- module Api
3
- module Hat
4
- module Repository
5
-
6
- def get_repos_actions_by_owner_repo(owner, repo, opt = {})
7
- @http.get("/repos/#{owner}/#{repo}/actions", opt)
8
- end
9
-
10
- def post_repos_actions_runs_jobs_by_owner_repo_run_job(owner, repo, run, job, opt = {})
11
- @http.post("/repos/#{owner}/#{repo}/actions/runs/#{run}/jobs/#{job}", opt)
12
- end
13
-
14
- def post_repos_actions_disable(owner, repo, opt= {})
15
- @http.post("/repos/#{owner}/#{repo}/actions/disable", opt)
16
- end
17
-
18
- def post_repos_actions_enable(owner, repo, opt= {})
19
- @http.post("/repos/#{owner}/#{repo}/actions/enable", opt)
20
- end
21
-
22
- def get_repos_contents_by_owner_repo(owner, repo, opt = {})
23
- @http.get("/repos/#{owner}/#{repo}/contents", opt)
24
- end
25
-
26
- def get_repos_contents_by_owner_repo_filepath(owner, repo, filepath, opt = {})
27
- @http.get("/repos/#{owner}/#{repo}/contents/#{filepath}", opt)
28
- end
29
-
30
- def get_repos_find_by_owner_repo(owner, repo, opt = {})
31
- @http.get("/repos/#{owner}/#{repo}/find", opt)
32
- end
33
-
34
- def get_repos_git_commits_by_owner_repo_sha(owner, repo, sha, opt = {})
35
- @http.get("/repos/#{owner}/#{repo}/git/commits/#{sha}", opt)
36
- end
37
-
38
- def get_repos_commits_diff_by_owner_repo_sha(owner, repo, sha, opt = {})
39
- @http.get("/repos/#{owner}/#{repo}/commits/#{sha}/diff", opt)
40
- end
41
-
42
- def post_repos_hooks_by_owner_repo(owner, repo, opt = {})
43
- @http.post("/repos/#{owner}/#{repo}/hooks", opt)
44
- end
45
-
46
- def patch_repos_hooks_by_owner_repo_id(owner, repo, id, opt = {})
47
- @http.patch("/repos/#{owner}/#{repo}/hooks/#{id}", opt)
48
- end
49
-
50
- def get_repos_hooks_hooktasks_by_owner_repo_id(owner, repo, id, opt = {})
51
- @http.get("/repos/#{owner}/#{repo}/hooks/#{id}/hooktasks", opt)
52
- end
53
-
54
- def get_repos_releases_latest_by_owner_repo(owner, repo, opt = {})
55
- @http.get("/repos/#{owner}/#{repo}/releases/latest", opt)
56
- end
57
-
58
- def get_repos_releases_by_owner_repo(owner, repo, opt = {})
59
- @http.get("/repos/#{owner}/#{repo}/releases", opt)
60
- end
61
-
62
- def get_repos_releases_by_owner_repo_id(owner, repo, opt = {})
63
- @http.get("/repos/#{owner}/#{repo}/releases/#{id}", opt)
64
- end
65
-
66
- def post_repos_releases_by_owner_repo(owner, repo, opt = {})
67
- @http.post("/repos/#{owner}/#{repo}/releases", opt)
68
- end
69
-
70
- def patch_repos_releases_by_owner_repo_id(owner, repo, id, opt = {})
71
- @http.patch("/repos/#{owner}/#{repo}/releases/#{id}", opt)
72
- end
73
-
74
- def get_repos_branch_name_set_by_owner_repo(owner, repo, opt = {})
75
- @http.get("/repos/#{owner}/#{repo}/branch_name_set", opt)
76
- end
77
-
78
- def get_repos_branches_by_owner_repo(owner, repo, opt={})
79
- @http.get("/repos/#{owner}/#{repo}/branches", opt)
80
- end
81
-
82
- def get_repos_branches_branches_slice_by_owner_repo(owner, repo, opt = {})
83
- @http.get("/repos/#{owner}/#{repo}/branches/branches_slice", opt)
84
- end
85
-
86
- def post_repos_branches_restore_by_owner_repo(owner, repo, opt = {})
87
- @http.post("/repos/#{owner}/#{repo}/branches/restore", opt)
88
- end
89
-
90
- def get_repos_tag_name_set_by_owner_repo(owner, repo, opt = {})
91
- @http.get("/repos/#{owner}/#{repo}/tag_name_set", opt)
92
- end
93
-
94
- def get_repos_tags_by_owner_repo(owner, repo, opt = {})
95
- @http.get("/repos/#{owner}/#{repo}/tags", opt)
96
- end
97
-
98
- def get_repos_tags_by_owner_repo_tag(owner, repo, tag, opt = {})
99
- @http.get("/repos/#{owner}/#{repo}/tags/#{tag}", opt)
100
- end
101
-
102
- def get_repos_branch_tag_count_by_owner_repo(owner, repo, opt = {})
103
- @http.get("/repos/#{owner}/#{repo}/branch_tag_count", opt)
104
- end
105
-
106
- def get_repos_readme_by_owner_repo(owner, repo, opt = {})
107
- @http.get("/repos/#{owner}/#{repo}/readme", opt)
108
- end
109
-
110
- def get_repos_readme_by_owner_repo_filepath(owner, repo, filepath, opt = {})
111
- @http.get("/repos/#{owner}/#{repo}/readme/#{filepath}", opt)
112
- end
113
-
114
- def get_repos_commits_slice_by_owner_repo(owner, repo, opt = {})
115
- @http.get("/repos/#{owner}/#{repo}/commits_slice", opt)
116
- end
117
-
118
- def get_repos_recent_commits_by_owner_repo(owner, repo, opt = {})
119
- @http.get("/repos/#{owner}/#{repo}/recent_commits", opt)
120
- end
121
-
122
- def get_repos_contributors_by_owner_repo(owner, repo, opt = {})
123
- @http.get("/repos/#{owner}/#{repo}/contributors", opt)
124
- end
125
-
126
- def get_repos_contributors_stat_by_owner_repo(owner, repo, opt = {})
127
- @http.get("/repos/#{owner}/#{repo}/contributors/stat", opt)
128
- end
129
-
130
- def get_repos_code_stats_by_owner_repo(owner, repo, opt = {})
131
- @http.get("/repos/#{owner}/#{repo}/code_stats", opt)
132
- end
133
-
134
- def get_repos_count_by_owner_repo(owner, repo, opt = {})
135
- @http.get("/repos/#{owner}/#{repo}/count", opt)
136
- end
137
-
138
- def get_repos_file_commits_by_owner_repo_filepath(owner, repo, filepath, opt = {})
139
- @http.get("/repos/#{owner}/#{repo}/file_commits/#{filepath}", opt)
140
- end
141
-
142
- def get_repos_blame_by_owner_repo(owner, repo, opt = {})
143
- @http.get("/repos/#{owner}/#{repo}/blame", opt)
144
- end
145
-
146
- def get_repos_compare_by_owner_repo_baseref_headref(owner, repo, baseRef, headRef, opt = {})
147
- @http.get("/repos/#{owner}/#{repo}/compare/#{baseRef}...#{headRef}", opt)
148
- end
149
-
150
- def post_repos_transfer_by_owner_repo(owner, repo, opt = {})
151
- @http.post("/repos/#{owner}/#{repo}/transfer", opt)
152
- end
153
-
154
- def get_repos_pulls_by_owner_repo_index(owner, repo, index, opt = {})
155
- @http.get("/repos/#{owner}/#{repo}/pulls/#{index}", opt)
156
- end
157
-
158
- def get_repos_pulls_commits_by_owner_repo_index(owner, repo, index, opt = {})
159
- @http.get("/repos/#{owner}/#{repo}/pulls/#{index}/commits", opt)
160
- end
161
-
162
- def get_repos_pulls_files_by_owner_repo_index(owner, repo, index, opt = {})
163
- @http.get("/repos/#{owner}/#{repo}/pulls/#{index}/files", opt)
164
- end
165
-
166
- def post_repos_contents_batch_by_owner_repo(owner, repo, opt = {})
167
- @http.post("/repos/#{owner}/#{repo}/contents/batch", opt)
168
- end
169
-
170
- def get_repos_pulls_versions_by_owner_repo_index(owner, repo, index, opt = {})
171
- @http.get("/repos/#{owner}/#{repo}/pulls/#{index}/versions", opt)
172
- end
173
-
174
- def get_repos_pulls_versions_diff_by_owner_repo_index_id(owner, repo, index, versionID, opt = {})
175
- @http.get("/repos/#{owner}/#{repo}/pulls/#{index}/versions/#{versionID}/diff", opt)
176
- end
177
-
178
- end # Repository
179
- end # Hat
180
- end # Api
181
- end # Gitea
@@ -1,13 +0,0 @@
1
- module Gitea
2
- module Api
3
- module Hat
4
- module Users
5
-
6
- def get_users_heatmap_by_username(username, opt = {})
7
- @http.get("/users/#{username}/heatmap", opt)
8
- end
9
-
10
- end # Users
11
- end # Hat
12
- end # Api
13
- end # Gitea