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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70ed582ce67159f6cbe5199f9322fc946fe65cdf
4
- data.tar.gz: 97ea9c7a5b9dc5afc9080dee8da1589d640278bd
3
+ metadata.gz: 9e6ff73c0318107e4b3b2cc7fa5dda3f7630b429
4
+ data.tar.gz: 156be8774fdfd86f83040b1c33edce322214efe2
5
5
  SHA512:
6
- metadata.gz: 12fbf0ffd8df27ab7e77cdd65ccbc11ae735690545eec60ad609c4a18db6af684c44c0ab76706eefff9beb3615d85284c3451b54f004a54f85216d7436ad42b4
7
- data.tar.gz: 6098f639d11a6c0608bca5afd18fb2a193bcbe290b9bb4c9fff32805a8ea4ae8408293c79bae4cf6419f6f17e6898a4975c04e85a858485a253b457772a7d3d5
6
+ metadata.gz: 758d123c1789cbe68239e56cb5116f8ba4dff72dc84009e9b897da9aa0f72f67cdb0d1030737e1a3bc0b98bf28c488d900b7759ed50ae5c1b18f11ae01e15829
7
+ data.tar.gz: 29f84ad3e708a9f79adeae1a6bd22e8f202dc2e5bcbad32e8ef113c9587f16d271e2adeae01e9f547da1d332239949e5655a422cf90b41e42556e2af662df5aa
data/.env.example CHANGED
@@ -1,3 +1,4 @@
1
1
  GITLAB_API_ENDPOINT=http://example.com/api/v3
2
2
  GITLAB_API_PRIVATE_TOKEN=XXXXXXXXXXXXXXXXXXX
3
3
  GITLAB_PROJECT_NAME=group/name
4
+ ALLOW_TAG_FORMAT=^v?[\d.]+
@@ -2,6 +2,7 @@ require "active_support/all"
2
2
  require "gitlab_awesome_release/version"
3
3
  require "gitlab_awesome_release/project"
4
4
  require "gitlab"
5
+ # require "gitlab_awesome_release/gitlab_logging_ext"
5
6
 
6
7
  module GitlabAwesomeRelease
7
8
  # Your code goes here...
@@ -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: gitlab_api_endpoint,
28
- private_token: gitlab_api_private_token,
29
- project_name: gitlab_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.all_tag_names
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
- puts "Write #{filename}"
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 [String]
11
- # @param private_token [String]
12
- # @param project_name [String]
13
- def initialize(api_endpoint:, private_token:, project_name:)
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 name order by author date
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
- all_tag_names.within(oldest_tag, newest_tag).each_cons(2) do |from, to|
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
 
@@ -1,3 +1,3 @@
1
1
  module GitlabAwesomeRelease
2
- VERSION = "0.1.0.beta2"
2
+ VERSION = "0.1.0.beta3"
3
3
  end
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.beta2
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-08 00:00:00.000000000 Z
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