danger-changelog 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f8593deb38bfbe15247c55c9b28f149248f7c4d7
4
+ data.tar.gz: 8905154e4f917190f212f83b312394905024cabc
5
+ SHA512:
6
+ metadata.gz: e94967c180e24f33d89c908633d67de0df70e433696a3856a9c4c93b8e79b9a59a5c90ef33a3c64cc727a0184b179d782db16d6a01fd65295f29670f929393af
7
+ data.tar.gz: a2ea235027bc568fc141ddd6e0e391688d96437ed090f4164c7211bedfa334c6eacb2d73da7bd0e554fad2d8dd009b9bda29e2990e8df5ee1fecc23ef83ca059
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ pkg
3
+ .idea/
4
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format=documentation
data/.rubocop.yml ADDED
@@ -0,0 +1,7 @@
1
+ AllCops:
2
+ Include:
3
+ - Rakefile
4
+ Exclude:
5
+ - vendor/**/*
6
+
7
+ inherit_from: .rubocop_todo.yml
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,44 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-08-26 16:59:39 -0400 using RuboCop version 0.42.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 2
10
+ Metrics/AbcSize:
11
+ Max: 18
12
+
13
+ # Offense count: 26
14
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
15
+ # URISchemes: http, https
16
+ Metrics/LineLength:
17
+ Max: 240
18
+
19
+ # Offense count: 3
20
+ # Configuration parameters: CountComments.
21
+ Metrics/MethodLength:
22
+ Max: 14
23
+
24
+ # Offense count: 1
25
+ Style/Documentation:
26
+ Exclude:
27
+ - 'spec/**/*'
28
+ - 'test/**/*'
29
+ - 'lib/changelog/plugin.rb'
30
+
31
+ # Offense count: 3
32
+ Style/DoubleNegation:
33
+ Exclude:
34
+ - 'lib/changelog/changelog_file.rb'
35
+
36
+ # Offense count: 2
37
+ # Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
38
+ # NamePrefix: is_, has_, have_
39
+ # NamePrefixBlacklist: is_, has_, have_
40
+ # NameWhitelist: is_a?
41
+ Style/PredicateName:
42
+ Exclude:
43
+ - 'spec/**/*'
44
+ - 'lib/changelog/plugin.rb'
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+
3
+ cache:
4
+ directories:
5
+ - bundle
6
+
7
+ rvm:
8
+ - 2.3.1
9
+
10
+ before_script:
11
+ - bundle exec danger
12
+
13
+ script:
14
+ - bundle exec rake spec
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ ## Changelog
2
+
3
+ ### 0.1.0 (8/26/2016)
4
+
5
+ * [#2](https://github.com/dblock/danger-changelog/pull/2): Added `is_changelog_format_correct?` - [@dblock](https://github.com/dblock).
6
+ * [#1](https://github.com/dblock/danger-changelog/pull/1): Added `have_you_updated_changelog?`, have you updated CHANGELOG.md? - [@dblock](https://github.com/dblock).
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,125 @@
1
+ # Contributing to Danger-Changelog
2
+
3
+ This project is work of [many contributors](https://github.com/dblock/danger-changelog/graphs/contributors).
4
+
5
+ You're encouraged to submit [pull requests](https://github.com/dblock/danger-changelog/pulls), [propose features and discuss issues](https://github.com/dblock/danger-changelog/issues).
6
+
7
+ In the examples below, substitute your Github username for `contributor` in URLs.
8
+
9
+ ### Fork the Project
10
+
11
+ Fork the [project on Github](https://github.com/dblock/danger-changelog) and check out your copy.
12
+
13
+ ```
14
+ git clone https://github.com/contributor/danger-changelog.git
15
+ cd danger-changelog
16
+ git remote add upstream https://github.com/dblock/danger-changelog.git
17
+ ```
18
+
19
+ ### Bundle Install and Test
20
+
21
+ Ensure that you can build the project and run tests.
22
+
23
+ ```
24
+ bundle install
25
+ bundle exec rake
26
+ ```
27
+
28
+ ## Contribute Code
29
+
30
+ ### Create a Topic Branch
31
+
32
+ Make sure your fork is up-to-date and create a topic branch for your feature or bug fix.
33
+
34
+ ```
35
+ git checkout master
36
+ git pull upstream master
37
+ git checkout -b my-feature-branch
38
+ ```
39
+
40
+ ### Write Tests
41
+
42
+ Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build. Add tests to [spec](spec).
43
+
44
+ We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix.
45
+
46
+ ### Write Code
47
+
48
+ Implement your feature or bug fix.
49
+
50
+ Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop). Run `bundle exec rubocop` and fix any style issues highlighted, auto-correct issues when possible with `bundle exec rubocop -a`. To silence generally ingored issues, including line lengths or code complexity metrics, run `bundle exec rubocop --auto-gen-config`.
51
+
52
+ Make sure that `bundle exec rake` completes without errors.
53
+
54
+ ### Write Documentation
55
+
56
+ Document any external behavior in the [README](README.md).
57
+
58
+ ### Update Changelog
59
+
60
+ Add a line to [CHANGELOG](CHANGELOG.md) under *Next Release*. Don't remove *Your contribution here*.
61
+
62
+ Make it look like every other line, including a link to the issue being fixed, your name and link to your Github account.
63
+
64
+ ### Commit Changes
65
+
66
+ Make sure git knows your name and email address:
67
+
68
+ ```
69
+ git config --global user.name "Your Name"
70
+ git config --global user.email "contributor@example.com"
71
+ ```
72
+
73
+ Writing good commit logs is important. A commit log should describe what changed and why.
74
+
75
+ ```
76
+ git add ...
77
+ git commit
78
+ ```
79
+
80
+ ### Push
81
+
82
+ ```
83
+ git push origin my-feature-branch
84
+ ```
85
+
86
+ ### Make a Pull Request
87
+
88
+ Go to https://github.com/contributor/danger-changelog and select your feature branch. Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.
89
+
90
+ ### Update CHANGELOG Again
91
+
92
+ Update the [CHANGELOG](CHANGELOG.md) with the pull request number. A typical entry looks as follows.
93
+
94
+ ```
95
+ * [#123](https://github.com/dblock/danger-changelog/pull/123): Reticulated splines - [@contributor](https://github.com/contributor).
96
+ ```
97
+
98
+ Amend your previous commit and force push the changes.
99
+
100
+ ```
101
+ git commit --amend
102
+ git push origin my-feature-branch -f
103
+ ```
104
+
105
+ ### Rebase
106
+
107
+ If you've been working on a change for a while, rebase with upstream/master.
108
+
109
+ ```
110
+ git fetch upstream
111
+ git rebase upstream/master
112
+ git push origin my-feature-branch -f
113
+ ```
114
+
115
+ ### Check on Your Pull Request
116
+
117
+ Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above.
118
+
119
+ ### Be Patient
120
+
121
+ It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang on there!
122
+
123
+ ## Thank You
124
+
125
+ Please do know that we really appreciate and value your time and work. We love you, really.
data/Dangerfile ADDED
@@ -0,0 +1,3 @@
1
+ # danger.systems
2
+
3
+ changelog.check
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,19 @@
1
+ # A guardfile for making Danger Plugins
2
+ # For more info see https://github.com/guard/guard#readme
3
+
4
+ # To run, use `bundle exec guard`.
5
+
6
+ guard :rspec, cmd: 'bundle exec rspec' do
7
+ require 'guard/rspec/dsl'
8
+ dsl = Guard::RSpec::Dsl.new(self)
9
+
10
+ # RSpec files
11
+ rspec = dsl.rspec
12
+ watch(rspec.spec_helper) { rspec.spec_dir }
13
+ watch(rspec.spec_support) { rspec.spec_dir }
14
+ watch(rspec.spec_files)
15
+
16
+ # Ruby files
17
+ ruby = dsl.ruby
18
+ dsl.watch_spec_files_for(ruby.lib_files)
19
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Daniel Doubrovkine <dblock@dblock.org>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # danger-changelog
2
+
3
+ A PR linter plugin to [danger.systems](http://danger.systems) that is OCD about your CHANGELOG format.
4
+
5
+ [![Build Status](https://travis-ci.org/dblock/danger-changelog.svg?branch=master)](https://travis-ci.org/dblock/danger-changelog)
6
+
7
+ ## Installation
8
+
9
+ Add `danger-changelog` to your Gemfile.
10
+
11
+ ```
12
+ gem 'danger-changelog', '~> 0.1'
13
+ ```
14
+
15
+ Add `changelog.check` to your Dangerfile. Make a pull request and see this plugin in action.
16
+
17
+ ## Usage
18
+
19
+ Methods and attributes from this plugin are available in your `Dangerfile` under the `changelog` namespace.
20
+
21
+ ### changelog.filename
22
+
23
+ Set the CHANGELOG file name, defaults to `CHANGELOG.md`.
24
+
25
+ ### changelog.check
26
+
27
+ Run all checks with defaults.
28
+
29
+ #### changelog.have_you_updated_changelog?
30
+
31
+ Checks whether you have updated CHANGELOG.md.
32
+
33
+ ![](images/have_you_updated_changelog.png)
34
+
35
+ #### changelog.is_changelog_format_correct?
36
+
37
+ Checks whether the CHANGELOG format is correct.
38
+
39
+ ![](images/is_changelog_format_correct.png)
40
+
41
+ ## Contributing
42
+
43
+ See [CONTRIBUTING](CONTRIBUTING.md).
44
+
45
+ ## Copyright
46
+
47
+ Copyright (c) Daniel Doubrovkine, 2016
48
+
49
+ MIT License, see [LICENSE](LICENSE.txt) for details.
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:specs)
6
+
7
+ task default: [:rubocop, :specs]
8
+
9
+ task :spec do
10
+ Rake::Task['specs'].invoke
11
+ Rake::Task['rubocop'].invoke
12
+ Rake::Task['spec_docs'].invoke
13
+ end
14
+
15
+ desc 'Run RuboCop on the lib/specs directory'
16
+ RuboCop::RakeTask.new(:rubocop) do |task|
17
+ task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
18
+ end
19
+
20
+ desc 'Ensure that the plugin passes `danger plugins lint`'
21
+ task :spec_docs do
22
+ sh 'bundle exec danger plugins lint'
23
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'changelog/gem_version.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'danger-changelog'
8
+ spec.version = Changelog::VERSION
9
+ spec.authors = ['dblock']
10
+ spec.email = ['dblock@dblock.org']
11
+ spec.description = 'A danger.systems plugin that is OCD about your CHANGELOG.'
12
+ spec.summary = 'A danger.systems plugin that is OCD about your CHANGELOG.'
13
+ spec.homepage = 'https://github.com/dblock/danger-changelog'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.4'
26
+ spec.add_development_dependency 'rubocop', '~> 0.41'
27
+ spec.add_development_dependency 'yard', '~> 0.8'
28
+ spec.add_development_dependency 'guard', '~> 2.14'
29
+ spec.add_development_dependency 'guard-rspec', '~> 4.7'
30
+ spec.add_development_dependency 'listen', '3.0.7'
31
+ spec.add_development_dependency 'pry'
32
+ end
@@ -0,0 +1,61 @@
1
+ module Danger
2
+ module Changelog
3
+ # A CHANGELOG.md file reader.
4
+ class ChangelogFile
5
+ attr_reader :filename, :bad_lines, :exists
6
+
7
+ def initialize(filename = 'CHANGELOG.md')
8
+ @filename = filename
9
+ @exists = File.exist?(filename)
10
+ parse if @exists
11
+ end
12
+
13
+ # Any bad_lines?
14
+ def bad_lines?
15
+ !!bad_lines && bad_lines.any?
16
+ end
17
+
18
+ def exists?
19
+ !!@exists
20
+ end
21
+
22
+ def your_contribution_here?
23
+ !!@your_contribution_here
24
+ end
25
+
26
+ def bad?
27
+ bad_lines? || !your_contribution_here?
28
+ end
29
+
30
+ def good?
31
+ !bad?
32
+ end
33
+
34
+ private
35
+
36
+ # Parse CHANGELOG file.
37
+ def parse
38
+ @your_contribution_here = false
39
+ @bad_lines = []
40
+ File.open(filename).each_line do |line|
41
+ # ignore lines that aren't changes
42
+ next unless line[0] == '*'
43
+ # notice your contribution here
44
+ if line == "* Your contribution here.\n"
45
+ @your_contribution_here = true
46
+ next
47
+ end
48
+ next if valid_line?(line)
49
+ @bad_lines << line
50
+ end
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
+ end
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ module Changelog
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,73 @@
1
+ module Danger
2
+ # CHANGELOG OCD in your projects.
3
+ #
4
+ # @example Checking for everuthing
5
+ #
6
+ # changelog.check
7
+ #
8
+ # @see dblock/danger-changelog
9
+ # @tags changelog
10
+
11
+ class DangerChangelog < Plugin
12
+ # Sets the CHANGELOG file name.
13
+ # defaults to `CHANGELOG.md`.
14
+ #
15
+ # @return [String]
16
+ attr_accessor :filename
17
+
18
+ def initialize(dangerfile)
19
+ @filename = 'CHANGELOG.md'
20
+ super
21
+ end
22
+
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.
30
+ # @return [void]
31
+ def check
32
+ have_you_updated_changelog?
33
+ is_changelog_format_correct?
34
+ end
35
+
36
+ # Have you updated CHANGELOG.md?
37
+ # @return [boolean]
38
+ def have_you_updated_changelog?
39
+ if changelog_changes?
40
+ true
41
+ else
42
+ markdown <<-MARKDOWN
43
+ Here's an example of a #{filename} entry:
44
+
45
+ ```markdown
46
+ * [##{github.pr_json[:number]}](#{github.pr_json[:html_url]}): #{github.pr_title} - [@#{github.pr_author}](https://github.com/#{github.pr_author}).
47
+ ```
48
+ MARKDOWN
49
+ warn "Unless you're refactoring existing code, please update #{filename}.", sticky: false
50
+ false
51
+ end
52
+ end
53
+
54
+ # Is the CHANGELOG.md format correct?
55
+ def is_changelog_format_correct?
56
+ changelog_file = Danger::Changelog::ChangelogFile.new(filename)
57
+ if changelog_file.exists?
58
+ changelog_file.bad_lines.each do |line|
59
+ markdown <<-MARKDOWN
60
+ ```markdown
61
+ #{line}```
62
+ MARKDOWN
63
+ end
64
+ messaging.fail("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.", sticky: false) if changelog_file.bad_lines?
65
+ messaging.fail("Please put back the `* Your contribution here.` line into #{filename}.", sticky: false) unless changelog_file.your_contribution_here?
66
+ changelog_file.good?
67
+ else
68
+ messaging.fail('The #{filename} file does not exist.', sticky: false)
69
+ false
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1 @@
1
+ require 'changelog/gem_version'
@@ -0,0 +1,2 @@
1
+ require 'changelog/changelog_file'
2
+ require 'changelog/plugin'
@@ -0,0 +1,71 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe Danger::Changelog::ChangelogFile do
4
+ let(:filename) { 'CHANGELOG.md' }
5
+ subject do
6
+ Danger::Changelog::ChangelogFile.new(filename)
7
+ end
8
+ context 'minimal example' do
9
+ let(:filename) { File.expand_path('../fixtures/changelogs/minimal.md', __FILE__) }
10
+ it 'exists?' do
11
+ expect(subject.exists?).to be true
12
+ end
13
+ it 'bad_lines?' do
14
+ expect(subject.bad_lines).to eq []
15
+ expect(subject.bad_lines?).to be false
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
+ it 'is valid' do
31
+ expect(subject.bad_lines?).to be false
32
+ end
33
+ it 'has your contribution here' do
34
+ expect(subject.your_contribution_here?).to be true
35
+ end
36
+ end
37
+ context 'missing your contribution here' do
38
+ let(:filename) { File.expand_path('../fixtures/changelogs/missing_your_contribution_here.md', __FILE__) }
39
+ it 'is valid' do
40
+ expect(subject.bad_lines?).to be false
41
+ end
42
+ it 'is missing your contribution here' do
43
+ expect(subject.your_contribution_here?).to be false
44
+ end
45
+ end
46
+ context 'does not exist' do
47
+ let(:filename) { 'whatever.md' }
48
+ it 'exists?' do
49
+ expect(subject.exists?).to be false
50
+ end
51
+ it 'bad_lines?' do
52
+ expect(subject.bad_lines).to be nil
53
+ expect(subject.bad_lines?).to be false
54
+ end
55
+ end
56
+ context 'with bad lines' do
57
+ let(:filename) { File.expand_path('../fixtures/changelogs/with_bad_lines.md', __FILE__) }
58
+ it 'is not valid' do
59
+ expect(subject.bad_lines?).to be true
60
+ end
61
+ it 'reports all bad lines' do
62
+ expect(subject.bad_lines).to eq [
63
+ "* [#1](https://github.com/dblock/danger-changelog/pull/1) - Not a colon - [@dblock](https://github.com/dblock).\n",
64
+ "* [#1](https://github.com/dblock/danger-changelog/pull/1): No final period - [@dblock](https://github.com/dblock)\n"
65
+ ]
66
+ end
67
+ it 'has your contribution here' do
68
+ expect(subject.your_contribution_here?).to be true
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,132 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe Danger::Changelog do
4
+ it 'is a Danger plugin' do
5
+ expect(Danger::DangerChangelog.new(nil)).to be_a Danger::Plugin
6
+ end
7
+
8
+ describe 'with Dangerfile' do
9
+ let(:filename) { File.expand_path('../fixtures/changelogs/minimal.md', __FILE__) }
10
+ let(:dangerfile) { testing_dangerfile }
11
+ let(:changelog) do
12
+ dangerfile.changelog.filename = filename
13
+ dangerfile.changelog
14
+ end
15
+ let(:status_report) { changelog.status_report }
16
+
17
+ describe 'in a PR' do
18
+ before do
19
+ # typical PR JSON looks like https://raw.githubusercontent.com/danger/danger/bffc246a11dac883d76fc6636319bd6c2acd58a3/spec/fixtures/pr_response.json
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'
26
+ }
27
+ }
28
+ end
29
+
30
+ context 'have_you_updated_changelog?' do
31
+ subject do
32
+ changelog.have_you_updated_changelog?
33
+ end
34
+
35
+ context 'without CHANGELOG changes' do
36
+ before do
37
+ allow(changelog.git).to receive(:modified_files).and_return([])
38
+ allow(changelog.git).to receive(:added_files).and_return([])
39
+ end
40
+
41
+ it 'complains when no CHANGELOG can be found' do
42
+ expect(subject).to be false
43
+ expect(status_report[:errors]).to eq []
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"]
46
+ end
47
+ end
48
+
49
+ context 'with a new CHANGELOG' do
50
+ before do
51
+ allow(changelog.git).to receive(:modified_files).and_return([])
52
+ allow(changelog.git).to receive(:added_files).and_return([filename])
53
+ end
54
+
55
+ it 'has no complaints' do
56
+ expect(subject).to be true
57
+ expect(status_report[:errors]).to eq []
58
+ expect(status_report[:warnings]).to eq []
59
+ expect(status_report[:markdowns]).to eq []
60
+ end
61
+ end
62
+
63
+ context 'with CHANGELOG changes' do
64
+ before do
65
+ allow(changelog.git).to receive(:modified_files).and_return([filename])
66
+ allow(changelog.git).to receive(:added_files).and_return([])
67
+ end
68
+
69
+ it 'has no complaints' do
70
+ expect(subject).to be true
71
+ expect(status_report[:errors]).to eq []
72
+ expect(status_report[:warnings]).to eq []
73
+ expect(status_report[:markdowns]).to eq []
74
+ end
75
+ end
76
+ end
77
+
78
+ context 'is_changelog_format_correct?' do
79
+ subject do
80
+ changelog.is_changelog_format_correct?
81
+ end
82
+
83
+ context 'with CHANGELOG changes' do
84
+ before do
85
+ allow(changelog.git).to receive(:modified_files).and_return([filename])
86
+ allow(changelog.git).to receive(:added_files).and_return([])
87
+ end
88
+
89
+ it 'has no complaints' do
90
+ expect(subject).to be true
91
+ expect(status_report[:errors]).to eq []
92
+ expect(status_report[:warnings]).to eq []
93
+ expect(status_report[:markdowns]).to eq []
94
+ end
95
+
96
+ context 'missing your contribution here' do
97
+ let(:filename) { File.expand_path('../fixtures/changelogs/missing_your_contribution_here.md', __FILE__) }
98
+ it 'complains' do
99
+ expect(subject).to be false
100
+ expect(status_report[:errors]).to eq ["Please put back the `* Your contribution here.` line into #{filename}."]
101
+ expect(status_report[:warnings]).to eq []
102
+ expect(status_report[:markdowns]).to eq []
103
+ end
104
+ end
105
+
106
+ context 'minimal example' do
107
+ let(:filename) { File.expand_path('../fixtures/changelogs/minimal.md', __FILE__) }
108
+ it 'is ok' do
109
+ expect(subject).to be true
110
+ expect(status_report[:errors]).to eq []
111
+ expect(status_report[:warnings]).to eq []
112
+ expect(status_report[:markdowns]).to eq []
113
+ end
114
+ end
115
+
116
+ context 'with bad lines' do
117
+ let(:filename) { File.expand_path('../fixtures/changelogs/with_bad_lines.md', __FILE__) }
118
+ it 'complains' do
119
+ expect(subject).to be false
120
+ 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
+ expect(status_report[:warnings]).to eq []
122
+ expect(status_report[:markdowns]).to eq [
123
+ "```markdown\n* [#1](https://github.com/dblock/danger-changelog/pull/1) - Not a colon - [@dblock](https://github.com/dblock).\n```\n",
124
+ "```markdown\n* [#1](https://github.com/dblock/danger-changelog/pull/1): No final period - [@dblock](https://github.com/dblock)\n```\n"
125
+ ]
126
+ end
127
+ end
128
+ end
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,3 @@
1
+ ### Changelog
2
+
3
+ * Your contribution here.
@@ -0,0 +1,2 @@
1
+ ### Changelog
2
+
@@ -0,0 +1,6 @@
1
+ ### Changelog
2
+
3
+ Missing star - [@dblock](https://github.com/dblock).
4
+ * [#1](https://github.com/dblock/danger-changelog/pull/1) - Not a colon - [@dblock](https://github.com/dblock).
5
+ * [#1](https://github.com/dblock/danger-changelog/pull/1): No final period - [@dblock](https://github.com/dblock)
6
+ * Your contribution here.
@@ -0,0 +1,59 @@
1
+ require 'pathname'
2
+ ROOT = Pathname.new(File.expand_path('../../', __FILE__))
3
+ $LOAD_PATH.unshift((ROOT + 'lib').to_s)
4
+ $LOAD_PATH.unshift((ROOT + 'spec').to_s)
5
+
6
+ require 'bundler/setup'
7
+ require 'pry'
8
+
9
+ require 'rspec'
10
+ require 'danger'
11
+
12
+ # Use coloured output, it's the best.
13
+ RSpec.configure do |config|
14
+ config.filter_gems_from_backtrace 'bundler'
15
+ config.color = true
16
+ config.tty = true
17
+ end
18
+
19
+ require 'danger_plugin'
20
+
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
+ 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
40
+ end
41
+ # rubocop:enable Lint/NestedMethodDefinition
42
+
43
+ # Example environment (ENV) that would come from
44
+ # running a PR on TravisCI
45
+ def testing_env
46
+ {
47
+ 'HAS_JOSH_K_SEAL_OF_APPROVAL' => 'true',
48
+ 'TRAVIS_PULL_REQUEST' => '800',
49
+ 'TRAVIS_REPO_SLUG' => 'dblock/danger-changelog',
50
+ 'TRAVIS_COMMIT_RANGE' => '759adcbd0d8f...13c4dc8bb61d',
51
+ 'DANGER_GITHUB_API_TOKEN' => '123sbdq54erfsd3422gdfio'
52
+ }
53
+ end
54
+
55
+ # A stubbed out Dangerfile for use in tests
56
+ def testing_dangerfile
57
+ env = Danger::EnvironmentManager.new(testing_env)
58
+ Danger::Dangerfile.new(env, testing_ui)
59
+ end
metadata ADDED
@@ -0,0 +1,217 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danger-changelog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - dblock
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: danger-plugin-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.41'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.41'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.8'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.8'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.14'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.14'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '4.7'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '4.7'
125
+ - !ruby/object:Gem::Dependency
126
+ name: listen
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '='
130
+ - !ruby/object:Gem::Version
131
+ version: 3.0.7
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '='
137
+ - !ruby/object:Gem::Version
138
+ version: 3.0.7
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: A danger.systems plugin that is OCD about your CHANGELOG.
154
+ email:
155
+ - dblock@dblock.org
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".rspec"
162
+ - ".rubocop.yml"
163
+ - ".rubocop_todo.yml"
164
+ - ".travis.yml"
165
+ - CHANGELOG.md
166
+ - CONTRIBUTING.md
167
+ - Dangerfile
168
+ - Gemfile
169
+ - Guardfile
170
+ - LICENSE.txt
171
+ - README.md
172
+ - Rakefile
173
+ - danger-changelog.gemspec
174
+ - images/have_you_updated_changelog.png
175
+ - images/is_changelog_format_correct.png
176
+ - lib/changelog/changelog_file.rb
177
+ - lib/changelog/gem_version.rb
178
+ - lib/changelog/plugin.rb
179
+ - lib/danger_changelog.rb
180
+ - lib/danger_plugin.rb
181
+ - spec/changelog_file_spec.rb
182
+ - spec/changelog_spec.rb
183
+ - spec/fixtures/changelogs/minimal.md
184
+ - spec/fixtures/changelogs/missing_your_contribution_here.md
185
+ - spec/fixtures/changelogs/with_bad_lines.md
186
+ - spec/spec_helper.rb
187
+ homepage: https://github.com/dblock/danger-changelog
188
+ licenses:
189
+ - MIT
190
+ metadata: {}
191
+ post_install_message:
192
+ rdoc_options: []
193
+ require_paths:
194
+ - lib
195
+ required_ruby_version: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - ">="
198
+ - !ruby/object:Gem::Version
199
+ version: '0'
200
+ required_rubygems_version: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - ">="
203
+ - !ruby/object:Gem::Version
204
+ version: '0'
205
+ requirements: []
206
+ rubyforge_project:
207
+ rubygems_version: 2.6.4
208
+ signing_key:
209
+ specification_version: 4
210
+ summary: A danger.systems plugin that is OCD about your CHANGELOG.
211
+ test_files:
212
+ - spec/changelog_file_spec.rb
213
+ - spec/changelog_spec.rb
214
+ - spec/fixtures/changelogs/minimal.md
215
+ - spec/fixtures/changelogs/missing_your_contribution_here.md
216
+ - spec/fixtures/changelogs/with_bad_lines.md
217
+ - spec/spec_helper.rb