github_changelog_generator 1.15.0 → 1.16.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +32 -54
  3. data/Rakefile +1 -1
  4. data/lib/github_changelog_generator/argv_parser.rb +225 -0
  5. data/lib/github_changelog_generator/generator/entry.rb +10 -10
  6. data/lib/github_changelog_generator/generator/generator.rb +41 -19
  7. data/lib/github_changelog_generator/generator/generator_fetcher.rb +5 -9
  8. data/lib/github_changelog_generator/generator/generator_processor.rb +23 -20
  9. data/lib/github_changelog_generator/generator/generator_tags.rb +15 -9
  10. data/lib/github_changelog_generator/generator/section.rb +27 -7
  11. data/lib/github_changelog_generator/helper.rb +1 -1
  12. data/lib/github_changelog_generator/octo_fetcher.rb +190 -126
  13. data/lib/github_changelog_generator/options.rb +4 -0
  14. data/lib/github_changelog_generator/parser.rb +70 -248
  15. data/lib/github_changelog_generator/parser_file.rb +29 -14
  16. data/lib/github_changelog_generator/reader.rb +2 -2
  17. data/lib/github_changelog_generator/ssl_certs/cacert.pem +851 -1680
  18. data/lib/github_changelog_generator/task.rb +3 -2
  19. data/lib/github_changelog_generator/version.rb +1 -1
  20. data/man/git-generate-changelog.1 +46 -34
  21. data/man/git-generate-changelog.1.html +39 -31
  22. data/man/git-generate-changelog.html +19 -19
  23. data/man/git-generate-changelog.md +39 -31
  24. data/spec/files/config_example +5 -0
  25. data/spec/spec_helper.rb +1 -1
  26. data/spec/unit/generator/entry_spec.rb +37 -31
  27. data/spec/unit/generator/generator_processor_spec.rb +99 -44
  28. data/spec/unit/generator/generator_spec.rb +47 -0
  29. data/spec/unit/generator/generator_tags_spec.rb +46 -3
  30. data/spec/unit/generator/section_spec.rb +34 -0
  31. data/spec/unit/octo_fetcher_spec.rb +45 -2
  32. data/spec/unit/parser_spec.rb +50 -0
  33. metadata +45 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ee18824228b1ec5cade4842046046452afa0c4a0cab01ee3c52f86b60206cfb
4
- data.tar.gz: 2c6df785e4d34d416255d1949e58a3a2668453e1a8246ae706989ddf17442bd7
3
+ metadata.gz: 8c1d6d65e8dbae7462cb4af0ef5dcef7ccd69fa0d77cb4d36b2e1e340f955e0e
4
+ data.tar.gz: 44f3e31077975a41154b8843253eb2dd56a1f37e6b8536fde56e825496568b7b
5
5
  SHA512:
6
- metadata.gz: cd20b1b8916d83db50428dbe899c346d1a2b2ca1b26427fdc9997b2edf7604db530b9372c4461f443f4e7f0fc0133c6bd01b8643b1ec066cd1c80c4d0657ca3e
7
- data.tar.gz: 41169d141f512dbecc520251f50fb9db63d4df6160621c5b8598dabf31095d9b75ae7b3aeab1bc126ac9fc5e5a71131026235bce4acb8661ed29744e6a246fa0
6
+ metadata.gz: 9dfcc5e4330a6bf05c098e0d5187259cb0993d7eb3d7c680a0bd12d70fa0ee5f00a2a334866460f5d011b19f6e4086109b8670590b8223885297fb0711beb102
7
+ data.tar.gz: c77fd119b4bd3d854f9873bd726076460253eecc66bfc20d35f127053f5a8c448568c4bdec9b69f0e80992b7b2eb9032483dc4ccf8b4e428fad3bb1aaadcaa69
data/README.md CHANGED
@@ -5,11 +5,6 @@
5
5
 
6
6
  # github-changelog-generator ![GitHub Logo](../master/images/logo.jpg)
7
7
 
8
- #### Update:
9
-
10
- 🖖 Keep it alive: We need more Collaborators to github-changelog-generator [#727](https://github.com/github-changelog-generator/github-changelog-generator/issues/727)
11
-
12
- ---
13
8
  <!--
14
9
  To update TOC, please run:
15
10
  > doctoc ./README.md --github
@@ -44,7 +39,7 @@ To update TOC, please run:
44
39
 
45
40
  ### Changelog generation has never been so easy
46
41
 
47
- **Fully automated changelog generation** - This gem generates a changelog file based on **tags**, **issues** and merged **pull requests** (and splits them into separate lists according to labels) from :octocat: GitHub Issue Tracker.
42
+ **Fully automated changelog generation** - This gem generates a changelog file based on **tags**, **issues** and merged **pull requests** (and splits them into separate lists according to labels) from :octocat: GitHub.
48
43
 
49
44
  Since you don't have to fill your `CHANGELOG.md` manually now: just run the script, relax and take a cup of :coffee: before your next release! :tada:
50
45
 
@@ -72,15 +67,35 @@ Install the gem like:
72
67
  Depending on your system, you _may_ need to run the shell as an Administrator (Windows),
73
68
  or use `sudo gem install github_changelog_generator` (Linux).
74
69
 
75
- ## Running with Docker
76
70
 
77
- Using [Docker](https://www.docker.com/products/docker-desktop) is an alternative to installing Ruby and the gem.
71
+ ## Usage
72
+
73
+
74
+ ### Running with CLI:
78
75
 
79
- `ferrarimarco` has made a Docker image available that you can use.
76
+ github_changelog_generator -u github_project_namespace -p github_project
77
+
78
+ (where the project namespace is _likely_ your username if it's a project you own, but it could also be the namespace of the project)
79
+
80
+
81
+ ### Running with Docker
82
+
83
+ Using [Docker](https://www.docker.com/products/docker-desktop) is an alternative to installing Ruby and the gem.
80
84
 
81
85
  Example invocation:
82
86
 
83
- $ docker run -it --rm -v "$(pwd)":/usr/local/src/your-app ferrarimarco/github-changelog-generator
87
+ $ docker run -it --rm -v "$(pwd)":/usr/local/src/your-app githubchangeloggenerator/github-changelog-generator
88
+
89
+
90
+
91
+ - For GitHub Enterprise repos, specify *both* `--github-site` and `--github-api` options:
92
+
93
+ $ github_changelog_generator --github-site="https://github.yoursite.com" \
94
+ --github-api="https://github.yoursite.com/api/v3/"
95
+
96
+
97
+ This generates a `CHANGELOG.md`, with pretty Markdown formatting.
98
+
84
99
 
85
100
  ## Output example
86
101
 
@@ -109,25 +124,6 @@ Example invocation:
109
124
  >
110
125
  > - support enterprise github via command line options [\#42](https://github.com/github-changelog-generator/Github-Changelog-Generator/pull/42) ([glenlovett](https://github.com/glenlovett))
111
126
 
112
-
113
- ## Usage
114
-
115
- - Run this:
116
-
117
- $ github_changelog_generator -u github_username -p github_project
118
-
119
- or, on the 1.14.x (current stable release)
120
-
121
- $ github_changelog_generator github_username/github_project
122
-
123
-
124
- - For Github Enterprise repos, specify *both* `--github-site` and `--github-api` options:
125
-
126
- $ github_changelog_generator --github-site="https://github.yoursite.com" \
127
- --github-api="https://github.yoursite.com/api/v3/"
128
-
129
- This generates a `CHANGELOG.md`, with pretty Markdown formatting.
130
-
131
127
  ### Params
132
128
 
133
129
  Print help for all command-line options to learn more details:
@@ -150,7 +146,7 @@ since-tag=1.0.0
150
146
 
151
147
  ### GitHub token
152
148
 
153
- GitHub only allows 50 unauthenticated requests per hour.
149
+ GitHub only allows **50 unauthenticated requests per hour**.
154
150
 
155
151
  Therefore, it's recommended to run this script with authentication by using a **token**.
156
152
 
@@ -161,7 +157,7 @@ Here's how:
161
157
  - Run the script with `--token <your-40-digit-token>`; **OR**
162
158
  - Set the `CHANGELOG_GITHUB_TOKEN` environment variable to your 40 digit token
163
159
 
164
- You can set an environment variable by running the following command at the prompt, or by adding it to your shell profile (e.g., `~/.bash_profile` or `~/.zshrc`):
160
+ You can set an environment variable by running the following command at the prompt, or by adding it to your shell profile (e.g., `.env`, `~/.bash_profile`, `~/.zshrc`, etc):
165
161
 
166
162
  export CHANGELOG_GITHUB_TOKEN="«your-40-digit-github-token»"
167
163
 
@@ -290,27 +286,6 @@ I'm not trying to compare the quality of handwritten and auto-generated logs. Th
290
286
 
291
287
  An auto-generated changelog really helps, even if you manually fill in the release notes!
292
288
 
293
- For example:
294
-
295
- When you find a closed bug, it is very useful to know which release fixed it.
296
- So that you can easily find the issue by \# in `CHANGELOG.md`.
297
-
298
- - It's not quite as easy to find this in handwritten releases notes.
299
- - A generated file saves you the trouble of remembering everything;
300
- sometimes people forget to add things to a handwritten file.
301
-
302
- Ultimately, I think GitHub Releases are ideal for end-users.
303
- Meanwhile, `CHANGELOG.md` lives right in the repository, with its detailed list of changes, which is handy for developers.
304
- Finally, there's nothing wrong with using GitHub Releases alongside `CHANGELOG.md` in this combination.
305
-
306
- - ***I got an "API rate limit exceeded" error message. What does this mean?***
307
-
308
- GitHub [limits the number of API requests](https://developer.github.com/v3/#rate-limiting) you can make in an hour. You can make up to 5,000 requests per hour. For unauthenticated requests, the rate limit is only up to 60 requests per hour. Unauthenticated requests are associated with your IP address (not the user making requests).
309
-
310
- If you're seeing this warning, please do the following:
311
-
312
- 1. Make sure you're providing an OAuth token, so you're not making requests anonymously. Using an OAuth token increases your hourly request maximum from 60 to 5000.
313
- 2. If you have a large repo with lots of issues/PRs, you can use `--max-issues NUM` to limit the number of issues that are pulled back. For example: `--max-issues 1000`
314
289
 
315
290
  - ***My Ruby version is very old, can I use this?***
316
291
 
@@ -345,10 +320,13 @@ Workaround: Create a `C:\tmp`.
345
320
 
346
321
  ## Contributing
347
322
 
348
- We have collected notes on how to contribute to this project in [CONTRIBUTING.md].
323
+ Would you like to contribute to this project? [CONTRIBUTING.md] has all the details on how to do that.
349
324
 
350
325
  [CONTRIBUTING.md]: CONTRIBUTING.md
351
326
 
327
+ ## Contact us
328
+ [Join the chat at gitter : github-changelog-generator](https://gitter.im/github-changelog-generator/chat?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
329
+
352
330
  ## License
353
331
 
354
- Github Changelog Generator is released under the [MIT License](http://www.opensource.org/licenses/MIT).
332
+ GitHub Changelog Generator is released under the [MIT License](http://www.opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ RSpec::Core::RakeTask.new
13
13
 
14
14
  desc "When releasing the gem, re-fetch latest cacert.pem from curl.haxx.se. Developer task."
15
15
  task :update_ssl_ca_file do
16
- `pushd lib/github_changelog_generator/ssl_certs && curl --remote-name --time-cond cacert.pem https://curl.haxx.se/ca/cacert.pem && popd`
16
+ `pushd lib/github_changelog_generator/ssl_certs && curl --remote-name --time-cond cacert.pem https://curl.se/ca/cacert.pem && popd`
17
17
  end
18
18
 
19
19
  task default: %i[rubocop spec]
@@ -0,0 +1,225 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "optparse"
4
+ require "github_changelog_generator/version"
5
+
6
+ module GitHubChangelogGenerator
7
+ class ArgvParser
8
+ attr_reader :options
9
+
10
+ def initialize(options = {})
11
+ @options = options
12
+ end
13
+
14
+ def parse!(argv)
15
+ parser.parse(argv)
16
+ rescue OptionParser::ParseError => e
17
+ warn [e, parser].join("\n")
18
+ Kernel.abort
19
+ end
20
+
21
+ def parser
22
+ @parser ||= OptionParser.new do |opts| # rubocop:disable Metrics/BlockLength
23
+ opts.banner = "Usage: github_changelog_generator --user USER --project PROJECT [options]"
24
+ opts.on("-u", "--user USER", "Username of the owner of the target GitHub repo OR the namespace of target Github repo if owned by an organization.") do |last|
25
+ options[:user] = last
26
+ end
27
+ opts.on("-p", "--project PROJECT", "Name of project on GitHub.") do |last|
28
+ options[:project] = last
29
+ end
30
+ opts.on("-t", "--token TOKEN", "To make more than 50 requests per hour your GitHub token is required. You can generate it at: https://github.com/settings/tokens/new") do |last|
31
+ options[:token] = last
32
+ end
33
+ opts.on("-f", "--date-format FORMAT", "Date format. Default is %Y-%m-%d.") do |last|
34
+ options[:date_format] = last
35
+ end
36
+ opts.on("-o", "--output NAME", "Output file. To print to STDOUT instead, use blank as path. Default is CHANGELOG.md") do |last|
37
+ options[:output] = last
38
+ end
39
+ opts.on("-b", "--base NAME", "Optional base file to append generated changes to. Default is HISTORY.md") do |last|
40
+ options[:base] = last
41
+ end
42
+ opts.on("--summary-label LABEL", "Set up custom label for the release summary section. Default is \"\".") do |v|
43
+ options[:summary_prefix] = v
44
+ end
45
+ opts.on("--breaking-label LABEL", "Set up custom label for the breaking changes section. Default is \"**Breaking changes:**\".") do |v|
46
+ options[:breaking_prefix] = v
47
+ end
48
+ opts.on("--enhancement-label LABEL", "Set up custom label for enhancements section. Default is \"**Implemented enhancements:**\".") do |v|
49
+ options[:enhancement_prefix] = v
50
+ end
51
+ opts.on("--bugs-label LABEL", "Set up custom label for bug-fixes section. Default is \"**Fixed bugs:**\".") do |v|
52
+ options[:bug_prefix] = v
53
+ end
54
+ opts.on("--deprecated-label LABEL", "Set up custom label for the deprecated changes section. Default is \"**Deprecated:**\".") do |v|
55
+ options[:deprecated_prefix] = v
56
+ end
57
+ opts.on("--removed-label LABEL", "Set up custom label for the removed changes section. Default is \"**Removed:**\".") do |v|
58
+ options[:removed_prefix] = v
59
+ end
60
+ opts.on("--security-label LABEL", "Set up custom label for the security changes section. Default is \"**Security fixes:**\".") do |v|
61
+ options[:security_prefix] = v
62
+ end
63
+ opts.on("--issues-label LABEL", "Set up custom label for closed-issues section. Default is \"**Closed issues:**\".") do |v|
64
+ options[:issue_prefix] = v
65
+ end
66
+ opts.on("--header-label LABEL", "Set up custom header label. Default is \"# Changelog\".") do |v|
67
+ options[:header] = v
68
+ end
69
+ opts.on("--configure-sections HASH, STRING", "Define your own set of sections which overrides all default sections.") do |v|
70
+ options[:configure_sections] = v
71
+ end
72
+ opts.on("--add-sections HASH, STRING", "Add new sections but keep the default sections.") do |v|
73
+ options[:add_sections] = v
74
+ end
75
+ opts.on("--front-matter JSON", "Add YAML front matter. Formatted as JSON because it's easier to add on the command line.") do |v|
76
+ require "yaml"
77
+ options[:frontmatter] = "#{JSON.parse(v).to_yaml}---\n"
78
+ end
79
+ opts.on("--pr-label LABEL", "Set up custom label for pull requests section. Default is \"**Merged pull requests:**\".") do |v|
80
+ options[:merge_prefix] = v
81
+ end
82
+ opts.on("--[no-]issues", "Include closed issues in changelog. Default is true.") do |v|
83
+ options[:issues] = v
84
+ end
85
+ opts.on("--[no-]issues-wo-labels", "Include closed issues without labels in changelog. Default is true.") do |v|
86
+ options[:add_issues_wo_labels] = v
87
+ end
88
+ opts.on("--[no-]pr-wo-labels", "Include pull requests without labels in changelog. Default is true.") do |v|
89
+ options[:add_pr_wo_labels] = v
90
+ end
91
+ opts.on("--[no-]pull-requests", "Include pull-requests in changelog. Default is true.") do |v|
92
+ options[:pulls] = v
93
+ end
94
+ opts.on("--[no-]filter-by-milestone", "Use milestone to detect when issue was resolved. Default is true.") do |last|
95
+ options[:filter_issues_by_milestone] = last
96
+ end
97
+ opts.on("--[no-]issues-of-open-milestones", "Include issues of open milestones. Default is true.") do |v|
98
+ options[:issues_of_open_milestones] = v
99
+ end
100
+ opts.on("--[no-]author", "Add author of pull request at the end. Default is true.") do |author|
101
+ options[:author] = author
102
+ end
103
+ opts.on("--usernames-as-github-logins", "Use GitHub tags instead of Markdown links for the author of an issue or pull-request.") do |v|
104
+ options[:usernames_as_github_logins] = v
105
+ end
106
+ opts.on("--unreleased-only", "Generate log from unreleased closed issues only.") do |v|
107
+ options[:unreleased_only] = v
108
+ end
109
+ opts.on("--[no-]unreleased", "Add to log unreleased closed issues. Default is true.") do |v|
110
+ options[:unreleased] = v
111
+ end
112
+ opts.on("--unreleased-label LABEL", "Set up custom label for unreleased closed issues section. Default is \"**Unreleased:**\".") do |v|
113
+ options[:unreleased_label] = v
114
+ end
115
+ opts.on("--[no-]compare-link", "Include compare link (Full Changelog) between older version and newer version. Default is true.") do |v|
116
+ options[:compare_link] = v
117
+ end
118
+ opts.on("--include-labels x,y,z", Array, "Of the labeled issues, only include the ones with the specified labels.") do |list|
119
+ options[:include_labels] = list
120
+ end
121
+ opts.on("--exclude-labels x,y,z", Array, "Issues with the specified labels will be excluded from changelog. Default is 'duplicate,question,invalid,wontfix'.") do |list|
122
+ options[:exclude_labels] = list
123
+ end
124
+ opts.on("--summary-labels x,y,z", Array, 'Issues with these labels will be added to a new section, called "Release Summary". The section display only body of issues. Default is \'release-summary,summary\'.') do |list|
125
+ options[:summary_labels] = list
126
+ end
127
+ opts.on("--breaking-labels x,y,z", Array, 'Issues with these labels will be added to a new section, called "Breaking changes". Default is \'backwards-incompatible,breaking\'.') do |list|
128
+ options[:breaking_labels] = list
129
+ end
130
+ opts.on("--enhancement-labels x,y,z", Array, 'Issues with the specified labels will be added to "Implemented enhancements" section. Default is \'enhancement,Enhancement\'.') do |list|
131
+ options[:enhancement_labels] = list
132
+ end
133
+ opts.on("--bug-labels x,y,z", Array, 'Issues with the specified labels will be added to "Fixed bugs" section. Default is \'bug,Bug\'.') do |list|
134
+ options[:bug_labels] = list
135
+ end
136
+ opts.on("--deprecated-labels x,y,z", Array, 'Issues with the specified labels will be added to a section called "Deprecated". Default is \'deprecated,Deprecated\'.') do |list|
137
+ options[:deprecated_labels] = list
138
+ end
139
+ opts.on("--removed-labels x,y,z", Array, 'Issues with the specified labels will be added to a section called "Removed". Default is \'removed,Removed\'.') do |list|
140
+ options[:removed_labels] = list
141
+ end
142
+ opts.on("--security-labels x,y,z", Array, 'Issues with the specified labels will be added to a section called "Security fixes". Default is \'security,Security\'.') do |list|
143
+ options[:security_labels] = list
144
+ end
145
+ opts.on("--issue-line-labels x,y,z", Array, 'The specified labels will be shown in brackets next to each matching issue. Use "ALL" to show all labels. Default is [].') do |list|
146
+ options[:issue_line_labels] = list
147
+ end
148
+ opts.on("--include-tags-regex REGEX", "Apply a regular expression on tag names so that they can be included, for example: --include-tags-regex \".*\+\d{1,}\".") do |last|
149
+ options[:include_tags_regex] = last
150
+ end
151
+ opts.on("--exclude-tags x,y,z", Array, "Changelog will exclude specified tags") do |list|
152
+ options[:exclude_tags] = list
153
+ end
154
+ opts.on("--exclude-tags-regex REGEX", "Apply a regular expression on tag names so that they can be excluded, for example: --exclude-tags-regex \".*\+\d{1,}\".") do |last|
155
+ options[:exclude_tags_regex] = last
156
+ end
157
+ opts.on("--since-tag x", "Changelog will start after specified tag.") do |v|
158
+ options[:since_tag] = v
159
+ end
160
+ opts.on("--due-tag x", "Changelog will end before specified tag.") do |v|
161
+ options[:due_tag] = v
162
+ end
163
+ opts.on("--since-commit x", "Fetch only commits after this time. eg. \"2017-01-01 10:00:00\"") do |v|
164
+ options[:since_commit] = v
165
+ end
166
+ opts.on("--max-issues NUMBER", Integer, "Maximum number of issues to fetch from GitHub. Default is unlimited.") do |max|
167
+ options[:max_issues] = max
168
+ end
169
+ opts.on("--release-url URL", "The URL to point to for release links, in printf format (with the tag as variable).") do |url|
170
+ options[:release_url] = url
171
+ end
172
+ opts.on("--github-site URL", "The Enterprise GitHub site where your project is hosted.") do |last|
173
+ options[:github_site] = last
174
+ end
175
+ opts.on("--github-api URL", "The enterprise endpoint to use for your GitHub API.") do |last|
176
+ options[:github_endpoint] = last
177
+ end
178
+ opts.on("--simple-list", "Create a simple list from issues and pull requests. Default is false.") do |v|
179
+ options[:simple_list] = v
180
+ end
181
+ opts.on("--future-release RELEASE-VERSION", "Put the unreleased changes in the specified release number.") do |future_release|
182
+ options[:future_release] = future_release
183
+ end
184
+ opts.on("--release-branch RELEASE-BRANCH", "Limit pull requests to the release branch, such as master or release.") do |release_branch|
185
+ options[:release_branch] = release_branch
186
+ end
187
+ opts.on("--[no-]http-cache", "Use HTTP Cache to cache GitHub API requests (useful for large repos). Default is true.") do |http_cache|
188
+ options[:http_cache] = http_cache
189
+ end
190
+ opts.on("--cache-file CACHE-FILE", "Filename to use for cache. Default is github-changelog-http-cache in a temporary directory.") do |cache_file|
191
+ options[:cache_file] = cache_file
192
+ end
193
+ opts.on("--cache-log CACHE-LOG", "Filename to use for cache log. Default is github-changelog-logger.log in a temporary directory.") do |cache_log|
194
+ options[:cache_log] = cache_log
195
+ end
196
+ opts.on("--config-file CONFIG-FILE", "Path to configuration file. Default is .github_changelog_generator.") do |config_file|
197
+ options[:config_file] = config_file
198
+ end
199
+ opts.on("--ssl-ca-file PATH", "Path to cacert.pem file. Default is a bundled lib/github_changelog_generator/ssl_certs/cacert.pem. Respects SSL_CA_PATH.") do |ssl_ca_file|
200
+ options[:ssl_ca_file] = ssl_ca_file
201
+ end
202
+ opts.on("--require x,y,z", Array, "Path to Ruby file(s) to require before generating changelog.") do |paths|
203
+ options[:require] = paths
204
+ end
205
+ opts.on("--[no-]verbose", "Run verbosely. Default is true.") do |v|
206
+ options[:verbose] = v
207
+ end
208
+ opts.on("-v", "--version", "Print version number.") do |_v|
209
+ puts "Version: #{GitHubChangelogGenerator::VERSION}"
210
+ exit
211
+ end
212
+ opts.on("-h", "--help", "Displays Help.") do
213
+ puts opts
214
+ exit
215
+ end
216
+ end
217
+ end
218
+
219
+ class << self
220
+ def banner
221
+ new.parser.banner
222
+ end
223
+ end
224
+ end
225
+ end
@@ -40,6 +40,15 @@ module GitHubChangelogGenerator
40
40
  @content
41
41
  end
42
42
 
43
+ def line_labels_for(issue)
44
+ labels = if @options[:issue_line_labels] == ["ALL"]
45
+ issue["labels"]
46
+ else
47
+ issue["labels"].select { |label| @options[:issue_line_labels].include?(label["name"]) }
48
+ end
49
+ labels.map { |label| " \[[#{label['name']}](#{label['url'].sub('api.github.com/repos', 'github.com')})\]" }.join("")
50
+ end
51
+
43
52
  private
44
53
 
45
54
  # Creates section objects for this entry.
@@ -72,7 +81,7 @@ module GitHubChangelogGenerator
72
81
  end
73
82
 
74
83
  sections_json.collect do |name, v|
75
- Section.new(name: name.to_s, prefix: v["prefix"], labels: v["labels"], options: @options)
84
+ Section.new(name: name.to_s, prefix: v["prefix"], labels: v["labels"], body_only: v["body_only"], options: @options)
76
85
  end
77
86
  end
78
87
 
@@ -205,14 +214,5 @@ module GitHubChangelogGenerator
205
214
  end
206
215
  nil
207
216
  end
208
-
209
- def line_labels_for(issue)
210
- labels = if @options[:issue_line_labels] == ["ALL"]
211
- issue["labels"]
212
- else
213
- issue["labels"].select { |label| @options[:issue_line_labels].include?(label["name"]) }
214
- end
215
- labels.map { |label| " \[[#{label['name']}](#{label['url'].sub('api.github.com/repos', 'github.com')})\]" }.join("")
216
- end
217
217
  end
218
218
  end
@@ -26,6 +26,12 @@ module GitHubChangelogGenerator
26
26
  class Generator
27
27
  attr_accessor :options, :filtered_tags, :tag_section_mapping, :sorted_tags
28
28
 
29
+ CREDIT_LINE = <<~CREDIT
30
+ \\* *This Changelog was automatically generated \
31
+ by [github_changelog_generator]\
32
+ (https://github.com/github-changelog-generator/github-changelog-generator)*
33
+ CREDIT
34
+
29
35
  # A Generator responsible for all logic, related with changelog generation from ready-to-parse issues
30
36
  #
31
37
  # Example:
@@ -43,26 +49,21 @@ module GitHubChangelogGenerator
43
49
  # @return [String] Generated changelog file
44
50
  def compound_changelog
45
51
  @options.load_custom_ruby_files
46
- fetch_and_filter_tags
47
- fetch_issues_and_pr
48
-
49
- log = ""
50
- log += @options[:frontmatter] if @options[:frontmatter]
51
- log += "#{options[:header]}\n\n"
52
-
53
- log += if @options[:unreleased_only]
54
- generate_entry_between_tags(@filtered_tags[0], nil)
55
- else
56
- generate_entries_for_all_tags
57
- end
58
-
59
- log += File.read(@options[:base]) if File.file?(@options[:base])
60
-
61
- credit_line = "\n\n\\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*"
62
- log.gsub!(/#{credit_line}(\n)?/, "") # Remove old credit lines
63
- log += "#{credit_line}\n"
64
52
 
65
- @log = log
53
+ Sync do
54
+ fetch_and_filter_tags
55
+ fetch_issues_and_pr
56
+
57
+ log = if @options[:unreleased_only]
58
+ generate_entry_between_tags(@filtered_tags[0], nil)
59
+ else
60
+ generate_entries_for_all_tags
61
+ end
62
+ log += File.read(@options[:base]) if File.file?(@options[:base])
63
+ log = remove_old_fixed_string(log)
64
+ log = insert_fixed_string(log)
65
+ @log = log
66
+ end
66
67
  end
67
68
 
68
69
  private
@@ -151,5 +152,26 @@ module GitHubChangelogGenerator
151
152
  add_first_occurring_tag_to_prs(@sorted_tags, @pull_requests)
152
153
  nil
153
154
  end
155
+
156
+ # Remove the previously assigned fixed message.
157
+ # @param log [String] Old lines are fixed
158
+ def remove_old_fixed_string(log)
159
+ log.gsub!(/#{Regexp.escape(@options[:frontmatter])}/, "") if @options[:frontmatter]
160
+ log.gsub!(/#{Regexp.escape(@options[:header])}\n{,2}/, "")
161
+ log.gsub!(/\n{,2}#{Regexp.escape(CREDIT_LINE)}/, "") # Remove old credit lines
162
+ log
163
+ end
164
+
165
+ # Add template messages to given string. Previously added
166
+ # messages of the same wording are removed.
167
+ # @param log [String]
168
+ def insert_fixed_string(log)
169
+ ins = ""
170
+ ins += @options[:frontmatter] if @options[:frontmatter]
171
+ ins += "#{@options[:header]}\n\n"
172
+ log.insert(0, ins)
173
+ log += "\n\n#{CREDIT_LINE}"
174
+ log
175
+ end
154
176
  end
155
177
  end