gitlab_awesome_release 0.1.0.beta2 → 0.1.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env.example +1 -0
- data/lib/gitlab_awesome_release.rb +1 -0
- data/lib/gitlab_awesome_release/cli.rb +40 -7
- data/lib/gitlab_awesome_release/gitlab_logging_ext.rb +24 -0
- data/lib/gitlab_awesome_release/project.rb +17 -6
- data/lib/gitlab_awesome_release/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e6ff73c0318107e4b3b2cc7fa5dda3f7630b429
|
4
|
+
data.tar.gz: 156be8774fdfd86f83040b1c33edce322214efe2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 758d123c1789cbe68239e56cb5116f8ba4dff72dc84009e9b897da9aa0f72f67cdb0d1030737e1a3bc0b98bf28c488d900b7759ed50ae5c1b18f11ae01e15829
|
7
|
+
data.tar.gz: 29f84ad3e708a9f79adeae1a6bd22e8f202dc2e5bcbad32e8ef113c9587f16d271e2adeae01e9f547da1d332239949e5655a422cf90b41e42556e2af662df5aa
|
data/.env.example
CHANGED
@@ -4,6 +4,8 @@ require "dotenv"
|
|
4
4
|
|
5
5
|
module GitlabAwesomeRelease
|
6
6
|
class CLI < Thor
|
7
|
+
DEFAULT_VERSION_FORMAT = "^v?[\\d.]+"
|
8
|
+
|
7
9
|
desc "version", "Show gitlab_awesome_release version"
|
8
10
|
def version
|
9
11
|
puts GitlabAwesomeRelease::VERSION
|
@@ -16,33 +18,45 @@ module GitlabAwesomeRelease
|
|
16
18
|
option :gitlab_api_endpoint
|
17
19
|
option :gitlab_api_private_token
|
18
20
|
option :gitlab_project_name
|
21
|
+
option :allow_tag_format, desc: "Regular expression of tag format", default: "^v?[\\d.]+"
|
22
|
+
option :log_level, desc: "Log level (debug|info|warn|error|fatal|unknown)", default: "info"
|
19
23
|
def create_note
|
20
24
|
Dotenv.load
|
21
25
|
|
22
26
|
gitlab_api_endpoint = option_or_env!(:gitlab_api_endpoint)
|
23
27
|
gitlab_api_private_token = option_or_env!(:gitlab_api_private_token)
|
24
28
|
gitlab_project_name = option_or_env!(:gitlab_project_name)
|
29
|
+
allow_tag_format = option_or_env(:allow_tag_format, DEFAULT_VERSION_FORMAT)
|
30
|
+
|
31
|
+
@logger = Logger.new(STDOUT)
|
32
|
+
@logger.level = logger_level(option_or_env(:log_level))
|
33
|
+
@logger.formatter = proc{ |severity, datetime, progname, message|
|
34
|
+
"[#{datetime}] #{message}\n"
|
35
|
+
}
|
25
36
|
|
26
37
|
project = GitlabAwesomeRelease::Project.new(
|
27
|
-
api_endpoint:
|
28
|
-
private_token:
|
29
|
-
project_name:
|
38
|
+
api_endpoint: gitlab_api_endpoint,
|
39
|
+
private_token: gitlab_api_private_token,
|
40
|
+
project_name: gitlab_project_name,
|
41
|
+
allow_tag_format: /#{allow_tag_format}/,
|
42
|
+
logger: @logger,
|
30
43
|
)
|
31
44
|
|
32
|
-
tag_names = project.
|
45
|
+
tag_names = project.release_tag_names
|
33
46
|
oldest_tag = option_or_env(:from) || tag_names.first
|
34
47
|
newest_tag = option_or_env(:to) || tag_names.last
|
35
48
|
|
36
49
|
changelog = project.generate_change_log(oldest_tag, newest_tag)
|
37
50
|
|
38
51
|
write_changelog(changelog)
|
52
|
+
@logger.info "finish!"
|
39
53
|
end
|
40
54
|
|
41
55
|
private
|
42
56
|
|
43
|
-
def option_or_env(name)
|
57
|
+
def option_or_env(name, default = nil)
|
44
58
|
upper_name = name.to_s.upcase
|
45
|
-
options[name].presence || ENV[upper_name].presence
|
59
|
+
options[name].presence || ENV[upper_name].presence || default
|
46
60
|
end
|
47
61
|
|
48
62
|
def option_or_env!(name)
|
@@ -59,10 +73,29 @@ module GitlabAwesomeRelease
|
|
59
73
|
File.open(filename, "wb") do |f|
|
60
74
|
f.write(changelog)
|
61
75
|
end
|
62
|
-
|
76
|
+
@logger.info "Write to #{filename}"
|
63
77
|
else
|
64
78
|
puts changelog
|
65
79
|
end
|
66
80
|
end
|
81
|
+
|
82
|
+
def logger_level(log_level)
|
83
|
+
case log_level.to_sym
|
84
|
+
when :debug
|
85
|
+
Logger::DEBUG
|
86
|
+
when :error
|
87
|
+
Logger::ERROR
|
88
|
+
when :fatal
|
89
|
+
Logger::FATAL
|
90
|
+
when :info
|
91
|
+
Logger::INFO
|
92
|
+
when :unknown
|
93
|
+
Logger::UNKNOWN
|
94
|
+
when :warn
|
95
|
+
Logger::WARN
|
96
|
+
else
|
97
|
+
raise "Unknown log_level: #{log_level}"
|
98
|
+
end
|
99
|
+
end
|
67
100
|
end
|
68
101
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module GitlabAwesomeRelease
|
2
|
+
module GitlabLoggingExt
|
3
|
+
def get(path, options={})
|
4
|
+
start_time = Time.now
|
5
|
+
|
6
|
+
super(path, options)
|
7
|
+
|
8
|
+
ensure
|
9
|
+
end_time = Time.now
|
10
|
+
|
11
|
+
# NOTE: options[:headers] contains PRIVATE-TOKEN
|
12
|
+
_options = options.reject{ |k, _v| k == :headers }
|
13
|
+
logger.debug "(#{end_time - start_time} sec) GET #{path} #{_options}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def logger
|
17
|
+
@logger ||= Logger.new(STDOUT)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
Gitlab::Request.class_eval do
|
23
|
+
prepend GitlabAwesomeRelease::GitlabLoggingExt
|
24
|
+
end
|
@@ -7,26 +7,30 @@ module GitlabAwesomeRelease
|
|
7
7
|
|
8
8
|
PER_PAGE = 100
|
9
9
|
|
10
|
-
# @param api_endpoint
|
11
|
-
# @param private_token
|
12
|
-
# @param project_name
|
13
|
-
|
10
|
+
# @param api_endpoint [String]
|
11
|
+
# @param private_token [String]
|
12
|
+
# @param project_name [String]
|
13
|
+
# @param allow_tag_format [Regexp]
|
14
|
+
def initialize(api_endpoint:, private_token:, project_name:, allow_tag_format:, logger:)
|
14
15
|
Gitlab.configure do |config|
|
15
16
|
config.endpoint = api_endpoint
|
16
17
|
config.private_token = private_token
|
17
18
|
end
|
18
19
|
@project_name = project_name
|
20
|
+
@allow_tag_format = allow_tag_format
|
21
|
+
@logger = logger
|
19
22
|
end
|
20
23
|
|
21
24
|
def web_url
|
22
25
|
@web_url ||= Gitlab.project(escaped_project_name).web_url
|
23
26
|
end
|
24
27
|
|
25
|
-
# all tag
|
28
|
+
# all tag names order by author date
|
26
29
|
# @return [Array<String>]
|
27
30
|
def all_tag_names
|
28
31
|
return @all_tag_names if @all_tag_names
|
29
32
|
|
33
|
+
@logger.info "fetch git tags"
|
30
34
|
repo_tags =
|
31
35
|
with_paging do |params|
|
32
36
|
Gitlab.repo_tags(escaped_project_name, params)
|
@@ -34,12 +38,17 @@ module GitlabAwesomeRelease
|
|
34
38
|
@all_tag_names = repo_tags.sort_by{ |tag| tag.commit.authored_date }.map(&:name)
|
35
39
|
end
|
36
40
|
|
41
|
+
# @return [Array<String>]
|
42
|
+
def release_tag_names
|
43
|
+
all_tag_names.find_all { |tag| tag =~ @allow_tag_format }
|
44
|
+
end
|
45
|
+
|
37
46
|
# @param oldest_tag [String]
|
38
47
|
# @param newest_tag [String]
|
39
48
|
# @return [String]
|
40
49
|
def generate_change_log(oldest_tag, newest_tag)
|
41
50
|
release_notes = []
|
42
|
-
|
51
|
+
release_tag_names.within(oldest_tag, newest_tag).each_cons(2) do |from, to|
|
43
52
|
release_notes << generate_release_note(from, to)
|
44
53
|
end
|
45
54
|
release_notes << generate_release_note(newest_tag, "HEAD", title: "Unreleased") if newest_tag == all_tag_names.last
|
@@ -56,6 +65,8 @@ module GitlabAwesomeRelease
|
|
56
65
|
# @param title [String]
|
57
66
|
# @return [String]
|
58
67
|
def generate_release_note(from, to, title: nil)
|
68
|
+
@logger.info "generate release note (#{from}...#{to})"
|
69
|
+
|
59
70
|
title ||= to
|
60
71
|
summary = merge_requests_summary_between(from, to)
|
61
72
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitlab_awesome_release
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.
|
4
|
+
version: 0.1.0.beta3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sue445
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -188,6 +188,7 @@ files:
|
|
188
188
|
- lib/gitlab_awesome_release.rb
|
189
189
|
- lib/gitlab_awesome_release/array_within_ext.rb
|
190
190
|
- lib/gitlab_awesome_release/cli.rb
|
191
|
+
- lib/gitlab_awesome_release/gitlab_logging_ext.rb
|
191
192
|
- lib/gitlab_awesome_release/project.rb
|
192
193
|
- lib/gitlab_awesome_release/version.rb
|
193
194
|
- script/build.sh
|