Skip to content

Commit 70a57d2

Browse files
committed
Add HEAD feature to releases
1 parent 86d443a commit 70a57d2

File tree

8 files changed

+88
-22
lines changed

8 files changed

+88
-22
lines changed

Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -3,6 +3,7 @@ PATH
3
specs:
3
specs:
4
changelog (0.0.1)
4
changelog (0.0.1)
5
grit
5
grit
6+
highline
6
methadone
7
methadone
7
redcarpet
8
redcarpet
8

9

@@ -30,6 +31,7 @@ GEM
30
grit (2.4.1)
31
grit (2.4.1)
31
diff-lcs (~> 1.1)
32
diff-lcs (~> 1.1)
32
mime-types (~> 1.15)
33
mime-types (~> 1.15)
34+
highline (1.6.9)
33
json (1.6.5)
35
json (1.6.5)
34
methadone (0.5.1)
36
methadone (0.5.1)
35
bundler
37
bundler

bin/changelog

Lines changed: 17 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -2,28 +2,45 @@
2

2

3
require 'optparse'
3
require 'optparse'
4
require 'methadone'
4
require 'methadone'
5+
require 'highline/import'
5
require 'changelog'
6
require 'changelog'
6

7

7
include Methadone::Main
8
include Methadone::Main
8

9

9
main do |release|
10
main do |release|
10

11

12+
# upcase head
13+
release = 'HEAD' if release == 'head' || release == 'next'
14+
15+
# set repo path
11
Changelog.repo_path = File.expand_path(options[:repo])
16
Changelog.repo_path = File.expand_path(options[:repo])
12

17

18+
# set release
13
rls = Changelog::Release.new(release)
19
rls = Changelog::Release.new(release)
20+
21+
if release == 'HEAD'
22+
release = ask("Next release tag [last: rls.previous_tag]> ")
23+
end
24+
25+
puts "#{Changelog::Header.new(release)}\n"
26+
14
rls.listings.each do |listing|
27
rls.listings.each do |listing|
15
puts listing
28
puts listing
16
end
29
end
30+
31+
puts "\n"
17
end
32
end
18

33

19
options[:repo] = ".git"
34
options[:repo] = ".git"
20

35

21
description "Generate markdown formatted changelog from your git revision tags"
36
description "Generate markdown formatted changelog from your git revision tags"
22

37

23
on("-r REPO","--repo","Path to your git repository")
38
on("-r REPO","--repo","Path to your git repository")
39+
on("-m","--markdown","Output markdown formated")
24

40

25
arg :release, :required
41
arg :release, :required
26
arg :repo, :optional
42
arg :repo, :optional
43+
arg :markdown, :optional
27

44

28
version Changelog::VERSION
45
version Changelog::VERSION
29

46

changelog.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
24
s.add_development_dependency('rdoc')
24
s.add_development_dependency('rdoc')
25
s.add_development_dependency('aruba')
25
s.add_development_dependency('aruba')
26
s.add_development_dependency('rake','~> 0.9.2')
26
s.add_development_dependency('rake','~> 0.9.2')
27+
s.add_dependency('highline')
27
s.add_dependency('methadone')
28
s.add_dependency('methadone')
28
s.add_dependency('grit')
29
s.add_dependency('grit')
29
s.add_dependency('redcarpet')
30
s.add_dependency('redcarpet')

features/release.feature

Lines changed: 17 additions & 4 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -3,7 +3,20 @@ Feature: Output the changelog
3
I want to output the changelog
3
I want to output the changelog
4

4

5
Scenario: Output changelog for a release tag
5
Scenario: Output changelog for a release tag
6-
When I successfully run `changelog CL.0.1.20120120.1 -r ../../spec/dot_git`
6+
When I successfully run `changelog CL.0.1.20120120.1 --markdown --repo ../../spec/dot_git`
7-
Then the output should contain "* Fixes [ENG-6580](https://windermeresolutions.atlassian.net/browse/ENG-6580). Test JIRA tag [bd13232](https://github.com/dvantuyl/changelog/bd13232) (Dwight van Tuyl)"
7+
Then the output should contain "[CL.0.1.20120120.1](https://github.com/dvantuyl/changelog/tree/CL.0.1.20120120.1)"
8-
And the output should contain "* Test non-JIRA tag [ece268b](https://github.com/dvantuyl/changelog/ece268b) (Dwight van Tuyl)"
8+
And the output should contain "Fixes [ENG-6580](https://windermeresolutions.atlassian.net/browse/ENG-6580). Test JIRA tag [bd13232](https://github.com/dvantuyl/changelog/bd13232)"
9-
And the output should contain "* [ENG-4744](https://windermeresolutions.atlassian.net/browse/ENG-4744): Test JIRA Tag [32cc38a](https://github.com/dvantuyl/changelog/32cc38a) (Dwight van Tuyl)"
9+
And the output should contain "Test non-JIRA tag [ece268b](https://github.com/dvantuyl/changelog/ece268b)"
10+
And the output should contain "[ENG-4744](https://windermeresolutions.atlassian.net/browse/ENG-4744): Test JIRA Tag [32cc38a](https://github.com/dvantuyl/changelog/32cc38a)"
11+
12+
13+
Scenario: Output changelog for the first release tag
14+
When I successfully run `changelog CL.0.1.20120120.0 --markdown --repo ../../spec/dot_git`
15+
Then the output should contain "[CL.0.1.20120120.0](https://github.com/dvantuyl/changelog/tree/CL.0.1.20120120.0)"
16+
And the output should contain "Fixed [ENG-6627](https://windermeresolutions.atlassian.net/browse/ENG-6627)-Initial Commit [4f4f0a5](https://github.com/dvantuyl/changelog/4f4f0a5)"
17+
And the output should contain "[ENG-5091](https://windermeresolutions.atlassian.net/browse/ENG-5091): Test JIRA tag [3209c90](https://github.com/dvantuyl/changelog/3209c90)"
18+
19+
Scenario: Output changelog for the HEAD release
20+
When I run `changelog head --markdown --repo ../../spec/dot_git` interactively
21+
And I type "CL.0.1.20120121.0"
22+
Then the output should contain "[CL.0.1.20120121.0](https://github.com/dvantuyl/changelog/tree/CL.0.1.20120121.0)"

lib/changelog.rb

Lines changed: 18 additions & 4 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -4,6 +4,7 @@
4
require "changelog/version"
4
require "changelog/version"
5
require "changelog/release"
5
require "changelog/release"
6
require "changelog/listing"
6
require "changelog/listing"
7+
require "changelog/header"
7

8

8
module Changelog
9
module Changelog
9

10

@@ -18,23 +19,36 @@ def remote_url
18
@remote_url ||= repo.config["remote.origin.url"]
19
@remote_url ||= repo.config["remote.origin.url"]
19
end
20
end
20

21

22+
def remote_https_owner
23+
remote_url.match(/github.com\/(\w+)\//)[1]
24+
end
25+
26+
def remote_ssh_owner
27+
remote_url.match(/:(\w+)\//)[1]
28+
end
29+
21
def github?
30
def github?
22
remote_url && remote_url.match(/github\.com/)
31
remote_url && remote_url.match(/github\.com/)
23
end
32
end
24

33

25
def github_owner
34
def github_owner
26
return nil unless github?
35
return nil unless github?
27-
36+
@owner ||= remote_url.match(/https/) ? remote_https_owner : remote_ssh_owner
28-
#http or ssh
29-
@owner ||= remote_url.match(/https/) ? remote_url.match(/github.com\/(\w+)\//)[1] : remote_url.match(/:(\w+)\//)[1]
30
end
37
end
31

38

32
def github_project
39
def github_project
33
return nil unless github?
40
return nil unless github?
34-
35
@project ||= remote_url.match(/\/(\w+)\.git/)[1]
41
@project ||= remote_url.match(/\/(\w+)\.git/)[1]
36
end
42
end
37

43

44+
def github_base
45+
return nil unless github?
46+
@github_base ||= "https://github.com/#{github_owner}/#{github_project}"
47+
end
48+
49+
def jira_base
50+
"https://windermeresolutions.atlassian.net"
51+
end
38

52

39
end
53
end
40

54

lib/changelog/listing.rb

Lines changed: 2 additions & 7 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -9,19 +9,14 @@ def to_s
9
end
9
end
10

10

11
def jirafy_message
11
def jirafy_message
12-
jira_base = "https://windermeresolutions.atlassian.net"
13
key_pattern = /([A-Z]+-\d+)/
12
key_pattern = /([A-Z]+-\d+)/
14

13

15-
message.gsub(key_pattern, '[\1](' + jira_base + '/browse/\1)')
14+
message.gsub(key_pattern, '[\1](' + Changelog.jira_base + '/browse/\1)')
16
end
15
end
17

16

18
def githubify_id
17
def githubify_id
19-
20
if Changelog.github?
18
if Changelog.github?
21-
owner = Changelog.github_owner
19+
"[#{id_abbrev}](#{Changelog.github_base}/#{id_abbrev})"
22-
project = Changelog.github_project
23-
24-
"[#{id_abbrev}](https://github.com/#{owner}/#{project}/#{id_abbrev})"
25
else
20
else
26
"#{id_abbrev}"
21
"#{id_abbrev}"
27
end
22
end

lib/changelog/release.rb

Lines changed: 19 additions & 6 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -1,26 +1,39 @@
1
module Changelog
1
module Changelog
2
class Release
2
class Release
3

3

4+
attr_accessor :tag
5+
4
def initialize(tag)
6
def initialize(tag)
5
@tag = tag
7
@tag = tag
8+
raise "Tag not found" unless tag_index || is_head?
9+
end
10+
11+
def tags
12+
@tags ||= Changelog.repo.tags.map {|t| t.name}
13+
end
14+
15+
def tag_index
16+
@tag_index ||= tags.index(tag)
17+
end
18+
19+
def is_head?
20+
tag == 'HEAD'
6
end
21
end
7

22

8
def previous_tag
23
def previous_tag
9-
@previous_tag ||= _previous_tag
24+
@previous_tag ||= (previous_tag_index >= 0 ? tags[previous_tag_index] : nil)
10
end
25
end
11

26

12-
def _previous_tag
27+
def previous_tag_index
13-
tags = Changelog.repo.tags.map {|tag| tag.name}
28+
@previous_tag_index ||= (is_head? ? tags.size - 1 : tag_index - 1)
14-
tag_index = tags.index(@tag)
15-
tag_index == 0 ? nil : tags[tag_index -1]
16
end
29
end
17

30

18
def listings
31
def listings
19
@listings ||= _listings
32
@listings ||= _listings
20
end
33
end
21

34

22
def _listings
35
def _listings
23-
ref = (previous_tag ? "#{previous_tag}..#{@tag}" : @tag)
36+
ref = (previous_tag ? "#{previous_tag}..#{tag}" : tag)
24

37

25
Changelog.repo.commits(ref).map { |commit|
38
Changelog.repo.commits(ref).map { |commit|
26
Listing.create(Changelog.repo, :id => commit.id)
39
Listing.create(Changelog.repo, :id => commit.id)

spec/release_spec.rb

Lines changed: 12 additions & 1 deletion
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -3,6 +3,11 @@
3
module Changelog
3
module Changelog
4
describe Release do
4
describe Release do
5

5

6+
describe ".new" do
7+
it "raises exception if tag doesn't exist" do
8+
lambda { Release.new('bogus') }.should raise_error
9+
end
10+
end
6

11

7
describe "#previous_tag" do
12
describe "#previous_tag" do
8

13

@@ -15,10 +20,16 @@ module Changelog
15
rls = Release.new('CL.0.1.20120120.0')
20
rls = Release.new('CL.0.1.20120120.0')
16
rls.previous_tag.should be_nil
21
rls.previous_tag.should be_nil
17
end
22
end
23+
24+
it "returns the last tag before HEAD" do
25+
rls = Release.new('HEAD')
26+
rls.previous_tag.should == 'CL.0.1.20120120.1'
27+
end
28+
18
end
29
end
19

30

20
describe "#listings" do
31
describe "#listings" do
21-
32+
22
it "returns the release's commit listings" do
33
it "returns the release's commit listings" do
23
rls = Release.new('CL.0.1.20120120.1')
34
rls = Release.new('CL.0.1.20120120.1')
24
rls.listings.size.should == 3
35
rls.listings.size.should == 3

0 commit comments

Comments
 (0)