git-chlog 0.1.0 → 0.2.0

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: 0252df630af5256b8188c00be555ecd264e9fb07
4
- data.tar.gz: 426a0cc5da377b2ec0d793a9cd7e7d50019a05a9
3
+ metadata.gz: dd4344829226d0ef8ee4b1114eaa0e51f42f28d0
4
+ data.tar.gz: c8bca581e886d709df04b2381dbf8936f3548424
5
5
  SHA512:
6
- metadata.gz: d645e2fed6de7f9eb9ef5d5b55476537b787d5c7b6c33837733a538eff54cd79469717516a7c3aa1491636fca36960ff6c9bbe650b0d90fea1bf4b108af8dd46
7
- data.tar.gz: 5c3d28ec847c5667a765a5006b8b0141ac2e7695ef04b381c280990b12c2a40177045932746942b6a34cb3f77114b2020220e7025503405be0237fdf395572f9
6
+ metadata.gz: d933a5420529b961a21f04dabeb35aeef17216f807df696d5a9e6f21f2aa5429119909b6aac78597a73e8ab8a34be5af5fdf1e822ce69f657cb05c16a780e2c9
7
+ data.tar.gz: e05b442fbdb33afed083aa6e3eafbf4ec4a73f9aadb018becc1845a26e79dd172dbd724e27d90480cc0c30923dddf52359af6d07592df05e83b6fe30ac406b4f
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # Change Log
2
+ ## [v0.2.0](https://github.com/teohm/git-chlog/tree/v0.2.0)
3
+
4
+ [Full Changelog](https://github.com/teohm/git-chlog/compare/v0.1.0...v0.2.0)
5
+ * 2017-11-02 - Fix GitRepo#prev_tag to handle HEAD release [#5](https://github.com/teohm/git-chlog/pull/5)
6
+ * 2017-11-02 - Add --prepare-release to include unreleased merges when prepare release [#4](https://github.com/teohm/git-chlog/pull/4)
7
+
2
8
  ## [v0.1.0](https://github.com/teohm/git-chlog/tree/v0.1.0)
3
- Released on 2017-11-01
4
9
 
5
10
  [Full Changelog](https://github.com/teohm/git-chlog/compare/6bcc2fb6e...v0.1.0)
6
11
  * 2017-11-01 - fix :allowed_push_host metadata in gemspec [#3](https://github.com/teohm/git-chlog/pull/3)
data/exe/git-chlog CHANGED
@@ -74,12 +74,18 @@ module CodeHosting
74
74
  end
75
75
 
76
76
  class Release
77
- attr_reader :tag, :date
77
+ attr_reader :tag, :git_ref, :label, :date
78
78
  attr_accessor :prev_tag
79
79
 
80
- def initialize(tag:, date:)
80
+ def self.build_head(tag:, label:)
81
+ Release.new(tag: tag, date: Time.now, git_ref: "HEAD", label: label)
82
+ end
83
+
84
+ def initialize(tag:, date:, git_ref: nil, label: nil)
81
85
  @tag = tag
82
- @date = Time.parse(date)
86
+ @git_ref = git_ref || tag
87
+ @label = label || tag
88
+ @date = Time.parse(date.to_s)
83
89
  end
84
90
 
85
91
  def version_number
@@ -91,16 +97,22 @@ class Release
91
97
  end
92
98
  end
93
99
 
94
- module GitRepo
95
- def self.origin_remote_url
100
+ class GitRepo
101
+ attr_reader :options
102
+
103
+ def initialize(options = {})
104
+ @options = options.dup
105
+ end
106
+
107
+ def origin_remote_url
96
108
  `git remote get-url origin`.strip
97
109
  end
98
110
 
99
- def self.first_commit_sha
111
+ def first_commit_sha
100
112
  `git rev-list --max-parents=0 HEAD`.strip[0...9]
101
113
  end
102
114
 
103
- def self.prev_tag(current_tag)
115
+ def prev_tag(current_tag)
104
116
  `git log --format="%D" #{current_tag}~1`
105
117
  .split("\n")
106
118
  .select { |line| line.start_with?("tag:") }
@@ -108,36 +120,50 @@ module GitRepo
108
120
  &.match(/tag: ([^,]+)/)&.captures&.first
109
121
  end
110
122
 
111
- def self.load_releases
112
- LoadReleases.new(git_repo: self).call
123
+ def load_releases
124
+ LoadReleases.new(
125
+ git_repo: self,
126
+ head_release_tag: options[:prepare_release]
127
+ ).call
113
128
  end
114
129
 
115
- def self.load_merged_requests(release, code_hosting)
130
+ def load_merged_requests(release, code_hosting)
116
131
  LoadMergedRequests.new(
117
132
  release: release, code_hosting: code_hosting
118
133
  ).call
119
134
  end
120
135
 
121
136
  class LoadReleases
122
- attr_reader :git_repo
137
+ attr_reader :git_repo, :head_release_tag
123
138
 
124
- def initialize(git_repo:)
139
+ def initialize(git_repo:, head_release_tag:)
125
140
  @git_repo = git_repo
141
+ @head_release_tag = head_release_tag
126
142
  end
127
143
 
128
144
  def call
129
145
  raw_git_tag_data
130
146
  .map { |release_params| Release.new(release_params) }
147
+ .sort
148
+ .reverse
149
+ .unshift(head_release)
150
+ .compact
131
151
  .map { |release|
132
- release.prev_tag = git_repo.prev_tag(release.tag)
152
+ release.prev_tag = git_repo.prev_tag(release.git_ref)
133
153
  release
134
154
  }
135
- .sort
136
- .reverse
137
155
  end
138
156
 
139
157
  private
140
158
 
159
+ def head_release
160
+ if head_release_tag
161
+ Release.build_head(tag: head_release_tag, label: head_release_tag)
162
+ else
163
+ nil
164
+ end
165
+ end
166
+
141
167
  def raw_git_tag_data
142
168
  `git tag --format='%(refname:short)|%(creatordate:iso8601)'`
143
169
  .split("\n")
@@ -169,7 +195,7 @@ module GitRepo
169
195
  end
170
196
 
171
197
  def tag_range
172
- [release.tag, release.prev_tag].compact.join("...")
198
+ [release.git_ref, release.prev_tag].compact.join("...")
173
199
  end
174
200
 
175
201
  def is_merge_request?(raw_commit)
@@ -229,8 +255,7 @@ class PrintChangeLog
229
255
  private
230
256
 
231
257
  def print_release_heading(out, release)
232
- out.puts("## [#{release.tag}](#{code_hosting.tag_url(release.tag)})")
233
- out.puts("Released on #{format_date(release.date)}")
258
+ out.puts("## [#{release.label}](#{code_hosting.tag_url(release.tag)})")
234
259
  end
235
260
 
236
261
  def print_full_changelog_link(out, release)
@@ -272,8 +297,29 @@ class PrintChangeLog
272
297
  end
273
298
  end
274
299
 
300
+ options = {
301
+ prepare_release: false
302
+ }
303
+
304
+ require 'optparse'
305
+ OptionParser.new do |opts|
306
+ opts.banner = "Usage: git chlog [options]"
307
+
308
+ opts.on(
309
+ "--prepare-release=[TAG]",
310
+ "Add unreleased changes when preparing new release") do |tag|
311
+ options[:prepare_release] = tag || "HEAD"
312
+ end
313
+
314
+ opts.on("-h", "--help", "Prints this help") do
315
+ puts opts
316
+ exit
317
+ end
318
+ end.parse!
319
+
320
+ git_repo = GitRepo.new(options)
275
321
  PrintChangeLog.new(
276
- code_hosting: CodeHosting.build(GitRepo.origin_remote_url),
277
- git_repo: GitRepo,
322
+ code_hosting: CodeHosting.build(git_repo.origin_remote_url),
323
+ git_repo: git_repo,
278
324
  issue_tracker: IssueTracker::PivotalTracker
279
325
  ).call
@@ -1,5 +1,5 @@
1
1
  module Git
2
2
  module Chlog
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-chlog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Huiming Teo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-01 00:00:00.000000000 Z
11
+ date: 2017-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler