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
@@ -84,47 +84,47 @@
84
84
 
85
85
  <h2 id="OPTIONS">OPTIONS</h2>
86
86
 
87
- <p> -u, --user [USER]</p>
87
+ <p> -u, --user USER</p>
88
88
 
89
89
  <p> Username of the owner of target GitHub repo</p>
90
90
 
91
- <p> -p, --project [PROJECT]</p>
91
+ <p> -p, --project PROJECT</p>
92
92
 
93
93
  <p> Name of project on GitHub</p>
94
94
 
95
- <p> -t, --token [TOKEN]</p>
95
+ <p> -t, --token TOKEN</p>
96
96
 
97
97
  <p> To make more than 50 requests per hour your GitHub token is required. You can generate it at: https://github.com/settings/tokens/new</p>
98
98
 
99
- <p> -f, --date-format [FORMAT]</p>
99
+ <p> -f, --date-format FORMAT</p>
100
100
 
101
101
  <p> Date format. Default is %Y-%m-%d</p>
102
102
 
103
- <p> -o, --output [NAME]</p>
103
+ <p> -o, --output NAME</p>
104
104
 
105
105
  <p> Output file. Default is CHANGELOG.md</p>
106
106
 
107
- <p> -b, --base [NAME]</p>
107
+ <p> -b, --base NAME</p>
108
108
 
109
109
  <p> Optional base file to append generated changes to.</p>
110
110
 
111
- <p> --bugs-label [LABEL]</p>
111
+ <p> --bugs-label LABEL</p>
112
112
 
113
113
  <p> Setup custom label for bug-fixes section. Default is "<strong>Fixed bugs:</strong></p>
114
114
 
115
- <p> --enhancement-label [LABEL]</p>
115
+ <p> --enhancement-label LABEL</p>
116
116
 
117
117
  <p> Setup custom label for enhancements section. Default is "<strong>Implemented enhancements:</strong>"</p>
118
118
 
119
- <p> --issues-label [LABEL]</p>
119
+ <p> --issues-label LABEL</p>
120
120
 
121
121
  <p> Setup custom label for closed-issues section. Default is "<strong>Closed issues:</strong>"</p>
122
122
 
123
- <p> --header-label [LABEL]</p>
123
+ <p> --header-label LABEL</p>
124
124
 
125
125
  <p> Setup custom header label. Default is "# Changelog"</p>
126
126
 
127
- <p> --pr-label [LABEL]</p>
127
+ <p> --pr-label LABEL</p>
128
128
 
129
129
  <p> Setup custom label for pull requests section. Default is "<strong>Merged pull requests:</strong>"</p>
130
130
 
@@ -160,7 +160,7 @@
160
160
 
161
161
  <p> Add to log unreleased closed issues. Default is true</p>
162
162
 
163
- <p> --unreleased-label [label]</p>
163
+ <p> --unreleased-label LABEL</p>
164
164
 
165
165
  <p> Add to log unreleased closed issues. Default is true</p>
166
166
 
@@ -196,19 +196,19 @@
196
196
 
197
197
  <p> Changelog will end before specified tag</p>
198
198
 
199
- <p> --max-issues [NUMBER]</p>
199
+ <p> --max-issues NUMBER</p>
200
200
 
201
201
  <p> Max number of issues to fetch from GitHub. Default is unlimited</p>
202
202
 
203
- <p> --release-url [URL]</p>
203
+ <p> --release-url URL</p>
204
204
 
205
205
  <p> The URL to point to for release links, in printf format (with the tag as variable).</p>
206
206
 
207
- <p> --github-site [URL]</p>
207
+ <p> --github-site URL</p>
208
208
 
209
209
  <p> The Enterprise Github site on which your project is hosted.</p>
210
210
 
211
- <p> --github-api [URL]</p>
211
+ <p> --github-api URL</p>
212
212
 
213
213
  <p> The enterprise endpoint to use for your Github API.</p>
214
214
 
@@ -216,15 +216,15 @@
216
216
 
217
217
  <p> Create simple list from issues and pull requests. Default is false.</p>
218
218
 
219
- <p> --future-release [RELEASE-VERSION]</p>
219
+ <p> --future-release RELEASE-VERSION</p>
220
220
 
221
221
  <p> Put the unreleased changes in the specified release number.</p>
222
222
 
223
- <p> --configure-sections [HASH, STRING]</p>
223
+ <p> --configure-sections HASH, STRING</p>
224
224
 
225
225
  <p> Define your own set of sections which overrides all default sections") do |v|</p>
226
226
 
227
- <p> --add-sections [HASH, STRING]</p>
227
+ <p> --add-sections HASH, STRING</p>
228
228
 
229
229
  <p> Add new sections but keep the default sections"</p>
230
230
 
@@ -11,79 +11,79 @@ Automatically generate changelog from your tags, issues, labels and pull request
11
11
 
12
12
  ## OPTIONS
13
13
 
14
- -u, --user [USER]
14
+ -u, --user USER
15
15
 
16
16
  Username of the owner of target GitHub repo.
17
17
 
18
- -p, --project [PROJECT]
18
+ -p, --project PROJECT
19
19
 
20
20
  Name of project on GitHub.
21
21
 
22
- -t, --token [TOKEN]
22
+ -t, --token TOKEN
23
23
 
24
24
  To make more than 50 requests per hour your GitHub token is required. You can generate it at: https://github.com/settings/tokens/new
25
25
 
26
- -f, --date-format [FORMAT]
26
+ -f, --date-format FORMAT
27
27
 
28
28
  Date format. Default is %Y-%m-%d.
29
29
 
30
- -o, --output [NAME]
30
+ -o, --output NAME
31
31
 
32
32
  Output file. To print to STDOUT instead, use blank as path. Default is CHANGELOG.md.
33
33
 
34
- -b, --base [NAME]
34
+ -b, --base NAME
35
35
 
36
- Optional base file to append generated changes to.
36
+ Optional base file to append generated changes to. Default is HISTORY.md.
37
37
 
38
- --summary-label [LABEL]
38
+ --summary-label LABEL
39
39
 
40
40
  Set up custom label for the release summary section. Default is "".
41
41
 
42
- --breaking-label [LABEL]
42
+ --breaking-label LABEL
43
43
 
44
44
  Set up custom label for breaking changes section. Default is "**Breaking changes:**".
45
45
 
46
- --enhancement-label [LABEL]
46
+ --enhancement-label LABEL
47
47
 
48
48
  Set up custom label for enhancements section. Default is "**Implemented enhancements:**".
49
49
 
50
- --bugs-label [LABEL]
50
+ --bugs-label LABEL
51
51
 
52
52
  Set up custom label for bug-fixes section. Default is "**Fixed bugs:**".
53
53
 
54
- --deprecated-label [LABEL]
54
+ --deprecated-label LABEL
55
55
 
56
56
  Set up custom label for deprecated section. Default is "**Deprecated:**".
57
57
 
58
- --removed-label [LABEL]
58
+ --removed-label LABEL
59
59
 
60
60
  Set up custom label for removed section. Default is "**Removed:**".
61
61
 
62
- --security-label [LABEL]
62
+ --security-label LABEL
63
63
 
64
64
  Set up custom label for security section. Default is "**Security:**".
65
65
 
66
- --issues-label [LABEL]
66
+ --issues-label LABEL
67
67
 
68
68
  Set up custom label for closed-issues section. Default is "**Closed issues:**".
69
69
 
70
- --header-label [LABEL]
70
+ --header-label LABEL
71
71
 
72
72
  Set up custom header label. Default is "# Changelog".
73
73
 
74
- --configure-sections [HASH, STRING]
74
+ --configure-sections HASH, STRING
75
75
 
76
76
  Define your own set of sections which overrides all default sections.
77
77
 
78
- --add-sections [HASH, STRING]
78
+ --add-sections HASH, STRING
79
79
 
80
80
  Add new sections but keep the default sections.
81
81
 
82
- --front-matter [JSON]
82
+ --front-matter JSON
83
83
 
84
84
  Add YAML front matter. Formatted as JSON because it's easier to add on the command line.
85
85
 
86
- --pr-label [LABEL]
86
+ --pr-label LABEL
87
87
 
88
88
  Set up custom label for pull requests section. Default is "**Merged pull requests:**".
89
89
 
@@ -107,6 +107,10 @@ Automatically generate changelog from your tags, issues, labels and pull request
107
107
 
108
108
  Use milestone to detect when issue was resolved. Default is true.
109
109
 
110
+ --[no-]issues-of-open-milestones
111
+
112
+ Include issues of open milestones. Default is true.
113
+
110
114
  --[no-]author
111
115
 
112
116
  Add author of pull request at the end. Default is true.
@@ -123,7 +127,7 @@ Automatically generate changelog from your tags, issues, labels and pull request
123
127
 
124
128
  Add to log unreleased closed issues. Default is true.
125
129
 
126
- --unreleased-label [label]
130
+ --unreleased-label LABEL
127
131
 
128
132
  Set up custom label for unreleased closed issues section. Default is "**Unreleased:**".
129
133
 
@@ -175,7 +179,7 @@ Automatically generate changelog from your tags, issues, labels and pull request
175
179
 
176
180
  Changelog will exclude specified tags.
177
181
 
178
- --exclude-tags-regex [REGEX]
182
+ --exclude-tags-regex REGEX
179
183
 
180
184
  Apply a regular expression on tag names so that they can be excluded, for example: --exclude-tags-regex ".*\+\d{1,}".
181
185
 
@@ -187,19 +191,23 @@ Automatically generate changelog from your tags, issues, labels and pull request
187
191
 
188
192
  Changelog will end before specified tag.
189
193
 
190
- --max-issues [NUMBER]
194
+ --since-commit x
195
+
196
+ Fetch only commits after this time. eg. "2017-01-01 10:00:00"
197
+
198
+ --max-issues NUMBER
191
199
 
192
200
  Maximum number of issues to fetch from GitHub. Default is unlimited.
193
201
 
194
- --release-url [URL]
202
+ --release-url URL
195
203
 
196
204
  The URL to point to for release links, in printf format (with the tag as variable).
197
205
 
198
- --github-site [URL]
206
+ --github-site URL
199
207
 
200
208
  The Enterprise GitHub site where your project is hosted.
201
209
 
202
- --github-api [URL]
210
+ --github-api URL
203
211
 
204
212
  The enterprise endpoint to use for your GitHub API.
205
213
 
@@ -207,11 +215,11 @@ Automatically generate changelog from your tags, issues, labels and pull request
207
215
 
208
216
  Create a simple list from issues and pull requests. Default is false.
209
217
 
210
- --future-release [RELEASE-VERSION]
218
+ --future-release RELEASE-VERSION
211
219
 
212
220
  Put the unreleased changes in the specified release number.
213
221
 
214
- --release-branch [RELEASE-BRANCH]
222
+ --release-branch RELEASE-BRANCH
215
223
 
216
224
  Limit pull requests to the release branch, such as master or release.
217
225
 
@@ -219,15 +227,15 @@ Automatically generate changelog from your tags, issues, labels and pull request
219
227
 
220
228
  Use HTTP Cache to cache GitHub API requests (useful for large repos). Default is true.
221
229
 
222
- --[no-]cache-file [CACHE-FILE]
230
+ --[no-]cache-file CACHE-FILE
223
231
 
224
232
  Filename to use for cache. Default is github-changelog-http-cache in a temporary directory.
225
233
 
226
- --cache-log [CACHE-LOG]
234
+ --cache-log CACHE-LOG
227
235
 
228
236
  Filename to use for cache log. Default is github-changelog-logger.log in a temporary directory.
229
237
 
230
- --ssl-ca-file [PATH]
238
+ --ssl-ca-file PATH
231
239
 
232
240
  Path to cacert.pem file. Default is a bundled lib/github_changelog_generator/ssl_certs/cacert.pem. Respects SSL_CA_PATH.
233
241
 
@@ -0,0 +1,5 @@
1
+ user=spec_user
2
+ project=spec_project
3
+ unreleased=false
4
+ future-release=5.0.0
5
+ since-tag=1.0.0
data/spec/spec_helper.rb CHANGED
@@ -44,7 +44,7 @@ VCR.configure do |c|
44
44
  decode_compressed_response: true
45
45
  }
46
46
  c.filter_sensitive_data("<GITHUB_TOKEN>") do
47
- "token #{ENV.fetch('CHANGELOG_GITHUB_TOKEN') { 'frobnitz' }}"
47
+ "token #{ENV.fetch('CHANGELOG_GITHUB_TOKEN', 'frobnitz')}"
48
48
  end
49
49
 
50
50
  c.configure_rspec_metadata!
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Metrics/ModuleLength
4
3
  module GitHubChangelogGenerator
5
4
  RSpec.describe Entry do
6
5
  def label(name)
@@ -58,9 +57,6 @@ module GitHubChangelogGenerator
58
57
  let(:issues) { [] }
59
58
  let(:pull_requests) { [] }
60
59
  let(:tags) { [] }
61
- let(:compare_shas) do
62
- { "aaaaa1...master" => ["aaaaa1"] }
63
- end
64
60
 
65
61
  # Default to standard options minus verbose to avoid output during testing.
66
62
  let(:options) do
@@ -76,15 +72,14 @@ module GitHubChangelogGenerator
76
72
  fetch_closed_issues_and_pr: [issues, pull_requests],
77
73
  fetch_closed_pull_requests: [],
78
74
  fetch_events_async: issues + pull_requests,
79
- fetch_tag_shas_async: nil,
75
+ fetch_tag_shas: nil,
80
76
  fetch_comments_async: nil,
81
77
  default_branch: "master",
82
78
  oldest_commit: { "sha" => "aaaaa1" },
83
79
  fetch_commit: { "commit" => { "author" => { "date" => Time.now.utc } } }
84
80
  )
85
- allow(fake_fetcher).to receive(:fetch_compare) do |old, new|
86
- # Comparisons has a "commits" key of an array of commit hashes each with a "sha" key.
87
- { "commits" => compare_shas["#{old}...#{new}"].collect { |sha| { "sha" => sha } } }
81
+ allow(fake_fetcher).to receive(:commits_in_branch) do
82
+ ["aaaaa1"]
88
83
  end
89
84
  allow(GitHubChangelogGenerator::OctoFetcher).to receive(:new).and_return(fake_fetcher)
90
85
  generator = GitHubChangelogGenerator::Generator.new(options)
@@ -426,6 +421,18 @@ module GitHubChangelogGenerator
426
421
  sections_json.shift
427
422
  end
428
423
  end
424
+ context "parse also body_only" do
425
+ let(:sections_string) { "{ \"foo\": { \"prefix\": \"foofix\", \"labels\": [\"test1\", \"test2\"]}, \"bar\": { \"prefix\": \"barfix\", \"labels\": [\"test3\", \"test4\"], \"body_only\": true}}" }
426
+
427
+ it "returns correctly constructed sections" do
428
+ require "json"
429
+
430
+ parsed_sections = subject.send(:parse_sections, sections_string)
431
+
432
+ expect(parsed_sections[0].body_only).to eq false
433
+ expect(parsed_sections[1].body_only).to eq true
434
+ end
435
+ end
429
436
  end
430
437
  context "hash" do
431
438
  let(:sections_hash) do
@@ -548,14 +555,14 @@ module GitHubChangelogGenerator
548
555
  end
549
556
 
550
557
  it "assigns issues to the correct sections" do
551
- breaking_section = entry_sections.select { |section| section.name == "breaking" }[0]
552
- enhancement_section = entry_sections.select { |section| section.name == "enhancements" }[0]
553
- bug_section = entry_sections.select { |section| section.name == "bugs" }[0]
554
- deprecated_section = entry_sections.select { |section| section.name == "deprecated" }[0]
555
- removed_section = entry_sections.select { |section| section.name == "removed" }[0]
556
- security_section = entry_sections.select { |section| section.name == "security" }[0]
557
- issue_section = entry_sections.select { |section| section.name == "issues" }[0]
558
- merged_section = entry_sections.select { |section| section.name == "merged" }[0]
558
+ breaking_section = entry_sections.find { |section| section.name == "breaking" }
559
+ enhancement_section = entry_sections.find { |section| section.name == "enhancements" }
560
+ bug_section = entry_sections.find { |section| section.name == "bugs" }
561
+ deprecated_section = entry_sections.find { |section| section.name == "deprecated" }
562
+ removed_section = entry_sections.find { |section| section.name == "removed" }
563
+ security_section = entry_sections.find { |section| section.name == "security" }
564
+ issue_section = entry_sections.find { |section| section.name == "issues" }
565
+ merged_section = entry_sections.find { |section| section.name == "merged" }
559
566
 
560
567
  expect(titles_for(breaking_section.issues)).to eq(["issue breaking", "issue all the labels", "pr breaking", "pr all the labels"])
561
568
  expect(titles_for(enhancement_section.issues)).to eq(["issue enhancement", "pr enhancement"])
@@ -612,10 +619,10 @@ module GitHubChangelogGenerator
612
619
  end
613
620
 
614
621
  it "assigns issues to the correct sections" do
615
- foo_section = entry_sections.select { |section| section.name == "foo" }[0]
616
- bar_section = entry_sections.select { |section| section.name == "bar" }[0]
617
- issue_section = entry_sections.select { |section| section.name == "issues" }[0]
618
- merged_section = entry_sections.select { |section| section.name == "merged" }[0]
622
+ foo_section = entry_sections.find { |section| section.name == "foo" }
623
+ bar_section = entry_sections.find { |section| section.name == "bar" }
624
+ issue_section = entry_sections.find { |section| section.name == "issues" }
625
+ merged_section = entry_sections.find { |section| section.name == "merged" }
619
626
 
620
627
  aggregate_failures "checks all sections" do
621
628
  expect(titles_for(foo_section.issues)).to eq(["issue test1", "issue all the labels", "issue some included labels", "pr test1", "pr all the labels", "pr some included labels"])
@@ -670,10 +677,10 @@ module GitHubChangelogGenerator
670
677
  end
671
678
 
672
679
  it "assigns issues to the correct sections" do
673
- foo_section = entry_sections.select { |section| section.name == "foo" }[0]
674
- bar_section = entry_sections.select { |section| section.name == "bar" }[0]
675
- issue_section = entry_sections.select { |section| section.name == "issues" }[0]
676
- merged_section = entry_sections.select { |section| section.name == "merged" }[0]
680
+ foo_section = entry_sections.find { |section| section.name == "foo" }
681
+ bar_section = entry_sections.find { |section| section.name == "bar" }
682
+ issue_section = entry_sections.find { |section| section.name == "issues" }
683
+ merged_section = entry_sections.find { |section| section.name == "merged" }
677
684
 
678
685
  aggregate_failures "checks all sections" do
679
686
  expect(titles_for(foo_section.issues)).to eq(["issue test1", "issue all the labels", "pr test1", "pr all the labels"])
@@ -737,12 +744,12 @@ module GitHubChangelogGenerator
737
744
  end
738
745
 
739
746
  it "assigns issues to the correct sections" do
740
- foo_section = entry_sections.select { |section| section.name == "foo" }[0]
741
- breaking_section = entry_sections.select { |section| section.name == "breaking" }[0]
742
- enhancement_section = entry_sections.select { |section| section.name == "enhancements" }[0]
743
- bug_section = entry_sections.select { |section| section.name == "bugs" }[0]
744
- issue_section = entry_sections.select { |section| section.name == "issues" }[0]
745
- merged_section = entry_sections.select { |section| section.name == "merged" }[0]
747
+ foo_section = entry_sections.find { |section| section.name == "foo" }
748
+ breaking_section = entry_sections.find { |section| section.name == "breaking" }
749
+ enhancement_section = entry_sections.find { |section| section.name == "enhancements" }
750
+ bug_section = entry_sections.find { |section| section.name == "bugs" }
751
+ issue_section = entry_sections.find { |section| section.name == "issues" }
752
+ merged_section = entry_sections.find { |section| section.name == "merged" }
746
753
 
747
754
  aggregate_failures "checks all sections" do
748
755
  expect(titles_for(breaking_section.issues)).to eq(["issue all the labels", "pr all the labels"])
@@ -757,4 +764,3 @@ module GitHubChangelogGenerator
757
764
  end
758
765
  end
759
766
  end
760
- # rubocop:enable Metrics/ModuleLength
@@ -5,82 +5,137 @@ module GitHubChangelogGenerator
5
5
  let(:default_options) { GitHubChangelogGenerator::Parser.default_options.merge(verbose: false) }
6
6
  let(:options) { {} }
7
7
  let(:generator) { described_class.new(default_options.merge(options)) }
8
-
9
8
  let(:bad_label) { { "name" => "BAD" } }
10
- let(:bad_issue) { { "labels" => [bad_label] } }
11
9
  let(:good_label) { { "name" => "GOOD" } }
12
- let(:good_issue) { { "labels" => [good_label] } }
13
- let(:unlabeled_issue) { { "labels" => [] } }
14
- let(:issues) { [bad_issue, good_issue, unlabeled_issue] }
15
10
 
16
- describe "#exclude_issues_by_labels" do
17
- subject do
18
- generator.exclude_issues_by_labels(issues)
19
- end
11
+ describe "pull requests" do
12
+ let(:bad_pull_request) { { "pull_request" => {}, "labels" => [bad_label] } }
13
+ let(:good_pull_request) { { "pull_request" => {}, "labels" => [good_label] } }
14
+ let(:unlabeled_pull_request) { { "pull_request" => {}, "labels" => [] } }
15
+ let(:pull_requests) { [bad_pull_request, good_pull_request, unlabeled_pull_request] }
20
16
 
21
- let(:expected_issues) { issues }
17
+ describe "#filter_wo_labels" do
18
+ subject do
19
+ generator.filter_wo_labels(pull_requests)
20
+ end
22
21
 
23
- it { is_expected.to eq(expected_issues) }
22
+ let(:expected_pull_requests) { pull_requests }
24
23
 
25
- context "when 'exclude_lables' is provided" do
26
- let(:options) { { exclude_labels: %w[BAD BOO] } }
27
- let(:expected_issues) { [good_issue, unlabeled_issue] }
24
+ it { is_expected.to eq(expected_pull_requests) }
28
25
 
29
- it { is_expected.to eq(expected_issues) }
30
- end
26
+ context "when 'add_pr_wo_labels' is false" do
27
+ let(:options) { { add_pr_wo_labels: false } }
28
+ let(:expected_pull_requests) { [bad_pull_request, good_pull_request] }
31
29
 
32
- context "with no option given" do
33
- subject(:generator) { described_class.new }
34
- it "passes everything through when no option given" do
35
- result = generator.exclude_issues_by_labels(issues)
30
+ it { is_expected.to eq(expected_pull_requests) }
31
+ end
32
+
33
+ context "when 'add_pr_wo_labels' is true" do
34
+ let(:options) { { add_pr_wo_labels: true } }
36
35
 
37
- expect(result).to eq(issues)
36
+ it { is_expected.to eq(expected_pull_requests) }
38
37
  end
39
38
  end
40
39
  end
41
40
 
42
- describe "#get_filtered_issues" do
43
- subject do
44
- generator.get_filtered_issues(issues)
45
- end
41
+ describe "issues" do
42
+ let(:bad_issue) { { "labels" => [bad_label] } }
43
+ let(:good_issue) { { "labels" => [good_label] } }
44
+ let(:unlabeled_issue) { { "labels" => [] } }
45
+ let(:issues) { [bad_issue, good_issue, unlabeled_issue] }
46
46
 
47
- let(:expected_issues) { issues }
48
-
49
- it { is_expected.to eq(expected_issues) }
47
+ describe "#filter_wo_labels" do
48
+ subject do
49
+ generator.filter_wo_labels(issues)
50
+ end
50
51
 
51
- context "when 'exclude_labels' is provided" do
52
- let(:options) { { exclude_labels: %w[BAD BOO] } }
53
- let(:expected_issues) { [good_issue, unlabeled_issue] }
52
+ let(:expected_issues) { issues }
54
53
 
55
54
  it { is_expected.to eq(expected_issues) }
55
+
56
+ context "when 'add_issues_wo_labels' is false" do
57
+ let(:options) { { add_issues_wo_labels: false } }
58
+ let(:expected_issues) { [bad_issue, good_issue] }
59
+
60
+ it { is_expected.to eq(expected_issues) }
61
+ end
62
+
63
+ context "when 'add_issues_wo_labels' is true" do
64
+ let(:options) { { add_issues_wo_labels: true } }
65
+
66
+ it { is_expected.to eq(expected_issues) }
67
+ end
56
68
  end
57
69
 
58
- context "when 'add_issues_wo_labels' is false" do
59
- let(:options) { { add_issues_wo_labels: false } }
60
- let(:expected_issues) { [bad_issue, good_issue] }
70
+ describe "#exclude_issues_by_labels" do
71
+ subject do
72
+ generator.exclude_issues_by_labels(issues)
73
+ end
74
+
75
+ let(:expected_issues) { issues }
61
76
 
62
77
  it { is_expected.to eq(expected_issues) }
63
78
 
64
- context "with 'exclude_labels'" do
65
- let(:options) { { add_issues_wo_labels: false, exclude_labels: %w[GOOD] } }
66
- let(:expected_issues) { [bad_issue] }
79
+ context "when 'exclude_labels' is provided" do
80
+ let(:options) { { exclude_labels: %w[BAD BOO] } }
81
+ let(:expected_issues) { [good_issue, unlabeled_issue] }
67
82
 
68
83
  it { is_expected.to eq(expected_issues) }
69
84
  end
70
85
 
71
- context "with 'include_labels'" do
72
- let(:options) { { add_issues_wo_labels: false, include_labels: %w[GOOD] } }
73
- let(:expected_issues) { [good_issue] }
86
+ context "with no option given" do
87
+ subject(:generator) { described_class.new }
88
+ it "passes everything through when no option given" do
89
+ result = generator.exclude_issues_by_labels(issues)
74
90
 
75
- it { is_expected.to eq(expected_issues) }
91
+ expect(result).to eq(issues)
92
+ end
76
93
  end
77
94
  end
78
95
 
79
- context "when 'include_labels' is specified" do
80
- let(:options) { { include_labels: %w[GOOD] } }
81
- let(:expected_issues) { [good_issue, unlabeled_issue] }
96
+ describe "#get_filtered_issues" do
97
+ subject do
98
+ generator.get_filtered_issues(issues)
99
+ end
100
+
101
+ let(:expected_issues) { issues }
82
102
 
83
103
  it { is_expected.to eq(expected_issues) }
104
+
105
+ context "when 'exclude_labels' is provided" do
106
+ let(:options) { { exclude_labels: %w[BAD BOO] } }
107
+ let(:expected_issues) { [good_issue, unlabeled_issue] }
108
+
109
+ it { is_expected.to eq(expected_issues) }
110
+ end
111
+
112
+ context "when 'add_issues_wo_labels' is false" do
113
+ let(:options) { { add_issues_wo_labels: false } }
114
+ let(:expected_issues) { [bad_issue, good_issue] }
115
+
116
+ it { is_expected.to eq(expected_issues) }
117
+
118
+ context "with 'exclude_labels'" do
119
+ let(:options) { { add_issues_wo_labels: false, exclude_labels: %w[GOOD] } }
120
+ let(:expected_issues) { [bad_issue] }
121
+
122
+ it { is_expected.to eq(expected_issues) }
123
+ end
124
+
125
+ context "with 'include_labels'" do
126
+ let(:options) { { add_issues_wo_labels: false, include_labels: %w[GOOD] } }
127
+ let(:expected_issues) { [good_issue] }
128
+
129
+ it { is_expected.to eq(expected_issues) }
130
+ end
131
+ end
132
+
133
+ context "when 'include_labels' is specified" do
134
+ let(:options) { { include_labels: %w[GOOD] } }
135
+ let(:expected_issues) { [good_issue, unlabeled_issue] }
136
+
137
+ it { is_expected.to eq(expected_issues) }
138
+ end
84
139
  end
85
140
  end
86
141
  end