gitea-client 1.6.0 → 1.6.1

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: 53fe0f2181f0d524c29763ffe01e7ba2b41659f1802642f5e08a78548a4ded69
4
- data.tar.gz: 89c607503606f38aabad618c2d3f8f7db9e602057b9042fc7e2bd95bbbfea7bd
3
+ metadata.gz: f73d7bdbddf949f1429f3391a5cb91b055a4fd2a12c46b8e57a0d23d7fa24bea
4
+ data.tar.gz: 7e24b0c22048dd898836642fb6ffa39ae8da59590d3a91fd8bd774b344bd4e6b
5
5
  SHA512:
6
- metadata.gz: 20bfb39421e59ca4d339a1de6bb890e3adbdc6a4725e89e8722bc31d85d3935352ac176b00d5a849927aad19bb6d2ab57a19292c635c3954299b0cdee08530a3
7
- data.tar.gz: ef6bfae120d497a9bb285818359b7cb4e0476dc7625b2d767dbf384625b40c614262a050175ecf65b9ae568686ade91f069c5a9b2acfe662128b0ae82f8ab828
6
+ metadata.gz: 7b0b384ad1bdaca59ba57eec00cb72b574acd99c8e5cf00ccbc232a3520cabcb4ef140fc8ebff42755ebcf144dcab3c13dc1f63197ece0c012c75f4b7da06ffe
7
+ data.tar.gz: f31d595d1688f597c814c1012cc33fa1961f4c30ce09db9bde796bf05423e1eb152f3e7aabce6f0707c76499bd2324e599ed3cf666303acdcfc722db5070042d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gitea-client (1.6.0)
4
+ gitea-client (1.6.1)
5
5
  rest-client (~> 2.1.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -17,6 +17,7 @@ And then execute:
17
17
  Or install it yourself as:
18
18
 
19
19
  $ gem install gitea-client
20
+
20
21
 
21
22
  ## Usage Example
22
23
 
@@ -0,0 +1,12 @@
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
+ end # Admin
10
+ end # Hat
11
+ end # Api
12
+ end # Gitea
@@ -0,0 +1,48 @@
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
@@ -0,0 +1,36 @@
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
@@ -0,0 +1,132 @@
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
@@ -0,0 +1,25 @@
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
@@ -0,0 +1,209 @@
1
+ module Gitea
2
+ module Api
3
+ module Hat
4
+ module Repository
5
+
6
+ def delete_repos_by_owner_repo(owner, repo, opt = {})
7
+ @http.delete("/repos/#{owner}/#{repo}", opt)
8
+ end
9
+
10
+ def get_repos_actions_by_owner_repo(owner, repo, opt = {})
11
+ @http.get("/repos/#{owner}/#{repo}/actions", opt)
12
+ end
13
+
14
+ def post_repos_actions_runs_by_owner_repo(owner, repo, opt = {})
15
+ @http.post("/repos/#{owner}/#{repo}/actions/runs", opt)
16
+ end
17
+
18
+ def post_repos_actions_runs_jobs_by_owner_repo_run_job(owner, repo, run, job, opt = {})
19
+ @http.post("/repos/#{owner}/#{repo}/actions/runs/#{run}/jobs/#{job}", opt)
20
+ end
21
+
22
+ def post_repos_actions_disable(owner, repo, opt= {})
23
+ @http.post("/repos/#{owner}/#{repo}/actions/disable", opt)
24
+ end
25
+
26
+ def post_repos_actions_enable(owner, repo, opt= {})
27
+ @http.post("/repos/#{owner}/#{repo}/actions/enable", opt)
28
+ end
29
+
30
+ def get_repos_contents_by_owner_repo(owner, repo, opt = {})
31
+ @http.get("/repos/#{owner}/#{repo}/contents", opt)
32
+ end
33
+
34
+ def get_repos_contents_by_owner_repo_filepath(owner, repo, filepath, opt = {})
35
+ @http.get("/repos/#{owner}/#{repo}/contents/#{filepath}", opt)
36
+ end
37
+
38
+ def get_repos_find_by_owner_repo(owner, repo, opt = {})
39
+ @http.get("/repos/#{owner}/#{repo}/find", opt)
40
+ end
41
+
42
+ def get_repos_git_commits_by_owner_repo_sha(owner, repo, sha, opt = {})
43
+ @http.get("/repos/#{owner}/#{repo}/git/commits/#{sha}", opt)
44
+ end
45
+
46
+ def get_repos_commits_diff_by_owner_repo_sha(owner, repo, sha, opt = {})
47
+ @http.get("/repos/#{owner}/#{repo}/commits/#{sha}/diff", opt)
48
+ end
49
+
50
+ def get_repos_commits_files_by_owner_repo_sha(owner, repo, sha, opt={})
51
+ @http.get("/repos/#{owner}/#{repo}/commits/#{sha}/files", opt)
52
+ end
53
+
54
+ def get_repos_commits_files_by_owner_repo_sha_filepath(owner, repo, sha, filepath, opt={})
55
+ @http.get("/repos/#{owner}/#{repo}/commits/#{sha}/files/#{filepath}", opt)
56
+ end
57
+
58
+ def post_repos_hooks_by_owner_repo(owner, repo, opt = {})
59
+ @http.post("/repos/#{owner}/#{repo}/hooks", opt)
60
+ end
61
+
62
+ def patch_repos_hooks_by_owner_repo_id(owner, repo, id, opt = {})
63
+ @http.patch("/repos/#{owner}/#{repo}/hooks/#{id}", opt)
64
+ end
65
+
66
+ def get_repos_hooks_hooktasks_by_owner_repo_id(owner, repo, id, opt = {})
67
+ @http.get("/repos/#{owner}/#{repo}/hooks/#{id}/hooktasks", opt)
68
+ end
69
+
70
+ def get_repos_releases_latest_by_owner_repo(owner, repo, opt = {})
71
+ @http.get("/repos/#{owner}/#{repo}/releases/latest", opt)
72
+ end
73
+
74
+ def get_repos_releases_by_owner_repo(owner, repo, opt = {})
75
+ @http.get("/repos/#{owner}/#{repo}/releases", opt)
76
+ end
77
+
78
+ def get_repos_releases_by_owner_repo_id(owner, repo, opt = {})
79
+ @http.get("/repos/#{owner}/#{repo}/releases/#{id}", opt)
80
+ end
81
+
82
+ def post_repos_releases_by_owner_repo(owner, repo, opt = {})
83
+ @http.post("/repos/#{owner}/#{repo}/releases", opt)
84
+ end
85
+
86
+ def patch_repos_releases_by_owner_repo_id(owner, repo, id, opt = {})
87
+ @http.patch("/repos/#{owner}/#{repo}/releases/#{id}", opt)
88
+ end
89
+
90
+ def get_repos_branch_name_set_by_owner_repo(owner, repo, opt = {})
91
+ @http.get("/repos/#{owner}/#{repo}/branch_name_set", opt)
92
+ end
93
+
94
+ def get_repos_branches_by_owner_repo(owner, repo, opt={})
95
+ @http.get("/repos/#{owner}/#{repo}/branches", opt)
96
+ end
97
+
98
+ def get_repos_branches_branches_slice_by_owner_repo(owner, repo, opt = {})
99
+ @http.get("/repos/#{owner}/#{repo}/branches/branches_slice", opt)
100
+ end
101
+
102
+ def post_repos_branches_restore_by_owner_repo(owner, repo, opt = {})
103
+ @http.post("/repos/#{owner}/#{repo}/branches/restore", opt)
104
+ end
105
+
106
+ def get_repos_tag_name_set_by_owner_repo(owner, repo, opt = {})
107
+ @http.get("/repos/#{owner}/#{repo}/tag_name_set", opt)
108
+ end
109
+
110
+ def get_repos_tags_by_owner_repo(owner, repo, opt = {})
111
+ @http.get("/repos/#{owner}/#{repo}/tags", opt)
112
+ end
113
+
114
+ def get_repos_tags_by_owner_repo_tag(owner, repo, tag, opt = {})
115
+ @http.get("/repos/#{owner}/#{repo}/tags/#{tag}", opt)
116
+ end
117
+
118
+ def get_repos_branch_tag_count_by_owner_repo(owner, repo, opt = {})
119
+ @http.get("/repos/#{owner}/#{repo}/branch_tag_count", opt)
120
+ end
121
+
122
+ def get_repos_readme_by_owner_repo(owner, repo, opt = {})
123
+ @http.get("/repos/#{owner}/#{repo}/readme", opt)
124
+ end
125
+
126
+ def get_repos_readme_by_owner_repo_filepath(owner, repo, filepath, opt = {})
127
+ @http.get("/repos/#{owner}/#{repo}/readme/#{filepath}", opt)
128
+ end
129
+
130
+ def get_repos_commits_slice_by_owner_repo(owner, repo, opt = {})
131
+ @http.get("/repos/#{owner}/#{repo}/commits_slice", opt)
132
+ end
133
+
134
+ def get_repos_recent_commits_by_owner_repo(owner, repo, opt = {})
135
+ @http.get("/repos/#{owner}/#{repo}/recent_commits", opt)
136
+ end
137
+
138
+ def get_repos_contributors_by_owner_repo(owner, repo, opt = {})
139
+ @http.get("/repos/#{owner}/#{repo}/contributors", opt)
140
+ end
141
+
142
+ def get_repos_contributors_stat_by_owner_repo(owner, repo, opt = {})
143
+ @http.get("/repos/#{owner}/#{repo}/contributors/stat", opt)
144
+ end
145
+
146
+ def get_repos_code_stats_by_owner_repo(owner, repo, opt = {})
147
+ @http.get("/repos/#{owner}/#{repo}/code_stats", opt)
148
+ end
149
+
150
+ def get_repos_count_by_owner_repo(owner, repo, opt = {})
151
+ @http.get("/repos/#{owner}/#{repo}/count", opt)
152
+ end
153
+
154
+ def get_repos_file_commits_by_owner_repo_filepath(owner, repo, filepath, opt = {})
155
+ @http.get("/repos/#{owner}/#{repo}/file_commits/#{filepath}", opt)
156
+ end
157
+
158
+ def get_repos_blame_by_owner_repo(owner, repo, opt = {})
159
+ @http.get("/repos/#{owner}/#{repo}/blame", opt)
160
+ end
161
+
162
+ def get_repos_compare_by_owner_repo_baseref_headref(owner, repo, baseRef, headRef, opt = {})
163
+ @http.get("/repos/#{owner}/#{repo}/compare/#{baseRef}...#{headRef}", opt)
164
+ end
165
+
166
+ def get_repos_compare_files_by_owner_repo_baseref_headref(owner, repo, baseRef, headRef, opt={})
167
+ @http.get("/repos/#{owner}/#{repo}/compare/#{baseRef}...#{headRef}/files", opt)
168
+ end
169
+
170
+ def get_repos_compare_files_by_owner_repo_baseref_headref_filepath(owner, repo, baseRef, headRef, filepath, opt={})
171
+ @http.get("/repos/#{owner}/#{repo}/compare/#{baseRef}...#{headRef}/files/#{filepath}", opt)
172
+ end
173
+
174
+ def post_repos_transfer_by_owner_repo(owner, repo, opt = {})
175
+ @http.post("/repos/#{owner}/#{repo}/transfer", opt)
176
+ end
177
+
178
+ def get_repos_pulls_by_owner_repo_index(owner, repo, index, opt = {})
179
+ @http.get("/repos/#{owner}/#{repo}/pulls/#{index}", opt)
180
+ end
181
+
182
+ def get_repos_pulls_commits_by_owner_repo_index(owner, repo, index, opt = {})
183
+ @http.get("/repos/#{owner}/#{repo}/pulls/#{index}/commits", opt)
184
+ end
185
+
186
+ def get_repos_pulls_files_by_owner_repo_index(owner, repo, index, opt = {})
187
+ @http.get("/repos/#{owner}/#{repo}/pulls/#{index}/files", opt)
188
+ end
189
+
190
+ def get_repos_pulls_files_by_owner_repo_index_filepath(owner, repo, index, filepath, opt={})
191
+ @http.get("/repos/#{owner}/#{repo}/pulls/#{index}/files/#{filepath}", opt)
192
+ end
193
+
194
+ def post_repos_contents_batch_by_owner_repo(owner, repo, opt = {})
195
+ @http.post("/repos/#{owner}/#{repo}/contents/batch", opt)
196
+ end
197
+
198
+ def get_repos_pulls_versions_by_owner_repo_index(owner, repo, index, opt = {})
199
+ @http.get("/repos/#{owner}/#{repo}/pulls/#{index}/versions", opt)
200
+ end
201
+
202
+ def get_repos_pulls_versions_diff_by_owner_repo_index_id(owner, repo, index, versionID, opt = {})
203
+ @http.get("/repos/#{owner}/#{repo}/pulls/#{index}/versions/#{versionID}/diff", opt)
204
+ end
205
+
206
+ end # Repository
207
+ end # Hat
208
+ end # Api
209
+ end # Gitea
@@ -0,0 +1,13 @@
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
data/lib/gitea/api.rb CHANGED
@@ -11,3 +11,10 @@ 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.6.0"
4
+ VERSION = "1.6.1"
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.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - viletyy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-05 00:00:00.000000000 Z
11
+ date: 2024-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -49,6 +49,13 @@ 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
52
59
  - lib/gitea/api/http.rb
53
60
  - lib/gitea/api/issue.rb
54
61
  - lib/gitea/api/miscellaneous.rb