gitee-cli 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/exe/gitee +16 -0
- data/lib/gitee/cli/Rakefile +115 -0
- data/lib/gitee/cli.rb +97 -0
- data/lib/gitee/gitee4cli/api.rb +369 -0
- data/lib/gitee/gitee4cli.rb +21 -0
- data/lib/gitee-cli.rb +15 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2e07219311555afe8990344ec33c8e287528fc8f17f0b2f7f4ed88931fad67a1
|
4
|
+
data.tar.gz: 547475d996021e24377bdaedd094c6b8343f2ad32e3f33e7fc0050a93d9d1c86
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 901af3c3472ce87de5459e2994ae7801ca3518747fc4561ac507eb4e105d51813ccecdeb5802f2a3a5c1fe5ada3c999575a1b843f628c9e0c6d129d0a6d15648
|
7
|
+
data.tar.gz: fbebf9dd74cefbfddebb1f95e4519b4c5db843b98ab77eecedf2a94a84afd3e1ed20590c9102039c42be24ac522d5fe694b8cd50b9d76a9ddb6460a0b4a57d32
|
data/exe/gitee
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# ---------------------------------------------------------------
|
3
|
+
# File : gitee.rb
|
4
|
+
# Authors : Aoran Zeng <ccmywish@qq.com>
|
5
|
+
# Created on : <2023-04-28>
|
6
|
+
# Last modified : <2023-04-29>
|
7
|
+
#
|
8
|
+
# gitee:
|
9
|
+
#
|
10
|
+
# Do some Gitee stuff in the command line.
|
11
|
+
#
|
12
|
+
# ---------------------------------------------------------------
|
13
|
+
|
14
|
+
require 'gitee-cli'
|
15
|
+
|
16
|
+
Gitee::CLI.run
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# ---------------------------------------------------------------
|
2
|
+
# File : Rakefile
|
3
|
+
# Authors : Aoran Zeng <ccmywish@qq.com>
|
4
|
+
# Created on : <2023-04-29>
|
5
|
+
# Last modified : <2023-05-01>
|
6
|
+
#
|
7
|
+
# Rakefile:
|
8
|
+
#
|
9
|
+
# This file makes use of Rake and handle results of API calls
|
10
|
+
#
|
11
|
+
# ---------------------------------------------------------------
|
12
|
+
|
13
|
+
# desc "Print help" # Comment to hide this in help info
|
14
|
+
task :help do end # Just an empty task to be specified by default
|
15
|
+
|
16
|
+
namespace "repo" do
|
17
|
+
|
18
|
+
desc "Create a repository under your space"
|
19
|
+
task :create, [:repo] do |t, repo:|
|
20
|
+
res = Gitee::Gitee4CLI::API::Repositories.create(repo)
|
21
|
+
if res.successful?
|
22
|
+
cont = res.content
|
23
|
+
puts "Created successfully! Please visit: #{cont['html_url']}"
|
24
|
+
else
|
25
|
+
$stderr.puts "Error: " + res.why_failed
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
desc "Delete the '<user>/<repo>' repository"
|
31
|
+
task :delete, [:user, :repo] do |t, user:, repo:|
|
32
|
+
res = Gitee::Gitee4CLI::API::Repositories.delete(user,repo)
|
33
|
+
if res.successful?
|
34
|
+
puts "Deleted successfully!"
|
35
|
+
else
|
36
|
+
$stderr.puts "Error: " + res.why_failed
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
desc "Get all branches of a repository"
|
42
|
+
task :branches, [:user, :repo] do |t, args|
|
43
|
+
user, repo = args.user, args.repo
|
44
|
+
res = Gitee::Gitee4CLI::API::Repositories.all_branches(user, repo)
|
45
|
+
if res.successful?
|
46
|
+
res.content.each do |br|
|
47
|
+
puts br['name']
|
48
|
+
end
|
49
|
+
else
|
50
|
+
$stderr.puts "Error: " + res.why_failed
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
desc "View the repository's README"
|
56
|
+
task :view, [:user, :repo] do |t, user:, repo:|
|
57
|
+
res = Gitee::Gitee4CLI::API::Repositories.readme(user, repo)
|
58
|
+
if res.successful?
|
59
|
+
require 'base64'
|
60
|
+
require 'tty-markdown'
|
61
|
+
# res.content['content'] is UTF-8
|
62
|
+
cont = Base64.decode64(res.content['content']) # ASCII-8BIT
|
63
|
+
puts TTY::Markdown.parse(cont.force_encoding("UTF-8"))
|
64
|
+
puts puts
|
65
|
+
puts "View this repository on Gitee: " + Gitee::Gitee4CLI::URL + "#{user}/#{repo}"
|
66
|
+
else
|
67
|
+
$stderr.puts "Error: " + res.why_failed
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
desc "List repositories owned by user/organization"
|
73
|
+
task :list, [:user] do |t, args|
|
74
|
+
user = args.user
|
75
|
+
res = Gitee::Gitee4CLI::API::Repositories.list_for_user(user)
|
76
|
+
if res.successful?
|
77
|
+
# res.content is_a? Array => true
|
78
|
+
res.content.each_with_index do |repo, i|
|
79
|
+
print "#{i+1}. ".ljust(3), repo['full_name'].ljust(30)
|
80
|
+
if star = repo['stargazers_count']
|
81
|
+
print ' Star:', star
|
82
|
+
end
|
83
|
+
if fork = repo['forks_count']
|
84
|
+
print ' Fork:', fork
|
85
|
+
end
|
86
|
+
if lang = repo['language']
|
87
|
+
print ' Lang:', lang
|
88
|
+
end
|
89
|
+
puts
|
90
|
+
unless (desc = repo['description']).empty?
|
91
|
+
puts
|
92
|
+
puts " #{desc}"
|
93
|
+
end
|
94
|
+
puts puts
|
95
|
+
end
|
96
|
+
else
|
97
|
+
$stderr.puts "Error: " + res.why_failed
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
namespace "auth" do
|
105
|
+
|
106
|
+
desc "Apply for a Gitee access token (temporarily)"
|
107
|
+
task :apply do
|
108
|
+
puts 'Please visit:', ''
|
109
|
+
print ' ', Gitee::Gitee4CLI::API::BASE_URL + '/' + Gitee::Gitee4CLI::API::VERSION + '/swagger'
|
110
|
+
puts puts
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
task default: :help
|
data/lib/gitee/cli.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# ---------------------------------------------------------------
|
2
|
+
# File : cli.rb
|
3
|
+
# Authors : Aoran Zeng <ccmywish@qq.com>
|
4
|
+
# Created on : <2023-04-28>
|
5
|
+
# Last modified : <2023-05-01>
|
6
|
+
#
|
7
|
+
# cli:
|
8
|
+
#
|
9
|
+
# Comamnd line processing by first hand
|
10
|
+
#
|
11
|
+
# ---------------------------------------------------------------
|
12
|
+
|
13
|
+
require 'rake'
|
14
|
+
|
15
|
+
# Add method for Rake application
|
16
|
+
#
|
17
|
+
class Rake::Application
|
18
|
+
def run_gitee_cli(args)
|
19
|
+
opt = ['--rakefile', File.join(__FILE__, '..', 'cli', 'Rakefile') ]
|
20
|
+
standard_exception_handling do
|
21
|
+
argv = args.push *opt
|
22
|
+
init "gitee", argv
|
23
|
+
load_rakefile
|
24
|
+
top_level
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
module Gitee
|
31
|
+
|
32
|
+
module CLI
|
33
|
+
|
34
|
+
# gitee-cli version
|
35
|
+
VERSION = "0.1.0"
|
36
|
+
|
37
|
+
# Read token from local or environment variable
|
38
|
+
#
|
39
|
+
# @return [String] access token for Gitee API
|
40
|
+
#
|
41
|
+
def self.get_token
|
42
|
+
if tok = ENV['GITEE_TOKEN']
|
43
|
+
return tok
|
44
|
+
end
|
45
|
+
|
46
|
+
token_file = ENV['GITEE_TOKEN_FILE']
|
47
|
+
begin
|
48
|
+
return File.read(token_file).chomp
|
49
|
+
rescue Exception => e
|
50
|
+
$stderr.puts "gitee: Error to get Gitee token"
|
51
|
+
$stderr.puts e.message
|
52
|
+
exit
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Parse the commandline and run the program
|
57
|
+
#
|
58
|
+
# @noreturn
|
59
|
+
#
|
60
|
+
def self.run
|
61
|
+
argv = ARGV.dup
|
62
|
+
|
63
|
+
help_opts = ['-h', '-H', '--help', 'help']
|
64
|
+
version_opts = ['-v', '-V', '--version']
|
65
|
+
|
66
|
+
if argv.empty?
|
67
|
+
puts help_banner
|
68
|
+
argv << '-T'
|
69
|
+
elsif argv.intersect? help_opts
|
70
|
+
argv -= help_opts
|
71
|
+
puts help_banner
|
72
|
+
argv << '-T'
|
73
|
+
elsif argv.intersect? version_opts
|
74
|
+
argv -= version_opts
|
75
|
+
puts version_banner
|
76
|
+
end
|
77
|
+
|
78
|
+
Rake.application.run_gitee_cli(argv)
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
def self.version_banner
|
83
|
+
"gitee v#{VERSION}: Work with Gitee from the command line."
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
def self.help_banner
|
88
|
+
help = <<~BANNER
|
89
|
+
#{version_banner}
|
90
|
+
|
91
|
+
Usage:
|
92
|
+
|
93
|
+
BANNER
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,369 @@
|
|
1
|
+
# ---------------------------------------------------------------
|
2
|
+
# File : api.rb
|
3
|
+
# Authors : Aoran Zeng <ccmywish@qq.com>
|
4
|
+
# Created on : <2023-04-28>
|
5
|
+
# Last modified : <2023-05-01>
|
6
|
+
#
|
7
|
+
# api:
|
8
|
+
#
|
9
|
+
# APIs for Gitee
|
10
|
+
#
|
11
|
+
# ---------------------------------------------------------------
|
12
|
+
|
13
|
+
require 'http'
|
14
|
+
|
15
|
+
module Gitee::Gitee4CLI::API
|
16
|
+
|
17
|
+
BASE_URL = ::Gitee::Gitee4CLI::URL + '/api' # "https://gitee.com/api"
|
18
|
+
VERSION = "v5"
|
19
|
+
|
20
|
+
# Result type to return to CLI handler
|
21
|
+
#
|
22
|
+
class Result
|
23
|
+
|
24
|
+
# @return [String] The content of a successful API call
|
25
|
+
#
|
26
|
+
attr_reader :content
|
27
|
+
|
28
|
+
# @return [String] The reason of a failed API call
|
29
|
+
#
|
30
|
+
attr_reader :why_failed
|
31
|
+
|
32
|
+
# New a Result object with successful info and its content or failed reason
|
33
|
+
#
|
34
|
+
# @param [Boolean] successful If the API call succeeded
|
35
|
+
# @param [String] generic Content or failed reason
|
36
|
+
#
|
37
|
+
def initialize(successful, generic)
|
38
|
+
@status = successful
|
39
|
+
if successful
|
40
|
+
@content = generic
|
41
|
+
else
|
42
|
+
@why_failed = generic
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def successful?
|
47
|
+
@status
|
48
|
+
end
|
49
|
+
|
50
|
+
# A simple Result constructor
|
51
|
+
#
|
52
|
+
# @return [Result] A new Result object
|
53
|
+
#
|
54
|
+
# @note I just don't want to write 'new'
|
55
|
+
#
|
56
|
+
def self.[] arg1, arg2
|
57
|
+
new(arg1, arg2)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
# Descriptive HTTP status code rather than magic number
|
63
|
+
#
|
64
|
+
module HttpStatusCode
|
65
|
+
# Get successfully
|
66
|
+
Ok = 200
|
67
|
+
# Post successfully
|
68
|
+
Created = 201
|
69
|
+
# Delete successfully
|
70
|
+
NoContent = 204
|
71
|
+
end
|
72
|
+
|
73
|
+
# Private module to be included to provide common utilities for API modules, e.g. GitData
|
74
|
+
#
|
75
|
+
# @note Because it will be included, all functions shouldn't be declared as self.xxx
|
76
|
+
#
|
77
|
+
module CommonUtilities
|
78
|
+
|
79
|
+
# This is for API modules to directly call rather than spell the whole namespaces
|
80
|
+
Reuslt = Gitee::Gitee4CLI::API::Result
|
81
|
+
|
82
|
+
# Simple wrapper to get token
|
83
|
+
#
|
84
|
+
# @return [String] Token value
|
85
|
+
#
|
86
|
+
def get_token
|
87
|
+
Gitee::CLI.get_token
|
88
|
+
end
|
89
|
+
|
90
|
+
# Make the request url for an action
|
91
|
+
#
|
92
|
+
# Out two instance variables
|
93
|
+
# 1. `[Status] @status` status
|
94
|
+
# 2. `[String] @body` response body string
|
95
|
+
#
|
96
|
+
# @noparams
|
97
|
+
# @noreturn
|
98
|
+
#
|
99
|
+
# @note This is only called by module functions
|
100
|
+
#
|
101
|
+
def make_request
|
102
|
+
instance_exec {
|
103
|
+
url = [BASE_URL, VERSION, @path].join('/')
|
104
|
+
# e.g. HTTP.get("http://example.com/resource", :params => {:foo => "bar"})
|
105
|
+
res = HTTP.send @action.to_sym, url, :params => @params
|
106
|
+
|
107
|
+
# require 'irb'
|
108
|
+
# binding.irb
|
109
|
+
|
110
|
+
@status, @body = res.status, res.to_s
|
111
|
+
}
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
# Make it only accessible from inside
|
117
|
+
private_constant :CommonUtilities
|
118
|
+
|
119
|
+
# GitData APIs
|
120
|
+
#
|
121
|
+
# @see https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoGitBlobsSha
|
122
|
+
#
|
123
|
+
module GitData
|
124
|
+
|
125
|
+
class << self
|
126
|
+
include CommonUtilities
|
127
|
+
end
|
128
|
+
|
129
|
+
# Get file Blob
|
130
|
+
#
|
131
|
+
# @param owner 仓库所属空间地址(企业、组织或个人的地址)
|
132
|
+
# @param repo 仓库路径(path)
|
133
|
+
# @param sha 文件的 Blob SHA,可通过[获取仓库具体路径下的内容(tree)]API获取
|
134
|
+
# @param [Boolean] recursive 赋值为1递归获取目录
|
135
|
+
#
|
136
|
+
# @return [String] JSON响应体
|
137
|
+
#
|
138
|
+
# @HTTP [GET] https://gitee.com/api/v5/repos/{owner}/{repo}/git/blobs/{sha}
|
139
|
+
#
|
140
|
+
def self.blob(owner, repo, sha, recursive = true)
|
141
|
+
access_token = get_token
|
142
|
+
recursive = recursive ? 1 : 0
|
143
|
+
@params = {access_token:, recursive:}
|
144
|
+
@path = spirntf "repos/%s/%s/git/blobs/%s", owner, repo, sha
|
145
|
+
make_request
|
146
|
+
end
|
147
|
+
|
148
|
+
# Get directory Tree
|
149
|
+
#
|
150
|
+
# @param [String] owner 仓库所属空间地址(企业、组织或个人的地址)
|
151
|
+
# @param [String] repo 仓库路径(path)
|
152
|
+
# @param [String] sha 可以是分支名(如master)、Commit或者目录Tree的SHA值
|
153
|
+
# @param [Boolean] recursive 赋值为1递归获取目录
|
154
|
+
#
|
155
|
+
# @return [Result] JSON响应体
|
156
|
+
#
|
157
|
+
# @HTTP [Get] https://gitee.com/api/v5/repos/{owner}/{repo}/git/trees/{sha}
|
158
|
+
#
|
159
|
+
# @example [URL] https://gitee.com/api/v5/repos/ccmywish/gitee-cli/git/trees/main?access_token=abc
|
160
|
+
#
|
161
|
+
def self.tree(owner, repo, sha, recursive = true)
|
162
|
+
access_token = get_token
|
163
|
+
recursive = recursive ? 1 : 0
|
164
|
+
@params = {access_token:, recursive:}
|
165
|
+
@path = sprintf "repos/%s/%s/git/trees/%s", owner, repo, sha
|
166
|
+
make_request
|
167
|
+
end
|
168
|
+
|
169
|
+
# Get Gitee metrics for a repository
|
170
|
+
#
|
171
|
+
# @param [String] owner 仓库所属空间地址(企业、组织或个人的地址)
|
172
|
+
# @param [String] repo 仓库路径(path)
|
173
|
+
#
|
174
|
+
# @return [Result] JSON响应体
|
175
|
+
#
|
176
|
+
# @HTTP [GET] https://gitee.com/api/v5/repos/{owner}/{repo}/git/gitee_metrics
|
177
|
+
#
|
178
|
+
# @example [URL] https://gitee.com/api/v5/repos/ccmywish/gitee-cli/git/gitee_metrics?access_token=abc
|
179
|
+
#
|
180
|
+
def self.gitee_metrics(owner, repo)
|
181
|
+
access_token = get_token
|
182
|
+
@params = {access_token:}
|
183
|
+
@path = sprintf "repos/%s/%s/git/gitee_metrics", owner, repo
|
184
|
+
@action = 'get'
|
185
|
+
make_request
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
|
190
|
+
|
191
|
+
# Repositories APIs
|
192
|
+
#
|
193
|
+
# @see https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoBranches
|
194
|
+
#
|
195
|
+
module Repositories
|
196
|
+
|
197
|
+
class << self
|
198
|
+
include CommonUtilities
|
199
|
+
end
|
200
|
+
|
201
|
+
# Get all branches
|
202
|
+
#
|
203
|
+
# @param [String] owner 仓库所属空间地址(企业、组织或个人的地址)
|
204
|
+
# @param [String] repo 仓库路径(path)
|
205
|
+
#
|
206
|
+
# @return [Result] JSON响应体
|
207
|
+
#
|
208
|
+
# @HTTP [GET] https://gitee.com/api/v5/repos/{owner}/{repo}/branches
|
209
|
+
#
|
210
|
+
def self.all_branches(owner, repo)
|
211
|
+
access_token = get_token
|
212
|
+
@params = {access_token:}
|
213
|
+
@path = sprintf "repos/%s/%s/branches", owner, repo
|
214
|
+
@action = 'get'
|
215
|
+
make_request
|
216
|
+
if @status.code == 200
|
217
|
+
# 'json' is already required somewhere, maybe from 'http.rb'
|
218
|
+
Result[true, JSON.parse(@body)]
|
219
|
+
else
|
220
|
+
Result[false, @status.to_s]
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
# @TODO
|
225
|
+
# Create a new branch
|
226
|
+
#
|
227
|
+
# @param [String] owner 仓库所属空间地址(企业、组织或个人的地址)
|
228
|
+
# @param [String] repo 仓库路径(path)
|
229
|
+
#
|
230
|
+
# @return [Result] JSON响应体
|
231
|
+
#
|
232
|
+
# @HTTP [POST] https://gitee.com/api/v5/repos/{owner}/{repo}/branches
|
233
|
+
#
|
234
|
+
def self.new_branch(owner, repo)
|
235
|
+
access_token = get_token
|
236
|
+
@params = {access_token:}
|
237
|
+
@path = sprintf "repos/%s/%s/branches", owner, repo
|
238
|
+
make_request
|
239
|
+
# TODO: post the request
|
240
|
+
end
|
241
|
+
|
242
|
+
# @TODO
|
243
|
+
# Get a branch
|
244
|
+
#
|
245
|
+
# @param [String] owner 仓库所属空间地址(企业、组织或个人的地址)
|
246
|
+
# @param [String] repo 仓库路径(path)
|
247
|
+
# @param [String] branch 分支名称
|
248
|
+
#
|
249
|
+
# @return [Result] JSON响应体
|
250
|
+
#
|
251
|
+
# @HTTP [GET] https://gitee.com/api/v5/repos/{owner}/{repo}/branches/{branch}
|
252
|
+
#
|
253
|
+
def self.get_branch(owner, repo, branch)
|
254
|
+
access_token = get_token
|
255
|
+
@params = {access_token:}
|
256
|
+
@path = sprintf "repos/%s/%s/branches/%s", owner, repo, branch
|
257
|
+
@action = 'get'
|
258
|
+
make_request
|
259
|
+
end
|
260
|
+
|
261
|
+
# Delete a repo
|
262
|
+
#
|
263
|
+
# @param [String] owner 仓库所属空间地址(企业、组织或个人的地址)
|
264
|
+
# @param [String] repo 仓库路径(path)
|
265
|
+
#
|
266
|
+
# @return [Result] JSON响应体
|
267
|
+
#
|
268
|
+
# @HTTP [DELETE] https://gitee.com/api/v5/repos/{owner}/{repo}
|
269
|
+
#
|
270
|
+
def self.delete(owner, repo)
|
271
|
+
access_token = get_token
|
272
|
+
@params = {access_token:}
|
273
|
+
@path = sprintf "repos/%s/%s", owner, repo
|
274
|
+
@action = 'delete'
|
275
|
+
make_request
|
276
|
+
if @status.code == HttpStatusCode::NoContent
|
277
|
+
Result[true, nil]
|
278
|
+
else
|
279
|
+
Result[false, @status.to_s]
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
# @TODO
|
284
|
+
# Clear a repo
|
285
|
+
#
|
286
|
+
# @param [String] owner 仓库所属空间地址(企业、组织或个人的地址)
|
287
|
+
# @param [String] repo 仓库路径(path)
|
288
|
+
#
|
289
|
+
# @return [String] JSON响应体
|
290
|
+
#
|
291
|
+
# @HTTP [PUT] https://gitee.com/api/v5/repos/{owner}/{repo}/clear
|
292
|
+
#
|
293
|
+
def self.clear(owner, repo)
|
294
|
+
access_token = get_token
|
295
|
+
@params = {access_token:}
|
296
|
+
@path = sprintf "repos/%s/%s/clear", owner, repo
|
297
|
+
@action = 'put'
|
298
|
+
make_request
|
299
|
+
# TODO put
|
300
|
+
end
|
301
|
+
|
302
|
+
# Make a new repo
|
303
|
+
#
|
304
|
+
# @param [String] repo 仓库路径(path)
|
305
|
+
#
|
306
|
+
# @return [Result] JSON响应体
|
307
|
+
#
|
308
|
+
# @HTTP [POST] https://gitee.com/api/v5/user/repos
|
309
|
+
#
|
310
|
+
def self.create(repo)
|
311
|
+
access_token = get_token
|
312
|
+
@params = {access_token:, name: repo}
|
313
|
+
@path = "user/repos"
|
314
|
+
@action = 'post'
|
315
|
+
make_request
|
316
|
+
if @status.code == HttpStatusCode::Created
|
317
|
+
Result[true, JSON.parse(@body)]
|
318
|
+
else
|
319
|
+
Result[false, @status.to_s]
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
# Get the README from a repo
|
324
|
+
#
|
325
|
+
# @param [String] owner 仓库所属空间地址(企业、组织或个人的地址)
|
326
|
+
# @param [String] repo 仓库路径(path)
|
327
|
+
#
|
328
|
+
# @return [Result] JSON响应体
|
329
|
+
#
|
330
|
+
# @HTTP [GET] https://gitee.com/api/v5/repos/{owner}/{repo}/readme
|
331
|
+
#
|
332
|
+
def self.readme(owner, repo)
|
333
|
+
access_token = get_token
|
334
|
+
@params = {access_token:}
|
335
|
+
@path = sprintf "repos/%s/%s/readme", owner, repo
|
336
|
+
@action = 'get'
|
337
|
+
make_request
|
338
|
+
if @status.code == HttpStatusCode::Ok
|
339
|
+
Result[true, JSON.parse(@body)]
|
340
|
+
else
|
341
|
+
Result[false, @status.to_s]
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
#
|
346
|
+
# List repos from a user
|
347
|
+
#
|
348
|
+
# @param [<Type>] repo <description>
|
349
|
+
#
|
350
|
+
# @return [<Type>] <description>
|
351
|
+
#
|
352
|
+
# @HTTP [GET] https://gitee.com/api/v5/users/{username}/repos
|
353
|
+
#
|
354
|
+
def self.list_for_user(user)
|
355
|
+
access_token = get_token
|
356
|
+
@params = {access_token:, per_page: 50} # default per_page set to 50 (max 100)
|
357
|
+
@path = sprintf "users/%s/repos", user
|
358
|
+
@action = 'get'
|
359
|
+
make_request
|
360
|
+
if @status.code == HttpStatusCode::Ok
|
361
|
+
Result[true, JSON.parse(@body)]
|
362
|
+
else
|
363
|
+
Result[false, @status.to_s]
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
end
|
368
|
+
|
369
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# ---------------------------------------------------------------
|
2
|
+
# File : gitee4cli.rb
|
3
|
+
# Authors : Aoran Zeng <ccmywish@qq.com>
|
4
|
+
# Created on : <2023-04-29>
|
5
|
+
# Last modified : <2023-04-29>
|
6
|
+
#
|
7
|
+
# gitee4cli:
|
8
|
+
#
|
9
|
+
# Third party Gitee modules for Ruby
|
10
|
+
#
|
11
|
+
# ---------------------------------------------------------------
|
12
|
+
|
13
|
+
module Gitee
|
14
|
+
|
15
|
+
module Gitee4CLI
|
16
|
+
URL = "https://gitee.com"
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'gitee/gitee4cli/api'
|
data/lib/gitee-cli.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# ---------------------------------------------------------------
|
3
|
+
# File : gitee-cli.rb
|
4
|
+
# Authors : Aoran Zeng <ccmywish@qq.com>
|
5
|
+
# Created on : <2023-04-29>
|
6
|
+
# Last modified : <2023-04-29>
|
7
|
+
#
|
8
|
+
# gitee-cli:
|
9
|
+
#
|
10
|
+
# Require two lib files
|
11
|
+
#
|
12
|
+
# ---------------------------------------------------------------
|
13
|
+
|
14
|
+
require 'gitee/cli'
|
15
|
+
require 'gitee/gitee4cli'
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gitee-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aoran Zeng
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-05-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '13.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '13.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: http
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: tty-markdown
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.7'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.7'
|
55
|
+
description: 'Work with Gitee from the command line.
|
56
|
+
|
57
|
+
'
|
58
|
+
email: ccmywish@qq.com
|
59
|
+
executables:
|
60
|
+
- gitee
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- exe/gitee
|
65
|
+
- lib/gitee-cli.rb
|
66
|
+
- lib/gitee/cli.rb
|
67
|
+
- lib/gitee/cli/Rakefile
|
68
|
+
- lib/gitee/gitee4cli.rb
|
69
|
+
- lib/gitee/gitee4cli/api.rb
|
70
|
+
homepage: https://gitee.com/ccmywish
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata:
|
74
|
+
bug_tracker_uri: https://gitee.com/ccmywish
|
75
|
+
source_code_uri: https://gitee.com/ccmywish
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 3.1.0
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubygems_version: 3.4.8
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: 'gitee-cli: Gitee command line tools (3rd party client)'
|
95
|
+
test_files: []
|