create_changelog 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/bin/ccl +10 -3
  3. data/bin/ccl~ +102 -44
  4. data/features/changelog_only_recent_changes.feature +51 -0
  5. data/features/changelog_only_recent_changes.feature~ +51 -0
  6. data/features/changelog_without_recent_changes.feature +51 -0
  7. data/features/changelog_without_recent_changes.feature~ +50 -0
  8. data/features/commandline.feature~ +21 -0
  9. data/features/complete_changelog.feature +51 -0
  10. data/features/complete_changelog.feature~ +51 -0
  11. data/features/create_changelog.feature~ +19 -0
  12. data/features/decorate_output.feature +30 -0
  13. data/features/decorate_output.feature~ +30 -0
  14. data/features/prepare_release.feature~ +26 -0
  15. data/features/step_definitions/git_steps.rb +61 -0
  16. data/features/step_definitions/git_steps.rb~ +74 -0
  17. data/features/step_definitions/stdout_steps.rb +7 -0
  18. data/features/step_definitions/stdout_steps.rb~ +10 -0
  19. data/features/support/assertions.rb +7 -0
  20. data/features/support/assertions.rb~ +7 -0
  21. data/features/support/env.rb +1 -0
  22. data/features/support/env.rb~ +6 -0
  23. data/lib/array.rb~ +18 -0
  24. data/lib/changelog.rb +5 -1
  25. data/lib/changelog.rb~ +14 -14
  26. data/lib/changelog_filter.rb~ +58 -0
  27. data/lib/commit_changelog.rb~ +9 -1
  28. data/lib/git.rb +66 -0
  29. data/lib/git.rb~ +76 -1
  30. data/lib/tag.rb~ +4 -5
  31. data/lib/tag_list.rb~ +13 -2
  32. data/lib/version.rb +1 -1
  33. data/lib/version.rb~ +1 -1
  34. data/test/test_changelog_filter.rb +21 -0
  35. data/test/test_changelog_filter.rb~ +19 -0
  36. data/test/test_tag_list.rb +12 -0
  37. data/test/test_tag_list.rb~ +12 -0
  38. metadata +74 -7
@@ -0,0 +1,51 @@
1
+ @announce
2
+ Feature: Creating a complete, decorated changelog.
3
+
4
+ Scenario: Repository with identical changelog lines only in commit messages
5
+ Given an empty Git repository
6
+ When 2 commits with standard changelog line are added
7
+ And I successfully run `ccl`
8
+ Then the stdout should contain 1 line starting with "- "
9
+
10
+ Scenario: Repository with multiple changelog lines only in commit messages
11
+ Given an empty Git repository
12
+ When 3 commits with unique changelog line are added
13
+ And I successfully run `ccl`
14
+ Then the stdout should contain 3 lines starting with "- "
15
+
16
+ Scenario: Changelog lines in commit messages and tag without changelog line
17
+ Given an empty Git repository
18
+ When 3 commits with unique changelog line are added
19
+ And a tag without changelog line is added
20
+ And I successfully run `ccl`
21
+ Then the stdout should contain 3 lines starting with "- "
22
+
23
+ Scenario: Changelog lines in commit messages and tag with different changelog line
24
+ Given an empty Git repository
25
+ When 3 commits with unique changelog line are added
26
+ And a tag with unique changelog line is added
27
+ And I successfully run `ccl`
28
+ Then the stdout should contain 4 lines starting with "- "
29
+
30
+ Scenario: Changelog lines in commit messages and tag with same changelog line
31
+ Given an empty Git repository
32
+ When 3 commits with standard changelog line are added
33
+ And a tag with standard changelog line is added
34
+ And I successfully run `ccl`
35
+ Then the stdout should contain 1 line starting with "- "
36
+
37
+ Scenario: Unique changelog lines in commit messages, tag, and recent commits
38
+ Given an empty Git repository
39
+ When 3 commits with unique changelog line are added
40
+ And a tag with unique changelog line is added
41
+ And 2 commits with unique changelog line are added
42
+ And I successfully run `ccl`
43
+ Then the stdout should contain 6 lines starting with "- "
44
+
45
+ Scenario: Same changelog lines in commit messages, tag, and recent commits
46
+ Given an empty Git repository
47
+ When 3 commits with standard changelog line are added
48
+ And a tag with standard changelog line is added
49
+ And 2 commits with standard changelog line are added
50
+ And I successfully run `ccl`
51
+ Then the stdout should contain 2 lines starting with "- "
@@ -0,0 +1,19 @@
1
+ Feature: Creating a complete, decorated changelog
2
+
3
+ Scenario: Repository with identical changelog lines only in commit messages
4
+ Given an empty Git repository
5
+ When 2 commits with identical changelog lines are added
6
+ And I successfully run `ccl`
7
+ Then the stdout should contain 1 line starting with "- "
8
+
9
+ Scenario: Log lines only in commit messages, generate without recent
10
+ Given an empty Git repository
11
+ When 2 commits with identical changelog lines are added
12
+ When I successfully run `ccl --no-recent`
13
+ Then the stdout should not contain anything
14
+
15
+ Scenario: Repository with multiple changelog lines only in commit messages
16
+ Given an empty Git repository
17
+ When 3 commits with unique changelog lines are added
18
+ And I successfully run `ccl`
19
+ Then the stdout should contain 3 line starting with "- "
@@ -0,0 +1,30 @@
1
+ @announce
2
+ Feature: Output may be decorated
3
+
4
+ Scenario: Creating complete changelog
5
+ Given an empty Git repository
6
+ When 2 commits with standard changelog line are added
7
+ And I successfully run `ccl`
8
+ Then the stdout should contain "====="
9
+ And the stdout should contain "* * *"
10
+
11
+ Scenario: Creating changelog without recent changes
12
+ Given an empty Git repository
13
+ When 2 commits with standard changelog line are added
14
+ And I successfully run `ccl --no-recent`
15
+ Then the stdout should not contain anything
16
+
17
+ Scenario: Creating changelog with recent changes only
18
+ Given an empty Git repository
19
+ When 2 commits with standard changelog line are added
20
+ And I successfully run `ccl --recent`
21
+ Then the stdout should not contain "====="
22
+ And the stdout should not contain "* * *"
23
+
24
+ Scenario: Creating changelog with custom 'recent' heading
25
+ Given an empty Git repository
26
+ When 2 commits with standard changelog line are added
27
+ And I successfully run `ccl TEST_VERSION`
28
+ Then the stdout should contain "TEST_VERSION"
29
+ And the stdout should contain "====="
30
+ And the stdout should contain "* * *"
@@ -0,0 +1,30 @@
1
+ @announce
2
+ Feature: Output may be decorated
3
+
4
+ Scenario: Creating complete changelog
5
+ Given an empty Git repository
6
+ When 2 commits with standard changelog line are added
7
+ And I successfully run `ccl`
8
+ Then the stdout should contain "====="
9
+ And the stdout should contain "* * *
10
+
11
+ Scenario: Creating changelog without recent changes
12
+ Given an empty Git repository
13
+ When 2 commits with standard changelog line are added
14
+ And I successfully run `ccl --no-recent`
15
+ Then the stdout should not contain anything
16
+
17
+ Scenario: Creating changelog with recent changes only
18
+ Given an empty Git repository
19
+ When 2 commits with standard changelog line are added
20
+ And I successfully run `ccl --recent`
21
+ Then the stdout should not contain "====="
22
+ And the stdout should not contain "* * *"
23
+
24
+ Scenario: Creating changelog with custom 'recent' heading
25
+ Given an empty Git repository
26
+ When 2 commits with standard changelog line are added
27
+ And I successfully run `ccl TEST_VERSION`
28
+ Then the stdout should contain "TEST_VERSION"
29
+ And the stdout should contain "====="
30
+ And the stdout should contain "* * *"
@@ -0,0 +1,26 @@
1
+ Feature: Prepare-release workflow
2
+
3
+ Scenario: Prepare-release fails if current branch is not release branch
4
+ Given an empty Git repository
5
+ When I run `ccl --prepare-release 1.0.0`
6
+ Then the exit status should not be 0
7
+
8
+ Scenario: Prepare-release requires tag name on the command line
9
+ Given an empty Git repository
10
+ And a new branch "release-1.0.0"
11
+ When I run `ccl --prepare-release`
12
+ Then the exit status should not be 0
13
+ And the stderr should contain "FATAL: Missing argument: TAG"
14
+
15
+ Scenario: Prepare-release aborts if annotation is empty
16
+ Given an empty Git repository
17
+ And a new branch "release-1.0.0"
18
+ When I run `ccl --prepare-release`
19
+ Then the stdout should contain "aborted"
20
+ And the current branch should be "release-1.0.0"
21
+
22
+ Scenario: Prepare-release checks out master branch and tags it
23
+ Given an empty Git repository
24
+ And a new branch "release-1.0.0"
25
+ When I run `ccl --prepare-release 1.0.0`
26
+
@@ -0,0 +1,61 @@
1
+ require 'fileutils'
2
+ require 'securerandom'
3
+
4
+ Given /^an empty Git repository$/ do
5
+ in_current_dir do
6
+ `git init`
7
+ end
8
+ end
9
+
10
+ When(/^(\d+) commits with standard changelog line are added$/) do |n|
11
+ in_current_dir do
12
+ n.to_i.times do
13
+ alter_dummy_file
14
+ `git add -A`
15
+ `git commit -m 'heading' -m '#{standard_log_entry}'`
16
+ end
17
+ end
18
+ end
19
+
20
+ When(/^(\d+) commits with unique changelog line are added$/) do |n|
21
+ in_current_dir do
22
+ n.to_i.times do
23
+ alter_dummy_file
24
+ `git add -A`
25
+ `git commit -m 'heading' -m '#{random_log_entry}'`
26
+ end
27
+ end
28
+ end
29
+
30
+ When(/a tag without changelog line is added/) do
31
+ in_current_dir do
32
+ `git tag -a some-tag -m "Some tag"`
33
+ end
34
+ end
35
+
36
+ When(/a tag with unique changelog line is added/) do
37
+ in_current_dir do
38
+ `git tag -a some-tag -m "Some tag" -m '#{random_log_entry}'`
39
+ end
40
+ end
41
+
42
+ When(/a tag with standard changelog line is added/) do
43
+ in_current_dir do
44
+ `git tag -a some-tag -m "Some tag" -m '#{standard_log_entry}'`
45
+ end
46
+ end
47
+
48
+ def alter_dummy_file
49
+ open 'dummy_file_for_commits.txt', 'a' do |f|
50
+ f.puts 'some text'
51
+ end
52
+ end
53
+
54
+ def standard_log_entry
55
+ "- INFO: This is a standard log entry for testing"
56
+ end
57
+
58
+ def random_log_entry
59
+ # ('a'..'z').to_a.shuffle[0,8].join
60
+ "- INFO: This is a unique log entry for testing - #{SecureRandom.hex}"
61
+ end
@@ -0,0 +1,74 @@
1
+ require 'fileutils'
2
+ require 'securerandom'
3
+ require '../lib/git.rb'
4
+
5
+ Given(/^an empty Git repository$/) do
6
+ in_current_dir do
7
+ `git init`
8
+ end
9
+ end
10
+
11
+ When(/^(\d+) commits with standard changelog line are added$/) do |n|
12
+ in_current_dir do
13
+ n.to_i.times do
14
+ alter_dummy_file
15
+ `git add -A`
16
+ `git commit -m 'heading' -m '#{standard_log_entry}'`
17
+ end
18
+ end
19
+ end
20
+
21
+ When(/^(\d+) commits with unique changelog line are added$/) do |n|
22
+ in_current_dir do
23
+ n.to_i.times do
24
+ alter_dummy_file
25
+ `git add -A`
26
+ `git commit -m 'heading' -m '#{random_log_entry}'`
27
+ end
28
+ end
29
+ end
30
+
31
+ When(/a tag without changelog line is added/) do
32
+ in_current_dir do
33
+ `git tag -a some-tag -m "Some tag"`
34
+ end
35
+ end
36
+
37
+ When(/a tag with unique changelog line is added/) do
38
+ in_current_dir do
39
+ `git tag -a some-tag -m "Some tag" -m '#{random_log_entry}'`
40
+ end
41
+ end
42
+
43
+ When(/a tag with standard changelog line is added/) do
44
+ in_current_dir do
45
+ `git tag -a some-tag -m "Some tag" -m '#{standard_log_entry}'`
46
+ end
47
+ end
48
+
49
+ Given(/a new branch "([^"]+)"/) do |branch|
50
+ in_current_dir do
51
+ Git.new_branch branch
52
+ end
53
+ end
54
+
55
+ Then(/the current branch should be "([^"]+)"/) do |branch|
56
+ in_current_dir do
57
+ Git.current_branch == branch
58
+ end
59
+ end
60
+
61
+ def alter_dummy_file
62
+ open 'dummy_file_for_commits.txt', 'a' do |f|
63
+ f.puts 'some text'
64
+ end
65
+ end
66
+
67
+ def standard_log_entry
68
+ "- INFO: This is a standard log entry for testing"
69
+ end
70
+
71
+ def random_log_entry
72
+ # ('a'..'z').to_a.shuffle[0,8].join
73
+ "- INFO: This is a unique log entry for testing - #{SecureRandom.hex}"
74
+ end
@@ -0,0 +1,7 @@
1
+ Then(/^the stdout should contain 1 line starting with "([^"]*)"$/) do |s|
2
+ assert_lines_starting_with all_stdout, 1, s
3
+ end
4
+
5
+ Then(/^the stdout should contain (\d+) lines starting with "([^"]*)"$/) do |n, s|
6
+ assert_lines_starting_with all_stdout, n, s
7
+ end
@@ -0,0 +1,10 @@
1
+ Then(/^the stdout should contain 1 line starting with "([^"]*)"$/) do |s|
2
+ expected = "(^#{s}.*\n){1}"
3
+ assert_matching_output(expected, all_output)
4
+ end
5
+
6
+ Then(/^the stdout should contain (\d+) lines starting with "([^"]*)"$/) do |n, s|
7
+ # expected = "(^#{s}.*\n){#{n}}"
8
+ # assert_matching_output(expected, all_output)
9
+ assert_lines_starting_with all_stdout, n, s
10
+ end
@@ -0,0 +1,7 @@
1
+ # Checks whether a mult-line text contains a specific number
2
+ # of lines that start with a given sequence.
3
+ def assert_lines_starting_with(text, number, start_with)
4
+ number = number.to_i if number.is_a? String
5
+ count = text.split("\n").count { |line| line.start_with? start_with }
6
+ expect(count).to eq number
7
+ end
@@ -0,0 +1,7 @@
1
+ # Checks whether a mult-line text contains a specific number
2
+ # of lines that start with a given sequence.
3
+ def assert_lines_starting_with(text, number, start_with)
4
+ number = number.to_i if number.is_a(String)
5
+ count = text.split("\n").count { |line| line.start_with? start_with }
6
+ expect(count).to eq number
7
+ end
@@ -0,0 +1 @@
1
+ require 'aruba/cucumber'
@@ -0,0 +1,6 @@
1
+ require 'aruba/cucumber'
2
+
3
+ Before do
4
+ set_env 'GIT_WORK_TREE', File.expand_path(current_dir)
5
+ set_env 'GIT_DIR', ".git"
6
+ end
data/lib/array.rb~ ADDED
@@ -0,0 +1,18 @@
1
+ # Removes common indentation from an array of strings
2
+ class Array
3
+ def remove_indent
4
+ lines_with_indent = self.select do |line|
5
+ line.size > 0
6
+ end
7
+ indents = lines_with_indent.map do |line|
8
+ match = line.match(/^( +)([^ ]|$)+/)
9
+ match ? match[1].size : 0
10
+ end
11
+ indent = indents.min
12
+ self.map do |line|
13
+ line[indent..-1]
14
+ end
15
+ end
16
+ end
17
+
18
+ # vim: nospell
data/lib/changelog.rb CHANGED
@@ -93,7 +93,11 @@ class Changelog
93
93
 
94
94
  # Combine changelog entries from tag annotation and commit messages
95
95
  if tag.changelog
96
- combined_changelog = tag.changelog.concat(commit_changelog.changelog)
96
+ if commit_changelog.changelog
97
+ combined_changelog = tag.changelog.concat(commit_changelog.changelog)
98
+ else
99
+ combined_changelog = tag.changelog
100
+ end
97
101
  else
98
102
  combined_changelog = commit_changelog.changelog
99
103
  end
data/lib/changelog.rb~ CHANGED
@@ -30,12 +30,12 @@ class Changelog
30
30
  # Generates a decorated changelog for the entire commit history.
31
31
  #
32
32
  # @param [bool] exclude_recent
33
- # Indicates whether to exclude recent changelog lines that were
34
- # added since the last tag.
33
+ # Indicates whether to exclude recent changelog lines that were
34
+ # added since the last tag.
35
35
  #
36
36
  # @return [String]
37
- # Decorated changelog, or nil if no lines were found.
38
- #
37
+ # Decorated changelog, or nil if no lines were found.
38
+ #
39
39
  def generate(exclude_recent = false)
40
40
  # Traverse tags
41
41
  @@tags = TagList.new(!exclude_recent)
@@ -50,8 +50,8 @@ class Changelog
50
50
  # since the most recent tag.
51
51
  #
52
52
  # @return [Array]
53
- # Array of changelog lines, or nil if no lines were found.
54
- #
53
+ # Array of changelog lines, or nil if no lines were found.
54
+ #
55
55
  def generate_recent
56
56
  @@tags = TagList.new
57
57
  log = CommitChangelog.new(@@tags.list[0], @@tags.list[1])
@@ -73,17 +73,17 @@ class Changelog
73
73
  # repository.
74
74
  #
75
75
  # @param [String] current_tag
76
- # Version tag for which to collect changelog information.
77
- #
76
+ # Version tag for which to collect changelog information.
77
+ #
78
78
  # @param [String] previous_tag
79
- # Previous version tag whose changelog information does not belong to
80
- # the current version's changelog information. However, if previous_tag
81
- # is the Sha-1 hash of the initial commit, its changelog lines _will_ be
82
- # included.
79
+ # Previous version tag whose changelog information does not belong to
80
+ # the current version's changelog information. However, if previous_tag
81
+ # is the Sha-1 hash of the initial commit, its changelog lines _will_ be
82
+ # included.
83
83
  #
84
84
  # @return [String]
85
- # Changelog decorated with markdown formatting, or empty string.
86
- #
85
+ # Changelog decorated with markdown formatting, or empty string.
86
+ #
87
87
  def generate_for(current_tag, previous_tag)
88
88
  tag = Tag.new(current_tag)
89
89
  commit_changelog = CommitChangelog.new(current_tag, previous_tag)
@@ -0,0 +1,58 @@
1
+ # changelog_filter.rb, part of Create-changelog
2
+ # Copyright 2015 Daniel Kraus
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require_relative 'array'
16
+
17
+ # Filters a text or array for changelog entries.
18
+ class ChangelogFilter
19
+ # Factory method that creates an instance given a text string
20
+ def self.FromString(string)
21
+ unless string.is_a?(String)
22
+ fail "Must call this factory with String, not " + string.class.to_s
23
+ end
24
+ self.FromArray(string.chomp.split("\n"))
25
+ end
26
+
27
+ # Factory method that creates an instance given an array of strings
28
+ def self.FromArray(ary)
29
+ unless ary.is_a?(Array)
30
+ fail "Must call this factory with Array, not " + ary.class.to_s
31
+ end
32
+ filter = ChangelogFilter.new
33
+ log, text = ary.partition do |line|
34
+ line.match(pattern)
35
+ end
36
+ filter.changelog = log.uniq.sort.remove_indent if log.length > 0
37
+ filter.other_text = text if text.length > 0
38
+ filter
39
+ end
40
+
41
+ # Returns the grep string that matches changelog entries.
42
+ def self.pattern
43
+ '\s*[*-]\s+[^:]+:\s'
44
+ end
45
+
46
+ # An array of changelog entries.
47
+ attr_accessor :changelog
48
+
49
+ # An array of text lines that are not changelog entries.
50
+ attr_accessor :other_text
51
+
52
+ private
53
+
54
+ def initialize
55
+ end
56
+ end
57
+
58
+ # vim: nospell