Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriomazzeo committed Aug 1, 2016
0 parents commit bbb3ee8
Show file tree
Hide file tree
Showing 14 changed files with 289 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
pkg
.idea/
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: ruby
cache:
directories:
- bundle

rvm:
- 2.0
- 2.1.3
- 2.3.1

script:
- bundle exec rake spec
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in danger-xcodebuild.gemspec
gemspec
19 changes: 19 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# A guardfile for making Danger Plugins
# For more info see https://github.com/guard/guard#readme

# To run, use `bundle exec guard`.

guard :rspec, cmd: 'bundle exec rspec' do
require 'guard/rspec/dsl'
dsl = Guard::RSpec::Dsl.new(self)

# RSpec files
rspec = dsl.rspec
watch(rspec.spec_helper) { rspec.spec_dir }
watch(rspec.spec_support) { rspec.spec_dir }
watch(rspec.spec_files)

# Ruby files
ruby = dsl.ruby
dsl.watch_spec_files_for(ruby.lib_files)
end
22 changes: 22 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2016 Valerio Mazzeo <[email protected]>

MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# danger-xcodebuild

A description of danger-xcodebuild.

## Installation

$ gem install danger-xcodebuild

## Usage

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

## Development

1. Clone this repo
2. Run `bundle install` to setup dependencies.
3. Run `bundle exec rake spec` to run the tests.
4. Use `bundle exec guard` to automatically have tests run as you make changes.
5. Make your changes.
23 changes: 23 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'

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

task default: :specs

task :spec do
Rake::Task['specs'].invoke
Rake::Task['rubocop'].invoke
Rake::Task['spec_docs'].invoke
end

desc 'Run RuboCop on the lib/specs directory'
RuboCop::RakeTask.new(:rubocop) do |task|
task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
end

desc 'Ensure that the plugin passes `danger plugins lint`'
task :spec_docs do
sh 'bundle exec danger plugins lint'
end
47 changes: 47 additions & 0 deletions danger-xcodebuild.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'xcodebuild/gem_version.rb'

Gem::Specification.new do |spec|
spec.name = 'danger-xcodebuild'
spec.version = Xcodebuild::VERSION
spec.authors = ['Valerio Mazzeo']
spec.email = ['[email protected]']
spec.description = %q{A short description of danger-xcodebuild.}
spec.summary = %q{A longer description of danger-xcodebuild.}
spec.homepage = 'https://github.com/Valerio Mazzeo/danger-xcodebuild'
spec.license = 'MIT'

spec.files = `git ls-files`.split($/)
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']

spec.add_runtime_dependency 'danger', '~>2.0'

# General ruby development
spec.add_development_dependency 'bundler', '~> 1.3'
spec.add_development_dependency 'rake', '~> 10.0'

# Testing support
spec.add_development_dependency 'rspec', '~> 3.4'

# Linting code and docs
spec.add_development_dependency "rubocop", "~> 0.41"
spec.add_development_dependency "yard", "~> 0.8"

# Makes testing easy via `bundle exec guard`
spec.add_development_dependency 'guard', '~> 2.14'
spec.add_development_dependency 'guard-rspec', '~> 4.7'

# If you want to work on older builds of ruby
spec.add_development_dependency 'listen', '3.0.7'

# This gives you the chance to run a REPL inside your test
# via
# require 'pry'
# binding.pry
# This will stop test execution and let you inspect the results
spec.add_development_dependency 'pry'
end
1 change: 1 addition & 0 deletions lib/danger_plugin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'xcodebuild/plugin'
1 change: 1 addition & 0 deletions lib/danger_xcodebuild.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'xcodebuild/gem_version'
3 changes: 3 additions & 0 deletions lib/xcodebuild/gem_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Xcodebuild
VERSION = "0.0.1".freeze
end
33 changes: 33 additions & 0 deletions lib/xcodebuild/plugin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module Danger
# This is your plugin class. Any attributes or methods you expose here will
# be available from within your Dangerfile.
#
# To be published on the Danger plugins site, you will need to have
# the public interface documented. Danger uses [YARD](http://yardoc.org/)
# for generating documentation from your plugin source, and you can verify
# by running `danger plugins lint` or `bundle exec rake spec`.
#
# You should replace these comments with a public description of your library.
#
# @example Ensure people are well warned about merging on Mondays
#
# my_plugin.warn_on_mondays
#
# @see Valerio Mazzeo/danger-xcodebuild
# @tags monday, weekends, time, rattata
#
class DangerXcodebuild < Plugin

# An attribute that you can read/write from your Dangerfile
#
# @return [Array<String>]
attr_accessor :my_attribute

# A method that you can call from your Dangerfile
# @return [Array<String>]
#
def warn_on_mondays
warn 'Trying to merge code on a Monday' if Date.today.wday == 1
end
end
end
59 changes: 59 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require 'pathname'
ROOT = Pathname.new(File.expand_path('../../', __FILE__))
$:.unshift((ROOT + 'lib').to_s)
$:.unshift((ROOT + 'spec').to_s)

require 'bundler/setup'
require 'pry'

require 'rspec'
require 'danger'

# Use coloured output, it's the best.
RSpec.configure do |config|
config.filter_gems_from_backtrace "bundler"
config.color = true
config.tty = true
end

require 'danger_plugin'

# These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
# If you are expanding these files, see if it's already been done ^.

# A silent version of the user interface,
# it comes with an extra function `.string` which will
# strip all ANSI colours from the string.

# rubocop:disable Lint/NestedMethodDefinition
def testing_ui
@output = StringIO.new
def @output.winsize
[20, 9999]
end

cork = Cork::Board.new(out: @output)
def cork.string
out.string.gsub(/\e\[([;\d]+)?m/, "")
end
cork
end
# rubocop:enable Lint/NestedMethodDefinition

# Example environment (ENV) that would come from
# running a PR on TravisCI
def testing_env
{
'HAS_JOSH_K_SEAL_OF_APPROVAL' => 'true',
'TRAVIS_PULL_REQUEST' => '800',
'TRAVIS_REPO_SLUG' => 'artsy/eigen',
'TRAVIS_COMMIT_RANGE' => '759adcbd0d8f...13c4dc8bb61d',
'DANGER_GITHUB_API_TOKEN' => '123sbdq54erfsd3422gdfio'
}
end

# A stubbed out Dangerfile for use in tests
def testing_dangerfile
env = Danger::EnvironmentManager.new(testing_env)
Danger::Dangerfile.new(env, testing_ui)
end
42 changes: 42 additions & 0 deletions spec/xcodebuild_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require File.expand_path('../spec_helper', __FILE__)

module Danger
describe Danger::DangerXcodebuild do
it 'should be a plugin' do
expect(Danger::DangerXcodebuild.new(nil)).to be_a Danger::Plugin
end

#
# You should test your custom attributes and methods here
#
describe 'with Dangerfile' do
before do
@dangerfile = testing_dangerfile
@my_plugin = @dangerfile.my_plugin
end

# Some examples for writing tests
# You should replace these with your own.

it "Warns on a monday" do
monday_date = Date.parse("2016-07-11")
allow(Date).to receive(:today).and_return monday_date

@my_plugin.warn_on_mondays

expect(@dangerfile.status_report[:warnings]).to eq(["Trying to merge code on a Monday"])
end

it "Does nothing on a tuesday" do
monday_date = Date.parse("2016-07-12")
allow(Date).to receive(:today).and_return monday_date

@my_plugin.warn_on_mondays

expect(@dangerfile.status_report[:warnings]).to eq([])
end

end
end
end

0 comments on commit bbb3ee8

Please sign in to comment.