Skip to content
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

Added Dangerfile to root directory of mapknitter #306

Closed
wants to merge 9 commits into from
Closed
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
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ install:
- docker-compose run web bash -c "rake db:setup"
- docker-compose run web bash -c "rake db:migrate"
- docker-compose run web bower install --allow-root
- 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then gem install danger danger-junit; fi'

script:
- docker-compose run web bash -c "rake test"
- docker-compose exec web bash -c "CI=TRUE GENERATE_REPORT=true rake test"
- echo -e '<?xml version="1.0" encoding="UTF-8"?>' > output.xml
- tail -n +2 -q ./test/reports/TEST*.xml >> output.xml
- 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then danger --verbose; fi'
63 changes: 63 additions & 0 deletions Dangerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
message "@#{github.pr_author} Thank you for your pull request! I'm here to help with some tips and recommendations. Please take a look at the list provided and help us review and accept your contribution! And **don't be discouraged if you see errors** -- we're here to help."

message "Your pull request is on the `master` branch. Please [make a separate feature branch](https://publiclab.org/wiki/contributing-to-public-lab-software#A+sample+git+workflow)) with a descriptive name like `new-blog-design` while making PRs in the future." if github.branch_for_head == 'master'

unless git.commits.any? { |c| c.message =~ /#[\d]+/ } || github.pr_body =~ /#[\d]+/
message "This pull request doesn't link to a issue number. Please refer to the issue it fixes (if any) in the body of your PR, in the format: `Fixes #123`."
end

if git.added_files.include?("Gemfile.lock") && !git.added_files.include?("Gemfile")
warn "You have added your `Gemfile.lock` file -- which is most likely not necessary, since you have not changed the Gemfile. Please [remove your changes to this file](https://stackoverflow.com/questions/215718/reset-or-revert-a-specific-file-to-a-specific-revision-using-git) to leave it as it was, thank you! If you really do mean to add Gemfile.lock, just leave a note explaining why. Thanks!"
end

if git.added_files.any? { |files| files.start_with? "db/migrate/" } && !git.added_files.include?("schema.rb.example")
warn "New migrations added. Please update `schema.rb.example` by overwriting it with a copy of the up-to-date `db/schema.rb`. Also, be aware to preserve the MySQL-specific conditions for full-text indices."
end

if git.commits.any? { |c| c.message =~ /^Merge branch 'master'/ }
warn "It looks like you merged from master in this pull request. Please [rebase](https://help.github.com/articles/about-git-rebase/) to get rid of the merge commits -- you may want to [rewind the master branch and rebase](https://publiclab.org/wiki/contributing-to-public-lab-software#Rewinding+the+master+branch) instead of merging in from master, which can cause problems when accepting new code!"
end

can_merge = github.pr_json["mergeable"]
warn("This pull request cannot be merged yet due to merge conflicts. Please resolve them -- probably by [rebasing](https://help.github.com/articles/about-git-rebase/) -- and ask for help (in the comments, or [in the chatroom](https://gitter.im/publiclab/publiclab) if you get into trouble!.", sticky: false) unless can_merge

if github.pr_body.include?("* [ ]") && !github.pr_title.include?("[WIP]")
message "It looks like you haven't marked all the checkboxes. Help us review and accept your suggested changes by going through the steps one by one. If it is still a 'Work in progress', please include '[WIP]' in the title."
end

message "Pull Request is marked as Work in Progress" if github.pr_title.include? "[WIP]"

begin

junit.parse "output.xml"
junit.failures.collect(&:nodes).flatten.each do |failure|
failure.nodes.each do |f|
f.match(/(test[a-z_\/]+.rb):([0-9]+)/) do |match|
source_path = match[1]
line = match[2]
if !source_path.nil? && !line.nil?
f = f.gsub(source_path + ':' + line, "<a href='https://github.com/#{github.pr_author}/mapknitter/tree/#{github.branch_for_head}/#{source_path}#L#{line}'>#{source_path}:#{line}</a>")
end
fail("There was a test failure at: #{f}")
end
end
end

junit.errors.collect(&:nodes).flatten.each do |error|
error.nodes.each do |f|
f.match(/(test[a-z_\/]+.rb):([0-9]+)/) do |match|
source_path = match[1]
line = match[2]
if !source_path.nil? && !line.nil?
f = f.gsub(source_path + ':' + line, "<a href='https://github.com/#{github.pr_author}/mapknitter/tree/#{github.branch_for_head}/#{source_path}#L#{line}'>#{source_path}:#{line}</a>")
.gsub('`', "'") # remove ` as these cause Markdown formatting
end
fail("There was a test error at: #{f}")
end
end
end

rescue => ex
fail "There was an error with Danger bot's Junit parsing: #{ex.message}"
message ex.inspect # view the entire error output in the log
end
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ group :test do
end

group :development do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in a group :test doesn't it? 🤔

gem 'ci_reporter_test_unit'
gem 'coveralls', require: false
gem 'minitest-reporters', '~> 1.3.6'
gem "jshintrb"
gem "therubyracer"
end
Expand Down
7 changes: 7 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
require 'coveralls'
Coveralls.wear!

ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'

require "minitest/reporters"
MiniTest::Reporters.use! [MiniTest::Reporters::ProgressReporter.new,
MiniTest::Reporters::JUnitReporter.new]

class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
#
Expand Down