Skip to content

Commit

Permalink
Merge pull request #1 from dblock/changelog-changed
Browse files Browse the repository at this point in the history
Changelog changed?
  • Loading branch information
dblock authored Aug 26, 2016
2 parents 88d0023 + 711a592 commit 45f927f
Show file tree
Hide file tree
Showing 14 changed files with 155 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--format=documentation
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
inherit_from: .rubocop_todo.yml
39 changes: 39 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-08-26 14:48:21 -0400 using RuboCop version 0.42.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
Metrics/AbcSize:
Max: 16

# Offense count: 6
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
# URISchemes: http, https
Metrics/LineLength:
Max: 242

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 12

# Offense count: 1
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'lib/changelog/plugin.rb'

# Offense count: 2
# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
# NamePrefix: is_, has_, have_
# NamePrefixBlacklist: is_, has_, have_
# NameWhitelist: is_a?
Style/PredicateName:
Exclude:
- 'spec/**/*'
- 'lib/changelog/plugin.rb'
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

### 0.1.0 (Next)

* [#1](https://github.com/dblock/danger-changelog/pull/1): Added `have_you_updated_changelog?`, have you updated CHANGELOG.md? - [@dblock](https://github.com/dblock).
* Your contribution here.
3 changes: 3 additions & 0 deletions Dangerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# danger.systems

changelog.check
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in danger-changelog.gemspec
gemspec
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,25 @@

A plugin that is OCD about your CHANGELOG format.

[![Build Status](https://travis-ci.org/dblock/danger-changelog.svg?branch=master)](https://travis-ci.org/dblock/danger-changelog)

## Installation

$ gem install danger-changelog

## Usage

Methods and attributes from this plugin are available in
your `Dangerfile` under the `changelog` namespace.
Methods and attributes from this plugin are available in your `Dangerfile` under the `changelog` namespace.

### changelog.check

Run all checks with defaults.

### changelog.have_you_updated_changelog?

Checks whether you have updated CHANGELOG.md.

![](images/have_you_updated_changelog.png)

## Development

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require 'rubocop/rake_task'

RSpec::Core::RakeTask.new(:specs)

task default: :specs
task default: [:rubocop, :specs]

task :spec do
Rake::Task['specs'].invoke
Expand Down
10 changes: 5 additions & 5 deletions danger-changelog.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ Gem::Specification.new do |spec|
spec.version = Changelog::VERSION
spec.authors = ['dblock']
spec.email = ['[email protected]']
spec.description = %q{A danger.systems plugin that is OCD about your CHANGELOG.}
spec.summary = %q{A danger.systems plugin that is OCD about your CHANGELOG.}
spec.description = 'A danger.systems plugin that is OCD about your CHANGELOG.'
spec.summary = 'A danger.systems plugin that is OCD about your CHANGELOG.'
spec.homepage = 'https://github.com/dblock/danger-changelog'
spec.license = 'MIT'

spec.files = `git ls-files`.split($/)
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']
Expand All @@ -23,8 +23,8 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'bundler', '~> 1.3'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.4'
spec.add_development_dependency "rubocop", "~> 0.41"
spec.add_development_dependency "yard", "~> 0.8"
spec.add_development_dependency 'rubocop', '~> 0.41'
spec.add_development_dependency 'yard', '~> 0.8'
spec.add_development_dependency 'guard', '~> 2.14'
spec.add_development_dependency 'guard-rspec', '~> 4.7'
spec.add_development_dependency 'listen', '3.0.7'
Expand Down
Binary file added images/have_you_updated_changelog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/changelog/gem_version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Changelog
VERSION = "0.1.0".freeze
VERSION = '0.1.0'.freeze
end
38 changes: 38 additions & 0 deletions lib/changelog/plugin.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,42 @@
module Danger
# CHANGELOG OCD in your projects.
#
# @example Checking for everuthing
#
# changelog.check
#
# @see dblock/danger-changelog
# @tags changelog

class DangerChangelog < Plugin
# Has the CHANGELOG file been modified?
# @return [boolean]
def has_changelog_changes?
git.modified_files.include?('CHANGELOG.md')
end

# Runs all checks.
# @return [void]
def check
have_you_updated_changelog?
end

# Have you updated CHANGELOG.md?
# @return [boolean]
def have_you_updated_changelog?
if has_changelog_changes?
true
else
markdown <<-MARKDOWN
Here's an example of a CHANGELOG.md entry:
```markdown
* [##{github.pr_json[:number]}](#{github.pr_json[:html_url]}): #{github.pr_title} - [@#{github.pr_author}](https://github.com/#{github.pr_author}).
```
MARKDOWN
warn "Unless you're refactoring existing code, please update CHANGELOG.md.", sticky: false
false
end
end
end
end
50 changes: 46 additions & 4 deletions spec/changelog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,53 @@ module Danger
end

describe 'with Dangerfile' do
before do
@dangerfile = testing_dangerfile
@my_plugin = @dangerfile.my_plugin
let(:dangerfile) { testing_dangerfile }
let(:changelog) { testing_dangerfile.changelog }
let(:status_report) { changelog.status_report }

describe 'in a PR' do
before do
# typical PR JSON looks like https://raw.githubusercontent.com/danger/danger/bffc246a11dac883d76fc6636319bd6c2acd58a3/spec/fixtures/pr_response.json
changelog.env.request_source.pr_json = {
number: 123,
title: 'being dangerous',
html_url: 'https://github.com/dblock/danger-changelog/pull/123',
user: {
login: 'dblock'
}
}
end

context 'have_you_updated_changelog?' do
subject do
changelog.have_you_updated_changelog?
end

context 'without CHANGELOG changes' do
before do
allow(changelog.git).to receive(:modified_files).and_return([])
end

it 'complains when no CHANGELOG can be found' do
expect(subject).to be false
expect(status_report[:warnings]).to eq ["Unless you're refactoring existing code, please update CHANGELOG.md."]
expect(status_report[:markdowns]).to eq ["Here's an example of a CHANGELOG.md entry:\n\n```markdown\n* [#123](https://github.com/dblock/danger-changelog/pull/123): being dangerous - [@dblock](https://github.com/dblock).\n```\n"]
end
end

context 'with CHANGELOG changes' do
before do
allow(changelog.git).to receive(:modified_files).and_return(['CHANGELOG.md'])
end

it 'has no complaints' do
expect(subject).to be true
expect(status_report[:warnings]).to eq []
expect(status_report[:markdowns]).to eq []
end
end
end
end
end
end
end

10 changes: 5 additions & 5 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'pathname'
ROOT = Pathname.new(File.expand_path('../../', __FILE__))
$:.unshift((ROOT + 'lib').to_s)
$:.unshift((ROOT + 'spec').to_s)
$LOAD_PATH.unshift((ROOT + 'lib').to_s)
$LOAD_PATH.unshift((ROOT + 'spec').to_s)

require 'bundler/setup'
require 'pry'
Expand All @@ -11,7 +11,7 @@

# Use coloured output, it's the best.
RSpec.configure do |config|
config.filter_gems_from_backtrace "bundler"
config.filter_gems_from_backtrace 'bundler'
config.color = true
config.tty = true
end
Expand All @@ -34,7 +34,7 @@ def @output.winsize

cork = Cork::Board.new(out: @output)
def cork.string
out.string.gsub(/\e\[([;\d]+)?m/, "")
out.string.gsub(/\e\[([;\d]+)?m/, '')
end
cork
end
Expand All @@ -46,7 +46,7 @@ def testing_env
{
'HAS_JOSH_K_SEAL_OF_APPROVAL' => 'true',
'TRAVIS_PULL_REQUEST' => '800',
'TRAVIS_REPO_SLUG' => 'artsy/eigen',
'TRAVIS_REPO_SLUG' => 'dblock/danger-changelog',
'TRAVIS_COMMIT_RANGE' => '759adcbd0d8f...13c4dc8bb61d',
'DANGER_GITHUB_API_TOKEN' => '123sbdq54erfsd3422gdfio'
}
Expand Down

0 comments on commit 45f927f

Please sign in to comment.