diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4e46fab --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +pkg +.idea/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..be17f09 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +language: ruby +cache: + directories: + - bundle + +rvm: + - 2.0 + - 2.1.3 + - 2.3.1 + +script: + - bundle exec rake spec \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..3b9b3fc --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +# Specify your gem's dependencies in danger-xcodebuild.gemspec +gemspec diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000..95b91ae --- /dev/null +++ b/Guardfile @@ -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 diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..282f362 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,22 @@ +Copyright (c) 2016 Valerio Mazzeo + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a6465b7 --- /dev/null +++ b/README.md @@ -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. diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..af16989 --- /dev/null +++ b/Rakefile @@ -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 diff --git a/danger-xcodebuild.gemspec b/danger-xcodebuild.gemspec new file mode 100644 index 0000000..b4a6bf8 --- /dev/null +++ b/danger-xcodebuild.gemspec @@ -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 = ['valerio.mazzeo@gmail.com'] + 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 diff --git a/lib/danger_plugin.rb b/lib/danger_plugin.rb new file mode 100644 index 0000000..685236a --- /dev/null +++ b/lib/danger_plugin.rb @@ -0,0 +1 @@ +require 'xcodebuild/plugin' diff --git a/lib/danger_xcodebuild.rb b/lib/danger_xcodebuild.rb new file mode 100644 index 0000000..6610139 --- /dev/null +++ b/lib/danger_xcodebuild.rb @@ -0,0 +1 @@ +require 'xcodebuild/gem_version' diff --git a/lib/xcodebuild/gem_version.rb b/lib/xcodebuild/gem_version.rb new file mode 100644 index 0000000..bbafa15 --- /dev/null +++ b/lib/xcodebuild/gem_version.rb @@ -0,0 +1,3 @@ +module Xcodebuild + VERSION = "0.0.1".freeze +end diff --git a/lib/xcodebuild/plugin.rb b/lib/xcodebuild/plugin.rb new file mode 100644 index 0000000..2197fa8 --- /dev/null +++ b/lib/xcodebuild/plugin.rb @@ -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] + attr_accessor :my_attribute + + # A method that you can call from your Dangerfile + # @return [Array] + # + def warn_on_mondays + warn 'Trying to merge code on a Monday' if Date.today.wday == 1 + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..90ef3be --- /dev/null +++ b/spec/spec_helper.rb @@ -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 diff --git a/spec/xcodebuild_spec.rb b/spec/xcodebuild_spec.rb new file mode 100644 index 0000000..d8766ca --- /dev/null +++ b/spec/xcodebuild_spec.rb @@ -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 +