Skip to content

Turning ruby-grape/danger into a reusable gem. #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--format=documentation
--color
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
### Changelog

### 0.1.0 (Next)

* [#5](https://github.com/ruby-grape/danger/pull/5): Initial public release as a gem for Danger 3.2.0 - [@dblock](https://github.com/dblock).
* Your contribution here.
* [#4](https://github.com/ruby-grape/danger/pull/4): Use Danger 2.1 - [@dblock](https://github.com/dblock).

### Shared Dangerfile

* [#4](https://github.com/ruby-grape/danger/pull/4): Support Danger 2.1 - [@dblock](https://github.com/dblock).
* [#2](https://github.com/ruby-grape/danger/pull/2): You've made changes to lib, but didn't write any tests? - [@dblock](https://github.com/dblock).
* [#2](https://github.com/ruby-grape/danger/pull/2): You've made changes to specs, but no library code has changed? - [@dblock](https://github.com/dblock).
* [#2](https://github.com/ruby-grape/danger/pull/2): Have you updated CHANGELOG.md and is it in the right format? - [@dblock](https://github.com/dblock).
43 changes: 1 addition & 42 deletions Dangerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
# --------------------------------------------------------------------------------------------------------------------
has_app_changes = !git.modified_files.grep(/lib/).empty?
has_spec_changes = !git.modified_files.grep(/spec/).empty?
has_changelog_changes = git.modified_files.include?('CHANGELOG.md')
has_dangerfile_changes = git.modified_files.include?('Dangerfile')
has_rakefile_changes = git.modified_files.include?('Rakefile')
has_code_changes = has_app_changes || has_dangerfile_changes || has_rakefile_changes

# --------------------------------------------------------------------------------------------------------------------
# You've made changes to lib, but didn't write any tests?
Expand All @@ -25,44 +21,7 @@ end
# --------------------------------------------------------------------------------------------------------------------
# Have you updated CHANGELOG.md?
# --------------------------------------------------------------------------------------------------------------------
if !has_changelog_changes && has_code_changes
pr_number = github.pr_json['number']
markdown <<-MARKDOWN
Here's an example of a CHANGELOG.md entry:

```markdown
* [##{pr_number}](https://github.com/ruby-grape/grape/pull/#{pr_number}): #{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)
end

# --------------------------------------------------------------------------------------------------------------------
# Is the CHANGELOG.md format correct?
# --------------------------------------------------------------------------------------------------------------------

your_contribution_here = false
errors = 0
File.open('CHANGELOG.md').each_line do |line|
# ignore lines that aren't changes
next unless line[0] == '*'
# notice your contribution here
if line == "* Your contribution here.\n"
your_contribution_here = true
next
end
# match the PR format, with or without PR number
next if line =~ %r{^\*\s[\`[:upper:]].* \- \[\@[\w\d\-\_]+\]\(https:\/\/github\.com\/.*[\w\d\-\_]+\)\.$}
next if line =~ %r{^\*\s\[\#\d+\]\(https:\/\/github\.com\/.*\d+\)\: [\`[:upper:]].* \- \[\@[\w\d\-\_]+\]\(https:\/\/github\.com\/.*[\w\d\-\_]+\)\.$}
errors += 1
markdown <<-MARKDOWN
```markdown
#{line}```
MARKDOWN
end

fail("One of the lines below found in CHANGELOG.md doesn't match the expected format. Please make it look like the other lines, pay attention to periods and spaces.", sticky: false) if errors > 0
fail('Please put back the `* Your contribution here.` line into CHANGELOG.md.', sticky: false) unless your_contribution_here
changelog.check

# --------------------------------------------------------------------------------------------------------------------
# Don't let testing shortcuts get into master by accident,
Expand Down
5 changes: 2 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
source 'https://rubygems.org'

gem 'bundler'
gem 'rake'
gemspec

gem 'rubocop', '0.42.0'
gem 'danger', '~> 2.1', require: false
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,30 @@ In Travis-CI, choose _Settings_ and add `DANGER_GITHUB_API_TOKEN` in _Environmen

#### Add Danger

Add `danger` to `Gemfile`.
Add `ruby-grape-danger` to `Gemfile`.

```ruby
gem 'danger', '~> 2.1', require: false
gem 'ruby-grape-danger', '~> 0.1.0', require: false
```

#### Add Dangerfile

Commit a `Dangerfile` with some placeholder text, eg. [Grape's Dangerfile](https://github.com/ruby-grape/grape/blob/master/Dangerfile). Danger automatically inherits the [Dangerfile](Dangerfile) in the organization's `danger` repo (this repo).
Commit a `Dangerfile`, eg. [Grape's Dangerfile](https://github.com/ruby-grape/grape/blob/master/Dangerfile).

```ruby
danger.import_dangerfile(gem: 'ruby-grape-danger')
```

#### Add Danger to Travis-CI

Add Danger to `.travis.yml`, eg. [Grape's Travis.yml](https://github.com/ruby-grape/grape/blob/master/.travis.yml).

```yaml
before_script:
- bundle exec danger
matrix:
include:
- rvm: 2.3.1
script:
- bundle exec danger
```

#### Commit via a Pull Request
Expand Down
65 changes: 65 additions & 0 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Releasing

There're no particular rules about when to release ruby-grape-danger. Release bug fixes frequenty, features not so frequently and breaking API changes rarely.

### Release

Run tests, check that all tests succeed locally.

```
bundle install
rake
```

Check that the last build succeeded in [Travis CI](https://travis-ci.org/ruby-grape/ruby-grape-danger) for all supported platforms.

Increment the version, modify [lib/ruby-grape-danger/version.rb](lib/ruby-grape-danger/version.rb).

* Increment the third number if the release has bug fixes and/or very minor features, only (eg. change `0.7.1` to `0.7.2`).
* Increment the second number if the release contains major features or breaking API changes (eg. change `0.7.1` to `0.8.0`).

Change "Next Release" in [CHANGELOG.md](CHANGELOG.md) to the new version.

```
### 0.7.2 (February 6, 2014)
```

Remove the line with "Your contribution here.", since there will be no more contributions to this release.

Commit your changes.

```
git add CHANGELOG.md lib/ruby-grape-danger/version.rb
git commit -m "Preparing for release, 0.7.2."
git push origin master
```

Release.

```
$ rake release

ruby-grape-danger 0.7.2 built to pkg/ruby-grape-danger-0.7.2.gem.
Tagged v0.7.2.
Pushed git commits and tags.
Pushed ruby-grape-danger 0.7.2 to rubygems.org.
```

### Prepare for the Next Version

Add the next release to [CHANGELOG.md](CHANGELOG.md).

```
Next Release
============

* Your contribution here.
```

Comit your changes.

```
git add CHANGELOG.md
git commit -m "Preparing for next release."
git push origin master
```
7 changes: 6 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ require 'bundler'

Bundler.setup :default

Bundler::GemHelper.install_tasks

require 'rubocop/rake_task'
RuboCop::RakeTask.new

task default: [:rubocop]
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)

task default: [:rubocop, :spec]
1 change: 0 additions & 1 deletion lib/placeholder.rb

This file was deleted.

3 changes: 3 additions & 0 deletions lib/ruby-grape-danger/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module RubyGrapeDanger
VERSION = '0.1.0'.freeze
end
22 changes: 22 additions & 0 deletions ruby-grape-danger.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path('../lib', __FILE__)
require 'ruby-grape-danger/version'

Gem::Specification.new do |s|
s.name = 'ruby-grape-danger'
s.version = RubyGrapeDanger::VERSION
s.authors = ['dblock']
s.email = ['[email protected]']
s.homepage = 'https://github.com/ruby-grape/danger'
s.summary = 'Danger.systems conventions for ruby-grape projects.'
s.description = 'Packages a Dangerfile to be used with Danger for projects within the Ruby Grape community.'

s.files = `git ls-files`.split('\n')
s.test_files = `git ls-files -- {test,spec,features}/*`.split('\n')
s.require_paths = ['lib']

s.add_development_dependency 'rake'
s.add_development_dependency 'rspec'
s.add_runtime_dependency 'danger', '~> 3.2.0'
s.add_runtime_dependency 'danger-changelog', '~> 0.1.0'
end
1 change: 0 additions & 1 deletion spec/placeholder.rb

This file was deleted.

5 changes: 5 additions & 0 deletions spec/ruby-grape-danger/version_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
RSpec.describe RubyGrapeDanger do
it 'has a version' do
expect(subject::VERSION).to_not be nil
end
end
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'bundler'
Bundler.require