danger-changelog 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f8593deb38bfbe15247c55c9b28f149248f7c4d7
4
- data.tar.gz: 8905154e4f917190f212f83b312394905024cabc
3
+ metadata.gz: 9d4fe77b8ef69e2c21ec85e896c0fcdb147360ee
4
+ data.tar.gz: 3fb652c91f7e792e0c5b9c66386ced70052fd9d5
5
5
  SHA512:
6
- metadata.gz: e94967c180e24f33d89c908633d67de0df70e433696a3856a9c4c93b8e79b9a59a5c90ef33a3c64cc727a0184b179d782db16d6a01fd65295f29670f929393af
7
- data.tar.gz: a2ea235027bc568fc141ddd6e0e391688d96437ed090f4164c7211bedfa334c6eacb2d73da7bd0e554fad2d8dd009b9bda29e2990e8df5ee1fecc23ef83ca059
6
+ metadata.gz: e6d4bdd5279313f49fd325e74995e0dc38495685cd71fb39bdfe4b70de98a25a7c0038ea37d1ca4737c8ee6818551f1d8bca06069f5d092e7405afaf30d99227
7
+ data.tar.gz: 429d0875a41ad68e6dfcc289ac9c98031f6c0104f49ac1e2238798e9e554284641a2d4b9f31cc35c480f6af133c81edf6bdf28686dba378b7ac11c7b81d704f2
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  pkg
3
3
  .idea/
4
4
  Gemfile.lock
5
+ .yardoc
data/.rubocop_todo.yml CHANGED
@@ -1,20 +1,20 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2016-08-26 16:59:39 -0400 using RuboCop version 0.42.0.
3
+ # on 2016-11-21 18:59:46 -0500 using RuboCop version 0.43.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 2
9
+ # Offense count: 1
10
10
  Metrics/AbcSize:
11
- Max: 18
11
+ Max: 19
12
12
 
13
- # Offense count: 26
13
+ # Offense count: 40
14
14
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
15
15
  # URISchemes: http, https
16
16
  Metrics/LineLength:
17
- Max: 240
17
+ Max: 254
18
18
 
19
19
  # Offense count: 3
20
20
  # Configuration parameters: CountComments.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## Changelog
2
2
 
3
+ ### 0.2.0 (11/21/2016)
4
+
5
+ * [#13](https://github.com/dblock/danger-changelog/pull/13): Fix: suggested CHANGELOG entry may not be of correct format - [@dblock](https://github.com/dblock).
6
+ * [#18](https://github.com/dblock/danger-changelog/pull/18): Fix: incorrect CHANGELOG filename reported when file doesn't exist - [@dblock](https://github.com/dblock).
7
+
3
8
  ### 0.1.0 (8/26/2016)
4
9
 
5
10
  * [#2](https://github.com/dblock/danger-changelog/pull/2): Added `is_changelog_format_correct?` - [@dblock](https://github.com/dblock).
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  # danger-changelog
2
2
 
3
- A PR linter plugin to [danger.systems](http://danger.systems) that is OCD about your CHANGELOG format.
3
+ A pull request linter plugin to [danger.systems](http://danger.systems) that enforces CHANGELOG.md O.C.D. in your projects.
4
+ This plugin can, for example, make sure the changes are attributes properly and that they are always terminated with a period.
4
5
 
6
+ [![Gem Version](https://badge.fury.io/rb/danger-changelog.svg)](https://badge.fury.io/rb/danger-changelog)
5
7
  [![Build Status](https://travis-ci.org/dblock/danger-changelog.svg?branch=master)](https://travis-ci.org/dblock/danger-changelog)
6
8
 
7
9
  ## Installation
@@ -45,17 +45,10 @@ module Danger
45
45
  @your_contribution_here = true
46
46
  next
47
47
  end
48
- next if valid_line?(line)
48
+ next if Danger::Changelog::ChangelogLine.valid?(line)
49
49
  @bad_lines << line
50
50
  end
51
51
  end
52
-
53
- # match the PR format, with or without PR number
54
- def valid_line?(line)
55
- return true if line =~ %r{^\*\s[\`[:upper:]].* \- \[\@[\w\d\-\_]+\]\(https:\/\/github\.com\/.*[\w\d\-\_]+\)\.$}
56
- return true if line =~ %r{^\*\s\[\#\d+\]\(https:\/\/github\.com\/.*\d+\)\: [\`[:upper:]].* \- \[\@[\w\d\-\_]+\]\(https:\/\/github\.com\/.*[\w\d\-\_]+\)\.$}
57
- false
58
- end
59
52
  end
60
53
  end
61
54
  end
@@ -0,0 +1,25 @@
1
+ module Danger
2
+ module Changelog
3
+ # A CHANGELOG.md file reader.
4
+ module ChangelogLine
5
+ # match the PR format, with or without PR number
6
+ def self.valid?(line)
7
+ return true if line =~ %r{^\*\s[\`[:upper:]].* \- \[\@[\w\d\-\_]+\]\(https:\/\/github\.com\/.*[\w\d\-\_]+\)\.$}
8
+ return true if line =~ %r{^\*\s\[\#\d+\]\(https:\/\/github\.com\/.*\d+\)\: [\`[:upper:]].* \- \[\@[\w\d\-\_]+\]\(https:\/\/github\.com\/.*[\w\d\-\_]+\)\.$}
9
+ false
10
+ end
11
+
12
+ # provide an example of a CHANGELOG line based on a commit message
13
+ def self.example(github)
14
+ pr_number = github.pr_json['number']
15
+ pr_url = github.pr_json['html_url']
16
+ pr_title = github.pr_title
17
+ .sub(/[?.!,;]?$/, '')
18
+ .capitalize
19
+ pr_author = github.pr_author
20
+ pr_author_url = "https://github.com/#{github.pr_author}"
21
+ "* [##{pr_number}](#{pr_url}): #{pr_title} - [@#{pr_author}](#{pr_author_url})."
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module Changelog
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
@@ -1,17 +1,22 @@
1
1
  module Danger
2
- # CHANGELOG OCD in your projects.
2
+ # Enforce CHANGELOG.md O.C.D. in your projects.
3
3
  #
4
- # @example Checking for everuthing
4
+ # This plugin can, for example, make sure the changes are attributes properly and that they are always terminated with a period.
5
+ #
6
+ # @example Run all checks on the default CHANGELOG.md.
5
7
  #
6
8
  # changelog.check
7
9
  #
10
+ # @example Customize the CHANGELOG file name and remind the requester to update it when necessary.
11
+ #
12
+ # changelog.filename = 'CHANGES.md'
13
+ # changelog.have_you_updated_changelog?
14
+ #
8
15
  # @see dblock/danger-changelog
9
16
  # @tags changelog
10
17
 
11
18
  class DangerChangelog < Plugin
12
- # Sets the CHANGELOG file name.
13
- # defaults to `CHANGELOG.md`.
14
- #
19
+ # The changelog file name, defaults to `CHANGELOG.md`.
15
20
  # @return [String]
16
21
  attr_accessor :filename
17
22
 
@@ -20,19 +25,19 @@ module Danger
20
25
  super
21
26
  end
22
27
 
23
- # Has the CHANGELOG file been modified?
24
- # @return [boolean]
25
- def changelog_changes?
26
- git.modified_files.include?(filename) || git.added_files.include?(filename)
27
- end
28
-
29
- # Runs all checks.
28
+ # Run all checks.
30
29
  # @return [void]
31
30
  def check
32
31
  have_you_updated_changelog?
33
32
  is_changelog_format_correct?
34
33
  end
35
34
 
35
+ # Has the CHANGELOG file been modified?
36
+ # @return [boolean]
37
+ def changelog_changes?
38
+ git.modified_files.include?(filename) || git.added_files.include?(filename)
39
+ end
40
+
36
41
  # Have you updated CHANGELOG.md?
37
42
  # @return [boolean]
38
43
  def have_you_updated_changelog?
@@ -43,7 +48,7 @@ module Danger
43
48
  Here's an example of a #{filename} entry:
44
49
 
45
50
  ```markdown
46
- * [##{github.pr_json[:number]}](#{github.pr_json[:html_url]}): #{github.pr_title} - [@#{github.pr_author}](https://github.com/#{github.pr_author}).
51
+ #{Danger::Changelog::ChangelogLine.example(github)}
47
52
  ```
48
53
  MARKDOWN
49
54
  warn "Unless you're refactoring existing code, please update #{filename}.", sticky: false
@@ -65,7 +70,7 @@ MARKDOWN
65
70
  messaging.fail("Please put back the `* Your contribution here.` line into #{filename}.", sticky: false) unless changelog_file.your_contribution_here?
66
71
  changelog_file.good?
67
72
  else
68
- messaging.fail('The #{filename} file does not exist.', sticky: false)
73
+ messaging.fail("The #{filename} file does not exist.", sticky: false)
69
74
  false
70
75
  end
71
76
  end
data/lib/danger_plugin.rb CHANGED
@@ -1,2 +1,3 @@
1
+ require 'changelog/changelog_line'
1
2
  require 'changelog/changelog_file'
2
3
  require 'changelog/plugin'
@@ -14,19 +14,6 @@ describe Danger::Changelog::ChangelogFile do
14
14
  expect(subject.bad_lines).to eq []
15
15
  expect(subject.bad_lines?).to be false
16
16
  end
17
- it 'valid lines' do
18
- expect(subject.send(:valid_line?, '* Reticluated spline - [@dblock](https://github.com/dblock).')).to be true
19
- expect(subject.send(:valid_line?, '* [#1](https://github.com/dblock/danger-changelog/pull/1): Reticluated spline - [@dblock](https://github.com/dblock).')).to be true
20
- end
21
- it 'invalid lines' do
22
- expect(subject.send(:valid_line?, 'Missing star - [@dblock](https://github.com/dblock).')).to be false
23
- expect(subject.send(:valid_line?, '* [#1](https://github.com/dblock/danger-changelog/pull/1) - Not a colon - [@dblock](https://github.com/dblock).')).to be false
24
- expect(subject.send(:valid_line?, '* [#1](https://github.com/dblock/danger-changelog/pull/1): No dash [@dblock](https://github.com/dblock).')).to be false
25
- expect(subject.send(:valid_line?, '* [#1](https://github.com/dblock/danger-changelog/pull/1): No final period - [@dblock](https://github.com/dblock)')).to be false
26
- expect(subject.send(:valid_line?, '* [#1](https://github.com/dblock/danger-changelog/pull/1): No name.')).to be false
27
- expect(subject.send(:valid_line?, '* [#1](https://github.com/dblock/danger-changelog/pull/1): No https in github - [@dblock](http://github.com/dblock).')).to be false
28
- expect(subject.send(:valid_line?, '* [#1](https://github.com/dblock/danger-changelog/pull/1): Extra trailing slash - [@dblock](https://github.com/dblock/).')).to be false
29
- end
30
17
  it 'is valid' do
31
18
  expect(subject.bad_lines?).to be false
32
19
  end
@@ -0,0 +1,45 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe Danger::Changelog::ChangelogLine do
4
+ context 'lines' do
5
+ it 'valid lines' do
6
+ expect(subject.valid?('* Reticluated spline - [@dblock](https://github.com/dblock).')).to be true
7
+ expect(subject.valid?('* [#1](https://github.com/dblock/danger-changelog/pull/1): Reticluated spline - [@dblock](https://github.com/dblock).')).to be true
8
+ end
9
+ it 'invalid lines' do
10
+ expect(subject.valid?('Missing star - [@dblock](https://github.com/dblock).')).to be false
11
+ expect(subject.valid?('* [#1](https://github.com/dblock/danger-changelog/pull/1) - Not a colon - [@dblock](https://github.com/dblock).')).to be false
12
+ expect(subject.valid?('* [#1](https://github.com/dblock/danger-changelog/pull/1): No dash [@dblock](https://github.com/dblock).')).to be false
13
+ expect(subject.valid?('* [#1](https://github.com/dblock/danger-changelog/pull/1): No final period - [@dblock](https://github.com/dblock)')).to be false
14
+ expect(subject.valid?('* [#1](https://github.com/dblock/danger-changelog/pull/1): No name.')).to be false
15
+ expect(subject.valid?('* [#1](https://github.com/dblock/danger-changelog/pull/1): No https in github - [@dblock](http://github.com/dblock).')).to be false
16
+ expect(subject.valid?('* [#1](https://github.com/dblock/danger-changelog/pull/1): Extra trailing slash - [@dblock](https://github.com/dblock/).')).to be false
17
+ end
18
+ end
19
+ context 'example' do
20
+ let(:github) do
21
+ double(Danger::RequestSources::GitHub,
22
+ pr_json: { 'number' => 123, 'html_url' => 'https://github.com/dblock/danger-changelog/pull/123' },
23
+ pr_author: 'dblock',
24
+ pr_title: pr_title)
25
+ end
26
+ context 'no transformation required' do
27
+ let(:pr_title) { 'Test' }
28
+ it 'uses title as is' do
29
+ expect(subject.example(github)).to eq '* [#123](https://github.com/dblock/danger-changelog/pull/123): Test - [@dblock](https://github.com/dblock).'
30
+ end
31
+ end
32
+ context 'with lowercase title' do
33
+ let(:pr_title) { 'test' }
34
+ it 'capitalizes it' do
35
+ expect(subject.example(github)).to eq '* [#123](https://github.com/dblock/danger-changelog/pull/123): Test - [@dblock](https://github.com/dblock).'
36
+ end
37
+ end
38
+ context 'with a trailing period' do
39
+ let(:pr_title) { 'Test.' }
40
+ it 'removes it' do
41
+ expect(subject.example(github)).to eq '* [#123](https://github.com/dblock/danger-changelog/pull/123): Test - [@dblock](https://github.com/dblock).'
42
+ end
43
+ end
44
+ end
45
+ end
@@ -18,11 +18,11 @@ describe Danger::Changelog do
18
18
  before do
19
19
  # typical PR JSON looks like https://raw.githubusercontent.com/danger/danger/bffc246a11dac883d76fc6636319bd6c2acd58a3/spec/fixtures/pr_response.json
20
20
  changelog.env.request_source.pr_json = {
21
- number: 123,
22
- title: 'being dangerous',
23
- html_url: 'https://github.com/dblock/danger-changelog/pull/123',
24
- user: {
25
- login: 'dblock'
21
+ 'number' => 123,
22
+ 'title' => 'being dangerous',
23
+ 'html_url' => 'https://github.com/dblock/danger-changelog/pull/123',
24
+ 'user' => {
25
+ 'login' => 'dblock'
26
26
  }
27
27
  }
28
28
  end
@@ -42,7 +42,7 @@ describe Danger::Changelog do
42
42
  expect(subject).to be false
43
43
  expect(status_report[:errors]).to eq []
44
44
  expect(status_report[:warnings]).to eq ["Unless you're refactoring existing code, please update #{filename}."]
45
- expect(status_report[:markdowns]).to eq ["Here's an example of a #{filename} entry:\n\n```markdown\n* [#123](https://github.com/dblock/danger-changelog/pull/123): being dangerous - [@dblock](https://github.com/dblock).\n```\n"]
45
+ expect(status_report[:markdowns].map(&:message)).to eq ["Here's an example of a #{filename} entry:\n\n```markdown\n* [#123](https://github.com/dblock/danger-changelog/pull/123): Being dangerous - [@dblock](https://github.com/dblock).\n```\n"]
46
46
  end
47
47
  end
48
48
 
@@ -80,6 +80,14 @@ describe Danger::Changelog do
80
80
  changelog.is_changelog_format_correct?
81
81
  end
82
82
 
83
+ context 'without a CHANGELOG file' do
84
+ let(:filename) { 'does-not-exist' }
85
+ it 'complains' do
86
+ expect(subject).to be false
87
+ expect(status_report[:errors]).to eq ['The does-not-exist file does not exist.']
88
+ end
89
+ end
90
+
83
91
  context 'with CHANGELOG changes' do
84
92
  before do
85
93
  allow(changelog.git).to receive(:modified_files).and_return([filename])
@@ -119,7 +127,7 @@ describe Danger::Changelog do
119
127
  expect(subject).to be false
120
128
  expect(status_report[:errors]).to eq ["One of the lines below found in #{filename} doesn't match the expected format. Please make it look like the other lines, pay attention to periods and spaces."]
121
129
  expect(status_report[:warnings]).to eq []
122
- expect(status_report[:markdowns]).to eq [
130
+ expect(status_report[:markdowns].map(&:message)).to eq [
123
131
  "```markdown\n* [#1](https://github.com/dblock/danger-changelog/pull/1) - Not a colon - [@dblock](https://github.com/dblock).\n```\n",
124
132
  "```markdown\n* [#1](https://github.com/dblock/danger-changelog/pull/1): No final period - [@dblock](https://github.com/dblock)\n```\n"
125
133
  ]
data/spec/spec_helper.rb CHANGED
@@ -9,7 +9,6 @@ require 'pry'
9
9
  require 'rspec'
10
10
  require 'danger'
11
11
 
12
- # Use coloured output, it's the best.
13
12
  RSpec.configure do |config|
14
13
  config.filter_gems_from_backtrace 'bundler'
15
14
  config.color = true
@@ -18,30 +17,10 @@ end
18
17
 
19
18
  require 'danger_plugin'
20
19
 
21
- # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
22
- # If you are expanding these files, see if it's already been done ^.
23
-
24
- # A silent version of the user interface,
25
- # it comes with an extra function `.string` which will
26
- # strip all ANSI colours from the string.
27
-
28
- # rubocop:disable Lint/NestedMethodDefinition
29
20
  def testing_ui
30
- @output = StringIO.new
31
- def @output.winsize
32
- [20, 9999]
33
- end
34
-
35
- cork = Cork::Board.new(out: @output)
36
- def cork.string
37
- out.string.gsub(/\e\[([;\d]+)?m/, '')
38
- end
39
- cork
21
+ Cork::Board.new(silent: true)
40
22
  end
41
- # rubocop:enable Lint/NestedMethodDefinition
42
23
 
43
- # Example environment (ENV) that would come from
44
- # running a PR on TravisCI
45
24
  def testing_env
46
25
  {
47
26
  'HAS_JOSH_K_SEAL_OF_APPROVAL' => 'true',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-changelog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - dblock
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-26 00:00:00.000000000 Z
11
+ date: 2016-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api
@@ -174,11 +174,13 @@ files:
174
174
  - images/have_you_updated_changelog.png
175
175
  - images/is_changelog_format_correct.png
176
176
  - lib/changelog/changelog_file.rb
177
+ - lib/changelog/changelog_line.rb
177
178
  - lib/changelog/gem_version.rb
178
179
  - lib/changelog/plugin.rb
179
180
  - lib/danger_changelog.rb
180
181
  - lib/danger_plugin.rb
181
182
  - spec/changelog_file_spec.rb
183
+ - spec/changelog_line_spec.rb
182
184
  - spec/changelog_spec.rb
183
185
  - spec/fixtures/changelogs/minimal.md
184
186
  - spec/fixtures/changelogs/missing_your_contribution_here.md
@@ -204,12 +206,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
206
  version: '0'
205
207
  requirements: []
206
208
  rubyforge_project:
207
- rubygems_version: 2.6.4
209
+ rubygems_version: 2.6.7
208
210
  signing_key:
209
211
  specification_version: 4
210
212
  summary: A danger.systems plugin that is OCD about your CHANGELOG.
211
213
  test_files:
212
214
  - spec/changelog_file_spec.rb
215
+ - spec/changelog_line_spec.rb
213
216
  - spec/changelog_spec.rb
214
217
  - spec/fixtures/changelogs/minimal.md
215
218
  - spec/fixtures/changelogs/missing_your_contribution_here.md