Skip to content

Commit

Permalink
Add HEAD feature to releases
Browse files Browse the repository at this point in the history
  • Loading branch information
dvantuyl committed Jan 23, 2012
1 parent 86d443a commit 70a57d2
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 22 deletions.
2 changes: 2 additions & 0 deletions Gemfile.lock
Expand Up @@ -3,6 +3,7 @@ PATH
specs:
changelog (0.0.1)
grit
highline
methadone
redcarpet

Expand Down Expand Up @@ -30,6 +31,7 @@ GEM
grit (2.4.1)
diff-lcs (~> 1.1)
mime-types (~> 1.15)
highline (1.6.9)
json (1.6.5)
methadone (0.5.1)
bundler
Expand Down
17 changes: 17 additions & 0 deletions bin/changelog
Expand Up @@ -2,28 +2,45 @@

require 'optparse'
require 'methadone'
require 'highline/import'
require 'changelog'

include Methadone::Main

main do |release|

# upcase head
release = 'HEAD' if release == 'head' || release == 'next'

# set repo path
Changelog.repo_path = File.expand_path(options[:repo])

# set release
rls = Changelog::Release.new(release)

if release == 'HEAD'
release = ask("Next release tag [last: rls.previous_tag]> ")
end

puts "#{Changelog::Header.new(release)}\n"

rls.listings.each do |listing|
puts listing
end

puts "\n"
end

options[:repo] = ".git"

description "Generate markdown formatted changelog from your git revision tags"

on("-r REPO","--repo","Path to your git repository")
on("-m","--markdown","Output markdown formated")

arg :release, :required
arg :repo, :optional
arg :markdown, :optional

version Changelog::VERSION

Expand Down
1 change: 1 addition & 0 deletions changelog.gemspec
Expand Up @@ -24,6 +24,7 @@ Gem::Specification.new do |s|
s.add_development_dependency('rdoc')
s.add_development_dependency('aruba')
s.add_development_dependency('rake','~> 0.9.2')
s.add_dependency('highline')
s.add_dependency('methadone')
s.add_dependency('grit')
s.add_dependency('redcarpet')
Expand Down
21 changes: 17 additions & 4 deletions features/release.feature
Expand Up @@ -3,7 +3,20 @@ Feature: Output the changelog
I want to output the changelog

Scenario: Output changelog for a release tag
When I successfully run `changelog CL.0.1.20120120.1 -r ../../spec/dot_git`
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)"
And the output should contain "* Test non-JIRA tag [ece268b](https://github.com/dvantuyl/changelog/ece268b) (Dwight van Tuyl)"
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)"
When I successfully run `changelog CL.0.1.20120120.1 --markdown --repo ../../spec/dot_git`
Then the output should contain "[CL.0.1.20120120.1](https://github.com/dvantuyl/changelog/tree/CL.0.1.20120120.1)"
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)"
And the output should contain "Test non-JIRA tag [ece268b](https://github.com/dvantuyl/changelog/ece268b)"
And the output should contain "[ENG-4744](https://windermeresolutions.atlassian.net/browse/ENG-4744): Test JIRA Tag [32cc38a](https://github.com/dvantuyl/changelog/32cc38a)"


Scenario: Output changelog for the first release tag
When I successfully run `changelog CL.0.1.20120120.0 --markdown --repo ../../spec/dot_git`
Then the output should contain "[CL.0.1.20120120.0](https://github.com/dvantuyl/changelog/tree/CL.0.1.20120120.0)"
And the output should contain "Fixed [ENG-6627](https://windermeresolutions.atlassian.net/browse/ENG-6627)-Initial Commit [4f4f0a5](https://github.com/dvantuyl/changelog/4f4f0a5)"
And the output should contain "[ENG-5091](https://windermeresolutions.atlassian.net/browse/ENG-5091): Test JIRA tag [3209c90](https://github.com/dvantuyl/changelog/3209c90)"

Scenario: Output changelog for the HEAD release
When I run `changelog head --markdown --repo ../../spec/dot_git` interactively
And I type "CL.0.1.20120121.0"
Then the output should contain "[CL.0.1.20120121.0](https://github.com/dvantuyl/changelog/tree/CL.0.1.20120121.0)"
22 changes: 18 additions & 4 deletions lib/changelog.rb
Expand Up @@ -4,6 +4,7 @@
require "changelog/version"
require "changelog/release"
require "changelog/listing"
require "changelog/header"

module Changelog

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

def remote_https_owner
remote_url.match(/github.com\/(\w+)\//)[1]
end

def remote_ssh_owner
remote_url.match(/:(\w+)\//)[1]
end

def github?
remote_url && remote_url.match(/github\.com/)
end

def github_owner
return nil unless github?

#http or ssh
@owner ||= remote_url.match(/https/) ? remote_url.match(/github.com\/(\w+)\//)[1] : remote_url.match(/:(\w+)\//)[1]
@owner ||= remote_url.match(/https/) ? remote_https_owner : remote_ssh_owner
end

def github_project
return nil unless github?

@project ||= remote_url.match(/\/(\w+)\.git/)[1]
end

def github_base
return nil unless github?
@github_base ||= "https://github.com/#{github_owner}/#{github_project}"
end

def jira_base
"https://windermeresolutions.atlassian.net"
end

end

Expand Down
9 changes: 2 additions & 7 deletions lib/changelog/listing.rb
Expand Up @@ -9,19 +9,14 @@ def to_s
end

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

message.gsub(key_pattern, '[\1](' + jira_base + '/browse/\1)')
message.gsub(key_pattern, '[\1](' + Changelog.jira_base + '/browse/\1)')
end

def githubify_id

if Changelog.github?
owner = Changelog.github_owner
project = Changelog.github_project

"[#{id_abbrev}](https://github.com/#{owner}/#{project}/#{id_abbrev})"
"[#{id_abbrev}](#{Changelog.github_base}/#{id_abbrev})"
else
"#{id_abbrev}"
end
Expand Down
25 changes: 19 additions & 6 deletions lib/changelog/release.rb
@@ -1,26 +1,39 @@
module Changelog
class Release

attr_accessor :tag

def initialize(tag)
@tag = tag
raise "Tag not found" unless tag_index || is_head?
end

def tags
@tags ||= Changelog.repo.tags.map {|t| t.name}
end

def tag_index
@tag_index ||= tags.index(tag)
end

def is_head?
tag == 'HEAD'
end

def previous_tag
@previous_tag ||= _previous_tag
@previous_tag ||= (previous_tag_index >= 0 ? tags[previous_tag_index] : nil)
end

def _previous_tag
tags = Changelog.repo.tags.map {|tag| tag.name}
tag_index = tags.index(@tag)
tag_index == 0 ? nil : tags[tag_index -1]
def previous_tag_index
@previous_tag_index ||= (is_head? ? tags.size - 1 : tag_index - 1)
end

def listings
@listings ||= _listings
end

def _listings
ref = (previous_tag ? "#{previous_tag}..#{@tag}" : @tag)
ref = (previous_tag ? "#{previous_tag}..#{tag}" : tag)

Changelog.repo.commits(ref).map { |commit|
Listing.create(Changelog.repo, :id => commit.id)
Expand Down
13 changes: 12 additions & 1 deletion spec/release_spec.rb
Expand Up @@ -3,6 +3,11 @@
module Changelog
describe Release do

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

describe "#previous_tag" do

Expand All @@ -15,10 +20,16 @@ module Changelog
rls = Release.new('CL.0.1.20120120.0')
rls.previous_tag.should be_nil
end

it "returns the last tag before HEAD" do
rls = Release.new('HEAD')
rls.previous_tag.should == 'CL.0.1.20120120.1'
end

end

describe "#listings" do

it "returns the release's commit listings" do
rls = Release.new('CL.0.1.20120120.1')
rls.listings.size.should == 3
Expand Down

0 comments on commit 70a57d2

Please sign in to comment.