github_changelog_generator 1.15.0.pre.alpha → 1.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE +1 -1
  3. data/README.md +332 -275
  4. data/Rakefile +3 -4
  5. data/bin/git-generate-changelog +1 -1
  6. data/lib/github_changelog_generator.rb +10 -6
  7. data/lib/github_changelog_generator/generator/entry.rb +218 -0
  8. data/lib/github_changelog_generator/generator/generator.rb +126 -104
  9. data/lib/github_changelog_generator/generator/generator_fetcher.rb +139 -23
  10. data/lib/github_changelog_generator/generator/generator_processor.rb +59 -27
  11. data/lib/github_changelog_generator/generator/generator_tags.rb +26 -22
  12. data/lib/github_changelog_generator/generator/section.rb +124 -0
  13. data/lib/github_changelog_generator/helper.rb +1 -1
  14. data/lib/github_changelog_generator/octo_fetcher.rb +261 -130
  15. data/lib/github_changelog_generator/options.rb +74 -1
  16. data/lib/github_changelog_generator/parser.rb +120 -176
  17. data/lib/github_changelog_generator/parser_file.rb +8 -3
  18. data/lib/github_changelog_generator/reader.rb +2 -2
  19. data/lib/github_changelog_generator/task.rb +5 -6
  20. data/lib/github_changelog_generator/version.rb +1 -1
  21. data/man/git-generate-changelog.1 +144 -45
  22. data/man/git-generate-changelog.1.html +157 -84
  23. data/man/git-generate-changelog.html +19 -7
  24. data/man/git-generate-changelog.md +151 -84
  25. data/spec/files/github-changelog-generator.md +114 -114
  26. data/spec/{install-gem-in-bundler.gemfile → install_gem_in_bundler.gemfile} +2 -0
  27. data/spec/spec_helper.rb +2 -6
  28. data/spec/unit/generator/entry_spec.rb +766 -0
  29. data/spec/unit/generator/generator_processor_spec.rb +103 -41
  30. data/spec/unit/generator/generator_spec.rb +47 -0
  31. data/spec/unit/generator/generator_tags_spec.rb +56 -24
  32. data/spec/unit/generator/section_spec.rb +34 -0
  33. data/spec/unit/octo_fetcher_spec.rb +247 -197
  34. data/spec/unit/options_spec.rb +28 -4
  35. data/spec/unit/parse_file_spec.rb +2 -2
  36. data/spec/unit/parser_spec.rb +0 -79
  37. data/spec/unit/reader_spec.rb +4 -4
  38. data/spec/vcr/GitHubChangelogGenerator_OctoFetcher/_commits/when_API_is_valid/returns_commits.json +1 -0
  39. data/spec/vcr/GitHubChangelogGenerator_OctoFetcher/_commits_before/when_API_is_valid/returns_commits.json +1 -1
  40. data/spec/vcr/GitHubChangelogGenerator_OctoFetcher/_fetch_closed_issues_and_pr/when_API_call_is_valid.json +1 -1
  41. data/spec/vcr/GitHubChangelogGenerator_OctoFetcher/_fetch_closed_issues_and_pr/when_API_call_is_valid/returns_issue_with_proper_key/values.json +1 -1
  42. data/spec/vcr/GitHubChangelogGenerator_OctoFetcher/_fetch_closed_issues_and_pr/when_API_call_is_valid/returns_issues.json +1 -1
  43. data/spec/vcr/GitHubChangelogGenerator_OctoFetcher/_fetch_closed_issues_and_pr/when_API_call_is_valid/returns_issues_with_labels.json +1 -1
  44. data/spec/vcr/GitHubChangelogGenerator_OctoFetcher/_fetch_closed_issues_and_pr/when_API_call_is_valid/returns_pull_request_with_proper_key/values.json +1 -1
  45. data/spec/vcr/GitHubChangelogGenerator_OctoFetcher/_fetch_closed_issues_and_pr/when_API_call_is_valid/returns_pull_requests_with_labels.json +1 -1
  46. data/spec/vcr/GitHubChangelogGenerator_OctoFetcher/_fetch_closed_pull_requests/when_API_call_is_valid.json +1 -1
  47. data/spec/vcr/GitHubChangelogGenerator_OctoFetcher/_fetch_closed_pull_requests/when_API_call_is_valid/returns_correct_pull_request_keys.json +1 -1
  48. data/spec/vcr/GitHubChangelogGenerator_OctoFetcher/_fetch_closed_pull_requests/when_API_call_is_valid/returns_pull_requests.json +1 -1
  49. data/spec/vcr/GitHubChangelogGenerator_OctoFetcher/_fetch_commit/when_API_call_is_valid.json +1 -1
  50. data/spec/vcr/GitHubChangelogGenerator_OctoFetcher/_fetch_commit/when_API_call_is_valid/returns_commit.json +1 -1
  51. data/spec/vcr/GitHubChangelogGenerator_OctoFetcher/_fetch_date_of_tag/when_API_call_is_valid.json +1 -1
  52. data/spec/vcr/GitHubChangelogGenerator_OctoFetcher/_fetch_date_of_tag/when_API_call_is_valid/returns_date.json +1 -1
  53. data/spec/vcr/GitHubChangelogGenerator_OctoFetcher/_fetch_events_async/when_API_call_is_valid.json +1 -1
  54. data/spec/vcr/GitHubChangelogGenerator_OctoFetcher/_fetch_events_async/when_API_call_is_valid/populates_issues.json +1 -1
  55. data/spec/vcr/GitHubChangelogGenerator_OctoFetcher/_github_fetch_tags/when_API_call_is_valid.json +1 -1
  56. data/spec/vcr/GitHubChangelogGenerator_OctoFetcher/_github_fetch_tags/when_API_call_is_valid/should_return_tags.json +1 -1
  57. data/spec/vcr/GitHubChangelogGenerator_OctoFetcher/_github_fetch_tags/when_API_call_is_valid/should_return_tags_count.json +1 -1
  58. data/spec/vcr/GitHubChangelogGenerator_OctoFetcher/_github_fetch_tags/when_wrong_token_provided.json +1 -1
  59. data/spec/vcr/GitHubChangelogGenerator_OctoFetcher/_github_fetch_tags/when_wrong_token_provided/should_raise_Unauthorized_error.json +1 -1
  60. metadata +71 -38
  61. data/bin/ghclgen +0 -5
  62. data/lib/github_changelog_generator/generator/generator_generation.rb +0 -180
  63. data/spec/unit/generator/generator_generation_spec.rb +0 -17
data/bin/ghclgen DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env ruby -U
2
- # frozen_string_literal: true
3
-
4
- require "github_changelog_generator"
5
- GitHubChangelogGenerator::CLI.start(ARGV)
@@ -1,180 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module GitHubChangelogGenerator
4
- class Generator
5
- # Main function to start change log generation
6
- #
7
- # @return [String] Generated change log file
8
- def compound_changelog
9
- fetch_and_filter_tags
10
- fetch_issues_and_pr
11
-
12
- log = ""
13
- log += options[:frontmatter] if options[:frontmatter]
14
- log += "#{options[:header]}\n\n"
15
-
16
- log += if options[:unreleased_only]
17
- generate_log_between_tags(filtered_tags[0], nil)
18
- else
19
- generate_log_for_all_tags
20
- end
21
-
22
- log += File.read(options[:base]) if File.file?(options[:base])
23
-
24
- credit_line = "\n\n\\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*"
25
- log.gsub!(credit_line, "") # Remove old credit lines
26
- log += credit_line
27
-
28
- @log = log
29
- end
30
-
31
- # @param [Array] issues List of issues on sub-section
32
- # @param [String] prefix Name of sub-section
33
- # @return [String] Generate ready-to-go sub-section
34
- def generate_sub_section(issues, prefix)
35
- log = ""
36
-
37
- if issues.any?
38
- log += "#{prefix}\n\n" unless options[:simple_list]
39
- issues.each do |issue|
40
- merge_string = get_string_for_issue(issue)
41
- log += "- #{merge_string}\n"
42
- end
43
- log += "\n"
44
- end
45
- log
46
- end
47
-
48
- # It generate one header for section with specific parameters.
49
- #
50
- # @param [String] newer_tag_name - name of newer tag
51
- # @param [String] newer_tag_link - used for links. Could be same as #newer_tag_name or some specific value, like HEAD
52
- # @param [Time] newer_tag_time - time, when newer tag created
53
- # @param [String] older_tag_link - tag name, used for links.
54
- # @param [String] project_url - url for current project.
55
- # @return [String] - Generate one ready-to-add section.
56
- def generate_header(newer_tag_name, newer_tag_link, newer_tag_time, older_tag_link, project_url)
57
- log = ""
58
-
59
- # Generate date string:
60
- time_string = newer_tag_time.strftime(options[:date_format])
61
-
62
- # Generate tag name and link
63
- release_url = if options[:release_url]
64
- format(options[:release_url], newer_tag_link)
65
- else
66
- "#{project_url}/tree/#{newer_tag_link}"
67
- end
68
- log += if newer_tag_name.equal?(options[:unreleased_label])
69
- "## [#{newer_tag_name}](#{release_url})\n\n"
70
- else
71
- "## [#{newer_tag_name}](#{release_url}) (#{time_string})\n\n"
72
- end
73
-
74
- if options[:compare_link] && older_tag_link
75
- # Generate compare link
76
- log += "[Full Changelog](#{project_url}/compare/#{older_tag_link}...#{newer_tag_link})\n\n"
77
- end
78
-
79
- log
80
- end
81
-
82
- # Generate log only between 2 specified tags
83
- # @param [String] older_tag all issues before this tag date will be excluded. May be nil, if it's first tag
84
- # @param [String] newer_tag all issue after this tag will be excluded. May be nil for unreleased section
85
- def generate_log_between_tags(older_tag, newer_tag)
86
- filtered_issues, filtered_pull_requests = filter_issues_for_tags(newer_tag, older_tag)
87
-
88
- if newer_tag.nil? && filtered_issues.empty? && filtered_pull_requests.empty?
89
- # do not generate empty unreleased section
90
- return ""
91
- end
92
-
93
- create_log_for_tag(filtered_pull_requests, filtered_issues, newer_tag, older_tag)
94
- end
95
-
96
- # Filters issues and pull requests based on, respectively, `closed_at` and `merged_at`
97
- # timestamp fields.
98
- #
99
- # @return [Array] filtered issues and pull requests
100
- def filter_issues_for_tags(newer_tag, older_tag)
101
- filtered_pull_requests = delete_by_time(@pull_requests, "merged_at", older_tag, newer_tag)
102
- filtered_issues = delete_by_time(@issues, "closed_at", older_tag, newer_tag)
103
-
104
- newer_tag_name = newer_tag.nil? ? nil : newer_tag["name"]
105
-
106
- if options[:filter_issues_by_milestone]
107
- # delete excess irrelevant issues (according milestones). Issue #22.
108
- filtered_issues = filter_by_milestone(filtered_issues, newer_tag_name, @issues)
109
- filtered_pull_requests = filter_by_milestone(filtered_pull_requests, newer_tag_name, @pull_requests)
110
- end
111
- [filtered_issues, filtered_pull_requests]
112
- end
113
-
114
- # The full cycle of generation for whole project
115
- # @return [String] The complete change log
116
- def generate_log_for_all_tags
117
- puts "Generating log..." if options[:verbose]
118
-
119
- log = generate_unreleased_section
120
-
121
- @tag_section_mapping.each_pair do |_tag_section, left_right_tags|
122
- older_tag, newer_tag = left_right_tags
123
- log += generate_log_between_tags(older_tag, newer_tag)
124
- end
125
-
126
- log
127
- end
128
-
129
- def generate_unreleased_section
130
- log = ""
131
- if options[:unreleased]
132
- start_tag = filtered_tags[0] || sorted_tags.last
133
- unreleased_log = generate_log_between_tags(start_tag, nil)
134
- log += unreleased_log if unreleased_log
135
- end
136
- log
137
- end
138
-
139
- # Parse issue and generate single line formatted issue line.
140
- #
141
- # Example output:
142
- # - Add coveralls integration [\#223](https://github.com/skywinder/github-changelog-generator/pull/223) (@skywinder)
143
- #
144
- # @param [Hash] issue Fetched issue from GitHub
145
- # @return [String] Markdown-formatted single issue
146
- def get_string_for_issue(issue)
147
- encapsulated_title = encapsulate_string issue["title"]
148
-
149
- title_with_number = "#{encapsulated_title} [\\##{issue['number']}](#{issue['html_url']})"
150
- if options[:issue_line_labels].present?
151
- title_with_number = "#{title_with_number}#{line_labels_for(issue)}"
152
- end
153
- issue_line_with_user(title_with_number, issue)
154
- end
155
-
156
- private
157
-
158
- def line_labels_for(issue)
159
- labels = if options[:issue_line_labels] == ["ALL"]
160
- issue["labels"]
161
- else
162
- issue["labels"].select { |label| options[:issue_line_labels].include?(label["name"]) }
163
- end
164
- labels.map { |label| " \[[#{label['name']}](#{label['url'].sub('api.github.com/repos', 'github.com')})\]" }.join("")
165
- end
166
-
167
- def issue_line_with_user(line, issue)
168
- return line if !options[:author] || issue["pull_request"].nil?
169
-
170
- user = issue["user"]
171
- return "#{line} ({Null user})" unless user
172
-
173
- if options[:usernames_as_github_logins]
174
- "#{line} (@#{user['login']})"
175
- else
176
- "#{line} ([#{user['login']}](#{user['html_url']}))"
177
- end
178
- end
179
- end
180
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module GitHubChangelogGenerator
4
- describe Generator do
5
- describe "#get_string_for_issue" do
6
- let(:issue) do
7
- { "title" => "Bug in code" }
8
- end
9
-
10
- it "formats an issue according to options" do
11
- expect do
12
- described_class.new.get_string_for_issue(issue)
13
- end.not_to raise_error
14
- end
15
- end
16
- end
17
- end