git-rc 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +2 -0
- data/bin/git-release +5 -0
- data/lib/git-release.rb +311 -0
- data/lib/git-release/version.rb +3 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 380e7fc28942c068da609dbdd385c83b54916207
|
4
|
+
data.tar.gz: 8e601ef556b96817c39a03b832d50a1fa2fcc0a2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: faa724918603f247be8910995d802e7dd7df0d051c959ff99f7f8fc204115a33e415bcb1521c634636375090e1a9e5843ce4fc736eaf023ff8eb6ad535bc2fdc
|
7
|
+
data.tar.gz: 0501ddc8fdd2a0eecf304a5c47a0d2d5cf437aaf6a310b84d5fcf9704015a85aa6be9012044ecaaffffa6b9bad79ff211e35736babb3cec58071148fa8f6addf
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Armin Grodon
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
data/bin/git-release
ADDED
data/lib/git-release.rb
ADDED
@@ -0,0 +1,311 @@
|
|
1
|
+
require 'octokit'
|
2
|
+
require 'highline'
|
3
|
+
require 'git-release/version'
|
4
|
+
|
5
|
+
module GitRelease
|
6
|
+
$cli = HighLine.new
|
7
|
+
$token_file = "~/.git-release-token"
|
8
|
+
$status = {
|
9
|
+
"r" => "release",
|
10
|
+
"p" => "prerelease",
|
11
|
+
"d" => "draft",
|
12
|
+
"release" => "release",
|
13
|
+
"prerelease" => "prerelease",
|
14
|
+
"draft" => "draft"
|
15
|
+
}
|
16
|
+
|
17
|
+
def self.run(args)
|
18
|
+
args << 'help' if args.empty?
|
19
|
+
command = args.shift
|
20
|
+
|
21
|
+
case command
|
22
|
+
when 'help'
|
23
|
+
usage
|
24
|
+
when 'version'
|
25
|
+
puts "git-release version #{GitRelease::VERSION}"
|
26
|
+
when 'login'
|
27
|
+
login = do_login
|
28
|
+
puts 'successfully logged in'
|
29
|
+
when 'list'
|
30
|
+
repo = get_repo
|
31
|
+
print_releases(repo)
|
32
|
+
when 'set'
|
33
|
+
repo = get_repo
|
34
|
+
tag = args.shift
|
35
|
+
status = $status[args.shift] || unknown_status
|
36
|
+
set_release(repo, tag, status)
|
37
|
+
when 'doc'
|
38
|
+
repo = get_repo
|
39
|
+
task = args.shift
|
40
|
+
tag = args.shift
|
41
|
+
case task
|
42
|
+
when 'clear'
|
43
|
+
clear_doc(repo, tag)
|
44
|
+
when 'add'
|
45
|
+
add_doc(repo, tag, args)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.usage
|
51
|
+
puts "usage: git-release <command> [<args>]"
|
52
|
+
puts " help print this message"
|
53
|
+
puts " version print the current version"
|
54
|
+
puts " login create or verify api token"
|
55
|
+
puts " list list all releases"
|
56
|
+
puts " set <tag> <state> change the status of a release"
|
57
|
+
puts " tag tag of the release to change"
|
58
|
+
puts " state new state. either r[elease], p[rerelease] or d[raft]"
|
59
|
+
puts " doc clear <tag> clear the release notes"
|
60
|
+
puts " doc add <tag> <text> add one or more lines to the release notes"
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.unknown_status
|
64
|
+
puts "unknown status"
|
65
|
+
puts "use one of: r[elease], p[rerelease] or d[raft]"
|
66
|
+
exit 1
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.get_repo
|
70
|
+
repo = `git remote get-url origin`.
|
71
|
+
sub("\n", "").
|
72
|
+
gsub(/.*github.com./, "")
|
73
|
+
if $?.exitstatus == 0
|
74
|
+
repo
|
75
|
+
else
|
76
|
+
puts "not a git repository"
|
77
|
+
exit 1
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.get_api_client
|
82
|
+
Octokit::Client.new(:access_token => load_token)
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.get_user_client
|
86
|
+
user = ask_username
|
87
|
+
pass = ask_password
|
88
|
+
client = Octokit::Client.new(:login => user, :password => pass)
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.do_login
|
92
|
+
if File.file?(File.expand_path($token_file))
|
93
|
+
begin
|
94
|
+
test = get_api_client
|
95
|
+
test.repos
|
96
|
+
rescue
|
97
|
+
client = get_user_client
|
98
|
+
token = get_token(client)
|
99
|
+
store_token(token)
|
100
|
+
end
|
101
|
+
else
|
102
|
+
client = get_user_client
|
103
|
+
token = get_token(client)
|
104
|
+
store_token(token)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.load_token
|
109
|
+
File.open(File.expand_path($token_file), &:readline)
|
110
|
+
end
|
111
|
+
|
112
|
+
def self.store_token(token)
|
113
|
+
f = File.new(File.expand_path($token_file), 'w', 0600)
|
114
|
+
f.write(token)
|
115
|
+
f.close
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.ask_username
|
119
|
+
user = $cli.ask("GitHub User: ", String)
|
120
|
+
if user.empty?
|
121
|
+
exit 1
|
122
|
+
end
|
123
|
+
user
|
124
|
+
end
|
125
|
+
|
126
|
+
def self.ask_password
|
127
|
+
pass = $cli.ask("GitHub Password: ", String) { |q| q.echo = "*" }
|
128
|
+
if pass.empty?
|
129
|
+
exit 1
|
130
|
+
end
|
131
|
+
pass
|
132
|
+
end
|
133
|
+
|
134
|
+
def self.ask_otp
|
135
|
+
otp = $cli.ask("GitHub 2FA: ", String)
|
136
|
+
if otp.empty?
|
137
|
+
exit 1
|
138
|
+
end
|
139
|
+
otp
|
140
|
+
end
|
141
|
+
|
142
|
+
def self.ask_note(note)
|
143
|
+
note = $cli.ask("OAuth token note: ", String) { |q| q.default = note }
|
144
|
+
if note.empty?
|
145
|
+
exit 1
|
146
|
+
end
|
147
|
+
note
|
148
|
+
end
|
149
|
+
|
150
|
+
def self.delete_token(client, note)
|
151
|
+
otp = ""
|
152
|
+
id = ""
|
153
|
+
done = false
|
154
|
+
while !done do
|
155
|
+
begin
|
156
|
+
if id.empty?
|
157
|
+
if otp.empty?
|
158
|
+
auths = client.authorizations
|
159
|
+
else
|
160
|
+
auths = client.authorizations(
|
161
|
+
:headers => { "X-GitHub-OTP" => otp})
|
162
|
+
end
|
163
|
+
id = auths.find { |a| a.note.include?(note) }.id
|
164
|
+
else
|
165
|
+
if otp.empty?
|
166
|
+
client.delete_authorization(id)
|
167
|
+
else
|
168
|
+
client.delete_authorization(
|
169
|
+
id,
|
170
|
+
:headers => { "X-GitHub-OTP" => otp})
|
171
|
+
end
|
172
|
+
done = true
|
173
|
+
end
|
174
|
+
rescue Octokit::OneTimePasswordRequired => e
|
175
|
+
otp = ask_otp
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def self.choose_delete(client, note)
|
181
|
+
$cli.choose do |menu|
|
182
|
+
menu.prompt = "Token '#{note}' already exists: "
|
183
|
+
menu.choice("regenerate token (will delete old one)") do
|
184
|
+
delete_token(client, note)
|
185
|
+
note
|
186
|
+
end
|
187
|
+
menu.choice("generate token with new name") do
|
188
|
+
ask_note(note)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
def self.get_token(client)
|
194
|
+
token = ""
|
195
|
+
note = 'Git Release CLI',
|
196
|
+
otp = ""
|
197
|
+
while token.empty? do
|
198
|
+
begin
|
199
|
+
if otp.empty?
|
200
|
+
token = client.create_authorization(
|
201
|
+
:scopes => ['repo'],
|
202
|
+
:note => note)
|
203
|
+
else
|
204
|
+
token = client.create_authorization(
|
205
|
+
:scopes => ['repo'],
|
206
|
+
:note => note,
|
207
|
+
:headers => { "X-GitHub-OTP" => otp})
|
208
|
+
end
|
209
|
+
rescue Octokit::OneTimePasswordRequired => e
|
210
|
+
otp = ask_otp
|
211
|
+
rescue Octokit::UnprocessableEntity => e
|
212
|
+
if e.message.include?("already_exists")
|
213
|
+
note = choose_delete(client, note)
|
214
|
+
else
|
215
|
+
puts e
|
216
|
+
exit 1
|
217
|
+
end
|
218
|
+
rescue => e
|
219
|
+
puts e
|
220
|
+
exit 1
|
221
|
+
end
|
222
|
+
end
|
223
|
+
token.token
|
224
|
+
end
|
225
|
+
|
226
|
+
def self.print_releases(repo)
|
227
|
+
client = get_api_client
|
228
|
+
releases = client.releases(repo)
|
229
|
+
sorted = releases.sort { |x,y| y.tag_name <=> x.tag_name }
|
230
|
+
first_testing = first_production = true
|
231
|
+
sorted.each do |r|
|
232
|
+
if r.draft
|
233
|
+
$cli.say("<%= color('#{r.tag_name} (draft)', :red) %>")
|
234
|
+
elsif r.prerelease
|
235
|
+
$cli.say("<%= color('#{r.tag_name} (prerelease)', :yellow) %>")
|
236
|
+
if first_testing
|
237
|
+
$cli.say("<%= color('current testing', :blue) %>")
|
238
|
+
first_testing = false
|
239
|
+
end
|
240
|
+
else
|
241
|
+
$cli.say("<%= color('#{r.tag_name} (release)', :green) %>")
|
242
|
+
if first_testing and first_production
|
243
|
+
$cli.say("<%= color('current testing and production', :blue) %>")
|
244
|
+
first_testing = first_production = false
|
245
|
+
elsif first_production
|
246
|
+
$cli.say("<%= color('current production', :blue) %>")
|
247
|
+
first_production = false
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
$cli.say("<%= color('released:', :blue) %> #{r.published_at}")
|
252
|
+
$cli.say("<%= color('notes:', :blue) %>")
|
253
|
+
r.body.each_line { |l| $cli.say(" #{l}") }
|
254
|
+
puts
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
def self.get_tag(releases, tag)
|
259
|
+
release = releases.find { |r| r.tag_name == tag }
|
260
|
+
if release.empty?
|
261
|
+
puts "unknown tag #{tag}"
|
262
|
+
exit 1
|
263
|
+
end
|
264
|
+
release
|
265
|
+
end
|
266
|
+
|
267
|
+
def self.set_release(repo, tag, status)
|
268
|
+
client = get_api_client
|
269
|
+
releases = client.releases(repo)
|
270
|
+
release = get_tag(releases, tag)
|
271
|
+
case status
|
272
|
+
when "release"
|
273
|
+
prerelease = false
|
274
|
+
draft = false
|
275
|
+
when "prerelease"
|
276
|
+
prerelease = true
|
277
|
+
draft = false
|
278
|
+
when "draft"
|
279
|
+
prerelease = true
|
280
|
+
draft = true
|
281
|
+
end
|
282
|
+
|
283
|
+
client.update_release(
|
284
|
+
release.url,
|
285
|
+
:prerelease => prerelease,
|
286
|
+
:draft => draft)
|
287
|
+
end
|
288
|
+
|
289
|
+
def self.clear_doc(repo, tag)
|
290
|
+
client = get_api_client
|
291
|
+
releases = client.releases(repo)
|
292
|
+
release = get_tag(releases, tag)
|
293
|
+
client.update_release(release.url, :body => "")
|
294
|
+
end
|
295
|
+
|
296
|
+
def self.add_doc(repo, tag, text)
|
297
|
+
client = get_api_client
|
298
|
+
releases = client.releases(repo)
|
299
|
+
release = get_tag(releases, tag)
|
300
|
+
|
301
|
+
if text.kind_of?(Array)
|
302
|
+
text = text.join("\n")
|
303
|
+
end
|
304
|
+
if release.body.empty?
|
305
|
+
body = text
|
306
|
+
else
|
307
|
+
body = "#{release.body}\n#{text}"
|
308
|
+
end
|
309
|
+
client.update_release(release.url, :body => body)
|
310
|
+
end
|
311
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git-rc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Armin Grodon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: octokit
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: highline
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: |2
|
56
|
+
provides the command 'git release' to list releases,
|
57
|
+
update release status (draft, prerelease) and edit change log, nothing more.
|
58
|
+
email:
|
59
|
+
- me@armingrodon.de
|
60
|
+
executables:
|
61
|
+
- git-release
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files:
|
64
|
+
- README.md
|
65
|
+
files:
|
66
|
+
- LICENSE
|
67
|
+
- README.md
|
68
|
+
- bin/git-release
|
69
|
+
- lib/git-release.rb
|
70
|
+
- lib/git-release/version.rb
|
71
|
+
homepage: https://github.com/x4121/git-release
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '1.9'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements:
|
90
|
+
- git
|
91
|
+
- git
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.5.1
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: A command line tool to edit existing GitHub releases
|
97
|
+
test_files: []
|