ballantine 0.1.4.pre.beta1 → 0.1.4.pre.beta2
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 +4 -4
- data/lib/ballantine/author.rb +18 -17
- data/lib/ballantine/cli.rb +31 -131
- data/lib/ballantine/commit.rb +34 -0
- data/lib/ballantine/repository.rb +207 -0
- data/lib/ballantine/version.rb +1 -1
- data/lib/ballantine.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 205e73804edf1a3ea9c16ddabb4dc3f5d1cc916300ff6f59576112153d8fadaa
|
4
|
+
data.tar.gz: 3a742736e8db01a38761b0a395a94e7e16083edd35ff8cf460c77e4db0f797d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41654e7d79f79ca6a0c5a556e567ec40f64f343797b92c748c6930d012c6cf49c9674878aa81ad9e7d50f42f8740208a0003f7bf9cde5e11bc674f0f8e8d0b5a
|
7
|
+
data.tar.gz: 214c98d8b880faf7b68aeefa65a5670c688186d2b3e2f3098e2c3ed42cd80f221282ce441de10b6ea12e2569ec977f4062954100206fedcf0f5eae509ca70a26
|
data/lib/ballantine/author.rb
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
|
3
3
|
module Ballantine
|
4
4
|
class Author
|
5
|
-
|
5
|
+
attr_reader :name, :commits_hash
|
6
6
|
|
7
7
|
class << self
|
8
8
|
# @param [String] name
|
9
9
|
# @return [Author] author
|
10
|
-
def find_or_create_by(name)
|
10
|
+
def find_or_create_by(name:)
|
11
11
|
@_collections = {} unless defined?(@_collections)
|
12
12
|
return @_collections[name] unless @_collections[name].nil?
|
13
13
|
|
14
|
-
@_collections[name] = new(name)
|
14
|
+
@_collections[name] = new(name:)
|
15
15
|
end
|
16
16
|
|
17
17
|
# @return [Array<Author>] authors
|
@@ -23,29 +23,30 @@ module Ballantine
|
|
23
23
|
end
|
24
24
|
|
25
25
|
# @param [String] name
|
26
|
-
def initialize(name)
|
26
|
+
def initialize(name:)
|
27
27
|
@name = name
|
28
|
-
@
|
28
|
+
@commits_hash = {}
|
29
29
|
end
|
30
30
|
|
31
|
-
# @return [
|
31
|
+
# @return [Boolean]
|
32
32
|
def print_commits
|
33
33
|
puts "\n" + "@#{name}".green
|
34
|
-
|
35
|
-
count, word = retrieve_count_and_word(
|
36
|
-
puts " > #{
|
37
|
-
puts
|
34
|
+
commits_hash.each do |repo_name, commits|
|
35
|
+
count, word = retrieve_count_and_word(commits)
|
36
|
+
puts " > #{repo_name.blue}: #{count} new #{word}\n"
|
37
|
+
puts commits.map(&:message)
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
|
+
true
|
40
41
|
end
|
41
42
|
|
42
43
|
# returns an array to use slack attachments field
|
43
44
|
# reference: https://api.slack.com/messaging/composing/layouts#building-attachments
|
44
45
|
# @return [Hash] result
|
45
46
|
def serialize_commits
|
46
|
-
message =
|
47
|
-
count, word = retrieve_count_and_word(
|
48
|
-
"*#{
|
47
|
+
message = commits_hash.map do |repo_name, commits|
|
48
|
+
count, word = retrieve_count_and_word(commits)
|
49
|
+
"*#{repo_name}*: #{count} new #{word}\n#{commits.map(&:message).join("\n")}"
|
49
50
|
end.join("\n")
|
50
51
|
|
51
52
|
{
|
@@ -56,10 +57,10 @@ module Ballantine
|
|
56
57
|
|
57
58
|
private
|
58
59
|
|
59
|
-
# @param [Array<
|
60
|
+
# @param [Array<Commit>] commits
|
60
61
|
# @param [Array(Integer, String)] count, word
|
61
|
-
def retrieve_count_and_word(
|
62
|
-
count =
|
62
|
+
def retrieve_count_and_word(commits)
|
63
|
+
count = commits.size
|
63
64
|
word = count == 1 ? "commit" : "commits"
|
64
65
|
[count, word]
|
65
66
|
end
|
data/lib/ballantine/cli.rb
CHANGED
@@ -2,25 +2,10 @@
|
|
2
2
|
|
3
3
|
module Ballantine
|
4
4
|
class CLI < Thor
|
5
|
-
# reference: https://github.com/desktop/desktop/blob/a7bca44088b105a04714dc4628f4af50f6f179c3/app/src/lib/remote-parsing.ts#L27-L44
|
6
|
-
GITHUB_REGEXES = [
|
7
|
-
'^https?://(.+)/(.+)/(.+)\.git/?$', # protocol: https -> https://github.com/oohyun15/ballantine.git | https://github.com/oohyun15/ballantine.git/
|
8
|
-
'^https?://(.+)/(.+)/(.+)/?$', # protocol: https -> https://github.com/oohyun15/ballantine | https://github.com/oohyun15/ballantine/
|
9
|
-
'^git@(.+):(.+)/(.+)\.git$', # protocol: ssh -> git@github.com:oohyun15/ballantine.git
|
10
|
-
'^git@(.+):(.+)/(.+)/?$', # protocol: ssh -> git@github.com:oohyun15/ballantine | git@github.com:oohyun15/ballantine/
|
11
|
-
'^git:(.+)/(.+)/(.+)\.git$', # protocol: ssh -> git:github.com/oohyun15/ballantine.git
|
12
|
-
'^git:(.+)/(.+)/(.+)/?$', # protocol: ssh -> git:github.com/oohyun15/ballantine | git:github.com/oohyun15/ballantine/
|
13
|
-
'^ssh://git@(.+)/(.+)/(.+)\.git$', # protocol: ssh -> ssh://git@github.com/oohyun15/ballantine.git
|
14
|
-
].freeze
|
15
|
-
|
16
|
-
FILE_GITMODULES = ".gitmodules"
|
17
|
-
|
18
5
|
TYPE_TERMINAL = "terminal"
|
19
6
|
TYPE_SLACK = "slack"
|
20
7
|
|
21
|
-
|
22
|
-
|
23
|
-
attr_reader :app_name, :main_path, :sub_path, :send_type
|
8
|
+
attr_reader :send_type, :repo
|
24
9
|
|
25
10
|
class << self
|
26
11
|
def exit_on_failure?; exit(1) end
|
@@ -63,30 +48,13 @@ module Ballantine
|
|
63
48
|
system("git pull -f &> /dev/null")
|
64
49
|
|
65
50
|
# init instance variables
|
66
|
-
init_variables(**options)
|
67
|
-
|
68
|
-
# find github url, branch
|
69
|
-
url = github_url(%x(git config --get remote.origin.url).chomp)
|
70
|
-
current_revision = %x(git rev-parse --abbrev-ref HEAD).chomp
|
71
|
-
|
72
|
-
# get commit hash
|
73
|
-
from, sub_from = commit_hash(target)
|
74
|
-
to, sub_to = commit_hash(source)
|
75
|
-
system("git checkout #{current_revision} -f &> /dev/null")
|
51
|
+
init_variables(target, source, **options)
|
76
52
|
|
77
53
|
# check commits
|
78
|
-
check_commits(
|
79
|
-
sub_path.each_with_index do |path, idx|
|
80
|
-
next if sub_from[idx] == sub_to[idx]
|
81
|
-
|
82
|
-
Dir.chdir(path)
|
83
|
-
sub_url = github_url(%x(git config --get remote.origin.url).chomp)
|
84
|
-
check_commits(sub_from[idx], sub_to[idx], sub_url)
|
85
|
-
Dir.chdir(main_path)
|
86
|
-
end
|
54
|
+
check_commits(**options)
|
87
55
|
|
88
56
|
# send commits
|
89
|
-
send_commits(target, source,
|
57
|
+
send_commits(target, source, **options)
|
90
58
|
|
91
59
|
exit(0)
|
92
60
|
end
|
@@ -126,117 +94,47 @@ module Ballantine
|
|
126
94
|
nil
|
127
95
|
end
|
128
96
|
|
97
|
+
# @param [String] target
|
98
|
+
# @param [String] source
|
129
99
|
# @param [Hash] options
|
130
100
|
# @return [Boolean]
|
131
|
-
def init_variables(**options)
|
101
|
+
def init_variables(target, source, **options)
|
132
102
|
@send_type = options[TYPE_SLACK] ? TYPE_SLACK : TYPE_TERMINAL
|
133
|
-
|
134
|
-
@
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
else
|
142
|
-
[]
|
143
|
-
end
|
103
|
+
Repository.send_type = @send_type
|
104
|
+
@repo = Repository.find_or_create_by(
|
105
|
+
path: Dir.pwd,
|
106
|
+
remote_url: %x(git config --get remote.origin.url).chomp,
|
107
|
+
)
|
108
|
+
|
109
|
+
# init repo
|
110
|
+
repo.init_variables(target, source)
|
144
111
|
true
|
145
112
|
end
|
146
113
|
|
147
|
-
# @param [
|
148
|
-
# @return [
|
149
|
-
def
|
150
|
-
|
151
|
-
return name unless list.grep(name).any?
|
152
|
-
|
153
|
-
system("git fetch origin tag #{name} -f &> /dev/null")
|
154
|
-
%x(git rev-list -n 1 #{name}).chomp[0...7]
|
155
|
-
end
|
156
|
-
|
157
|
-
# @param [String] from
|
158
|
-
# @param [String] to
|
159
|
-
# @param [String] url
|
160
|
-
# @return [NilClass] nil
|
161
|
-
def check_commits(from, to, url)
|
162
|
-
repo = File.basename(%x(git config --get remote.origin.url).chomp, ".git")
|
163
|
-
names = %x(git --no-pager log --pretty=format:"%an" #{from}..#{to}).split("\n").uniq.sort
|
164
|
-
authors = names.map { |name| Author.find_or_create_by(name) }
|
165
|
-
authors.each do |author|
|
166
|
-
format = commit_format(url, ljust: DEFAULT_LJUST - 10)
|
167
|
-
commits =
|
168
|
-
%x(git --no-pager log --reverse --no-merges --author="#{author.name}" --format="#{format}" --abbrev=7 #{from}..#{to})
|
169
|
-
.gsub('"', '\"')
|
170
|
-
.gsub(/[\u0080-\u00ff]/, "")
|
171
|
-
next if commits.empty?
|
172
|
-
|
173
|
-
author.commits[repo] = commits.split("\n")
|
174
|
-
end
|
175
|
-
nil
|
176
|
-
end
|
177
|
-
|
178
|
-
# @param [String] url
|
179
|
-
# @return [String] github_url
|
180
|
-
def github_url(url)
|
181
|
-
owner, repository = GITHUB_REGEXES.each do |regex|
|
182
|
-
if (str = url.match(regex))
|
183
|
-
break [str[2], str[3]]
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
"https://github.com/#{owner}/#{repository}"
|
188
|
-
end
|
189
|
-
|
190
|
-
# @param [String] hash
|
191
|
-
# @return [Array(String, Array<String>)] main, sub's hash
|
192
|
-
def commit_hash(hash)
|
193
|
-
# check argument is tag
|
194
|
-
hash = check_tag(hash)
|
195
|
-
|
196
|
-
system("git checkout #{hash} -f &> /dev/null")
|
197
|
-
system("git pull &> /dev/null")
|
198
|
-
main_hash = %x(git --no-pager log -1 --format='%h').chomp
|
199
|
-
sub_hash =
|
200
|
-
if sub_path.any?
|
201
|
-
%x(git ls-tree HEAD #{@sub_path.join(" ")}).split("\n").map { |line| line.split(" ")[2] }
|
202
|
-
else
|
203
|
-
[]
|
204
|
-
end
|
205
|
-
|
206
|
-
[main_hash, sub_hash]
|
207
|
-
end
|
114
|
+
# @param [Hash] options
|
115
|
+
# @return [Boolean]
|
116
|
+
def check_commits(**options)
|
117
|
+
repo.check_commits
|
208
118
|
|
209
|
-
|
210
|
-
# @param [String] format
|
211
|
-
# @param [Integer] ljust
|
212
|
-
def commit_format(url, ljust: DEFAULT_LJUST)
|
213
|
-
case send_type
|
214
|
-
when TYPE_TERMINAL
|
215
|
-
" - " + "%h".yellow + " %<(#{ljust})%s " + "#{url}/commit/%H".gray
|
216
|
-
when TYPE_SLACK
|
217
|
-
"\\\`<#{url}/commit/%H|%h>\\\` %s - %an"
|
218
|
-
else raise AssertionFailed, "Unknown send type: #{send_type}"
|
219
|
-
end
|
119
|
+
true
|
220
120
|
end
|
221
121
|
|
222
122
|
# @param [String] target
|
223
123
|
# @param [String] source
|
224
|
-
# @param [
|
225
|
-
# @
|
226
|
-
|
227
|
-
# @return [NilClass] nil
|
228
|
-
def send_commits(target, source, from, to, url)
|
124
|
+
# @param [Hash] options
|
125
|
+
# @return [Boolean]
|
126
|
+
def send_commits(target, source, **options)
|
229
127
|
authors = Author.all
|
230
128
|
if authors.empty?
|
231
129
|
raise ArgumentError, "ERROR: There is no commits between \"#{target}\" and \"#{source}\""
|
232
130
|
end
|
233
131
|
|
234
132
|
number = authors.size
|
235
|
-
last_commit =
|
133
|
+
last_commit = repo.print_last_commit
|
236
134
|
|
237
135
|
case send_type
|
238
136
|
when TYPE_TERMINAL
|
239
|
-
puts "Check commits before #{
|
137
|
+
puts "Check commits before #{repo.name.red} deployment. (#{target.cyan} <- #{source.cyan})".ljust(Repository::DEFAULT_LJUST + 44) + " #{repo.url}/compare/#{repo.from.hash}...#{repo.to.hash}".gray
|
240
138
|
puts "Author".yellow + ": #{number}"
|
241
139
|
puts "Last commit".blue + ": #{last_commit}"
|
242
140
|
authors.map(&:print_commits)
|
@@ -252,17 +150,19 @@ module Ballantine
|
|
252
150
|
request = Net::HTTP::Post.new(uri)
|
253
151
|
request.content_type = "application/json"
|
254
152
|
request.body = JSON.dump({
|
255
|
-
"text" => ":white_check_mark: *#{
|
153
|
+
"text" => ":white_check_mark: *#{repo.name}* deployment request by <@#{actor}>" \
|
154
|
+
" (\`<#{repo.url}/tree/#{repo.from.hash}|#{target}>\` <- \`<#{repo.url}/tree/#{repo.to.hash}|#{source}>\` <#{repo.url}/compare/#{repo.from.hash}...#{repo.to.hash}|compare>)" \
|
155
|
+
"\n:technologist: Author: #{number}\nLast commit: #{last_commit}",
|
256
156
|
"attachments" => messages,
|
257
157
|
})
|
258
158
|
req_options = { use_ssl: uri.scheme == "https" }
|
259
|
-
response = Net::HTTP.start(uri.hostname, uri.port, req_options)
|
260
|
-
http.request(request)
|
261
|
-
end
|
159
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) { |http| http.request(request) }
|
262
160
|
puts response.message
|
263
161
|
else
|
264
162
|
raise AssertionFailed, "Unknown send type: #{send_type}"
|
265
163
|
end
|
164
|
+
|
165
|
+
true
|
266
166
|
end
|
267
167
|
end
|
268
168
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ballantine
|
4
|
+
class Commit
|
5
|
+
attr_reader :hash, :message # attributes
|
6
|
+
attr_reader :repo, :author # associations
|
7
|
+
|
8
|
+
class << self
|
9
|
+
# @param [String] hash
|
10
|
+
# @param [Repository] repo
|
11
|
+
# @param [String] message
|
12
|
+
# @param [Author, NilClass] message
|
13
|
+
# @return [Commit]
|
14
|
+
def find_or_create_by(hash:, repo:, message: nil, author: nil)
|
15
|
+
@_collections = {} unless defined?(@_collections)
|
16
|
+
index = "#{hash}-#{repo.name}"
|
17
|
+
return @_collections[index] unless @_collections[index].nil?
|
18
|
+
|
19
|
+
@_collections[index] = new(hash:, repo:, message:, author:)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# @param [String] hash
|
24
|
+
# @param [Repository] repo
|
25
|
+
# @param [String] message
|
26
|
+
# @param [Author] author
|
27
|
+
def initialize(hash:, repo:, message:, author:)
|
28
|
+
@hash = hash
|
29
|
+
@repo = repo
|
30
|
+
@message = message
|
31
|
+
@author = author
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,207 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ballantine
|
4
|
+
class Repository
|
5
|
+
# reference: https://github.com/desktop/desktop/blob/a7bca44088b105a04714dc4628f4af50f6f179c3/app/src/lib/remote-parsing.ts#L27-L44
|
6
|
+
GITHUB_REGEXES = [
|
7
|
+
'^https?://(.+)/(.+)/(.+)\.git/?$', # protocol: https -> https://github.com/oohyun15/ballantine.git | https://github.com/oohyun15/ballantine.git/
|
8
|
+
'^https?://(.+)/(.+)/(.+)/?$', # protocol: https -> https://github.com/oohyun15/ballantine | https://github.com/oohyun15/ballantine/
|
9
|
+
'^git@(.+):(.+)/(.+)\.git$', # protocol: ssh -> git@github.com:oohyun15/ballantine.git
|
10
|
+
'^git@(.+):(.+)/(.+)/?$', # protocol: ssh -> git@github.com:oohyun15/ballantine | git@github.com:oohyun15/ballantine/
|
11
|
+
'^git:(.+)/(.+)/(.+)\.git$', # protocol: ssh -> git:github.com/oohyun15/ballantine.git
|
12
|
+
'^git:(.+)/(.+)/(.+)/?$', # protocol: ssh -> git:github.com/oohyun15/ballantine | git:github.com/oohyun15/ballantine/
|
13
|
+
'^ssh://git@(.+)/(.+)/(.+)\.git$', # protocol: ssh -> ssh://git@github.com/oohyun15/ballantine.git
|
14
|
+
].freeze
|
15
|
+
FILE_GITMODULES = ".gitmodules"
|
16
|
+
DEFAULT_LJUST = 70
|
17
|
+
PARSER_TOKEN = "!#!#"
|
18
|
+
|
19
|
+
attr_reader :name, :path, :owner, :url, :from, :to, :format # attributes
|
20
|
+
attr_reader :main_repo, :sub_repos, :commits # associations
|
21
|
+
|
22
|
+
class << self
|
23
|
+
# @param [String] path
|
24
|
+
# @param [String] remote_url
|
25
|
+
# @return [Repository]
|
26
|
+
def find_or_create_by(path:, remote_url: nil)
|
27
|
+
@_collections = {} unless defined?(@_collections)
|
28
|
+
return @_collections[path] unless @_collections[path].nil?
|
29
|
+
|
30
|
+
@_collections[path] = new(path:, remote_url:)
|
31
|
+
end
|
32
|
+
|
33
|
+
# @return [Array<Repository>]
|
34
|
+
def all
|
35
|
+
return [] unless defined?(@_collections)
|
36
|
+
|
37
|
+
@_collections.values
|
38
|
+
end
|
39
|
+
|
40
|
+
def send_type; @_send_type end
|
41
|
+
def send_type=(value); @_send_type = value end
|
42
|
+
end
|
43
|
+
|
44
|
+
# @param [String] path
|
45
|
+
# @param [String] remote_url
|
46
|
+
def initialize(path:, remote_url:)
|
47
|
+
@path = path
|
48
|
+
@commits = []
|
49
|
+
@sub_repos = retrieve_sub_repos
|
50
|
+
@owner, @name = GITHUB_REGEXES.each do |regex|
|
51
|
+
str = remote_url.match(regex)
|
52
|
+
break [str[2], str[3]] if str
|
53
|
+
end
|
54
|
+
@url = "https://github.com/#{owner}/#{name}"
|
55
|
+
@format = check_format
|
56
|
+
end
|
57
|
+
|
58
|
+
# @param [String] target
|
59
|
+
# @param [String] source
|
60
|
+
# @return [Boolean]
|
61
|
+
def init_variables(target, source)
|
62
|
+
current_revision = %x(git rev-parse --abbrev-ref HEAD).chomp
|
63
|
+
|
64
|
+
foo = lambda do |hash, context|
|
65
|
+
hash = check_tag(hash)
|
66
|
+
system("git checkout #{hash} -f &> /dev/null")
|
67
|
+
system("git pull &> /dev/null")
|
68
|
+
|
69
|
+
hash = %x(git --no-pager log -1 --format='%h').chomp
|
70
|
+
commit = Commit.find_or_create_by(
|
71
|
+
hash: hash,
|
72
|
+
repo: self,
|
73
|
+
)
|
74
|
+
instance_variable_set("@#{context}", commit)
|
75
|
+
|
76
|
+
if sub_repos.any?
|
77
|
+
%x(git ls-tree HEAD #{sub_repos.map(&:path).join(" ")}).split("\n").map do |line|
|
78
|
+
_, _, sub_hash, sub_path = line.split(" ")
|
79
|
+
sub_repo = Repository.find_or_create_by(
|
80
|
+
path: path + "/" + sub_path,
|
81
|
+
)
|
82
|
+
sub_commit = Commit.find_or_create_by(
|
83
|
+
hash: sub_hash,
|
84
|
+
repo: sub_repo,
|
85
|
+
)
|
86
|
+
sub_repo.instance_variable_set("@#{context}", sub_commit)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
foo.call(target, "from")
|
92
|
+
foo.call(source, "to")
|
93
|
+
|
94
|
+
system("git checkout #{current_revision} -f &> /dev/null")
|
95
|
+
|
96
|
+
true
|
97
|
+
end
|
98
|
+
|
99
|
+
# @return [Boolean]
|
100
|
+
def check_commits
|
101
|
+
authors = retrieve_authors
|
102
|
+
authors.each do |author|
|
103
|
+
commits = retrieve_commits(author)
|
104
|
+
next if commits.empty?
|
105
|
+
|
106
|
+
author.commits_hash[name] = commits
|
107
|
+
# TODO: append `commits` to `repo.commits`
|
108
|
+
end
|
109
|
+
|
110
|
+
if sub_repos.any?
|
111
|
+
sub_repos.each do |sub_repo|
|
112
|
+
next if sub_repo.from.hash == sub_repo.to.hash
|
113
|
+
|
114
|
+
Dir.chdir(sub_repo.path)
|
115
|
+
sub_repo.check_commits
|
116
|
+
end
|
117
|
+
Dir.chdir(path)
|
118
|
+
end
|
119
|
+
|
120
|
+
true
|
121
|
+
end
|
122
|
+
|
123
|
+
# @return [String]
|
124
|
+
def print_last_commit
|
125
|
+
%x(git --no-pager log --reverse --format="#{check_format(ljust: DEFAULT_LJUST - 12)}" --abbrev=7 #{from.hash}..#{to.hash} -1).strip
|
126
|
+
end
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
def send_type
|
131
|
+
self.class.send_type
|
132
|
+
end
|
133
|
+
|
134
|
+
# @param [String] name
|
135
|
+
# @return [String] hash
|
136
|
+
def check_tag(name)
|
137
|
+
list = %x(git tag -l).split("\n")
|
138
|
+
return name unless list.grep(name).any?
|
139
|
+
|
140
|
+
system("git fetch origin tag #{name} -f &> /dev/null")
|
141
|
+
%x(git rev-list -n 1 #{name}).chomp[0...7]
|
142
|
+
end
|
143
|
+
|
144
|
+
# @param [Integer] ljust
|
145
|
+
# @return [String]
|
146
|
+
def check_format(ljust: DEFAULT_LJUST)
|
147
|
+
case send_type
|
148
|
+
when CLI::TYPE_TERMINAL
|
149
|
+
" - " + "%h".yellow + " %<(#{ljust})%s " + "#{url}/commit/%H".gray
|
150
|
+
when CLI::TYPE_SLACK
|
151
|
+
"\\\`<#{url}/commit/%H|%h>\\\` %s - %an"
|
152
|
+
else
|
153
|
+
raise AssertionFailed, "Unknown send type: #{send_type}"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
# @return [Array<Repository>]
|
158
|
+
def retrieve_sub_repos
|
159
|
+
gitmodule = path + "/" + FILE_GITMODULES
|
160
|
+
return [] unless Dir[gitmodule].any?
|
161
|
+
|
162
|
+
file = File.open(gitmodule)
|
163
|
+
resp = file.read
|
164
|
+
file.close
|
165
|
+
|
166
|
+
resp.split(/\[submodule.*\]/)
|
167
|
+
.select { |line| line.match?(/path = /) }
|
168
|
+
.sort
|
169
|
+
.map do |line|
|
170
|
+
line = line.strip
|
171
|
+
repo = Repository.find_or_create_by(
|
172
|
+
path: path + "/" + line.match(/path = (.*)/)[1],
|
173
|
+
remote_url: line.match(/url = (.*)/)[1],
|
174
|
+
)
|
175
|
+
repo.instance_variable_set("@main_repo", self)
|
176
|
+
repo
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# @return [Array<Author>]
|
181
|
+
def retrieve_authors
|
182
|
+
%x(git --no-pager log --pretty=format:"%an" #{from.hash}..#{to.hash})
|
183
|
+
.split("\n").uniq.sort
|
184
|
+
.map { |name| Author.find_or_create_by(name:) }
|
185
|
+
end
|
186
|
+
|
187
|
+
# @param [Author] author
|
188
|
+
# @return [Array<Commit>]
|
189
|
+
def retrieve_commits(author)
|
190
|
+
results =
|
191
|
+
%x(git --no-pager log --reverse --no-merges --author="#{author.name}" --format="%h#{PARSER_TOKEN}#{format}" --abbrev=7 #{from.hash}..#{to.hash})
|
192
|
+
.gsub('"', '\"')
|
193
|
+
.gsub(/[\u0080-\u00ff]/, "")
|
194
|
+
.split("\n")
|
195
|
+
|
196
|
+
results.map do |result|
|
197
|
+
hash, message = result.split(PARSER_TOKEN)
|
198
|
+
Commit.find_or_create_by(
|
199
|
+
hash: hash,
|
200
|
+
repo: self,
|
201
|
+
message: message,
|
202
|
+
author: author,
|
203
|
+
)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
data/lib/ballantine/version.rb
CHANGED
data/lib/ballantine.rb
CHANGED
@@ -6,6 +6,8 @@ require_relative "string"
|
|
6
6
|
require_relative "ballantine/version"
|
7
7
|
require_relative "ballantine/config"
|
8
8
|
require_relative "ballantine/author"
|
9
|
+
require_relative "ballantine/repository"
|
10
|
+
require_relative "ballantine/commit"
|
9
11
|
require_relative "ballantine/cli"
|
10
12
|
|
11
13
|
module Ballantine
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ballantine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.4.pre.
|
4
|
+
version: 0.1.4.pre.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- oohyun15
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -51,7 +51,9 @@ files:
|
|
51
51
|
- lib/ballantine.rb
|
52
52
|
- lib/ballantine/author.rb
|
53
53
|
- lib/ballantine/cli.rb
|
54
|
+
- lib/ballantine/commit.rb
|
54
55
|
- lib/ballantine/config.rb
|
56
|
+
- lib/ballantine/repository.rb
|
55
57
|
- lib/ballantine/version.rb
|
56
58
|
- lib/string.rb
|
57
59
|
homepage: https://github.com/oohyun15/ballantine
|