From 993ec79d5fa3ac428c55a45a0433b9ab95e53c30 Mon Sep 17 00:00:00 2001 From: rafayet-monon Date: Mon, 12 Oct 2020 13:21:29 +0600 Subject: [PATCH] :tada: Initialize gem structure. --- .github/ISSUE_TEMPLATE/bug_template.md | 20 +++ .github/ISSUE_TEMPLATE/feature_template.md | 14 ++ .github/PULL_REQUEST_TEMPLATE.md | 13 ++ .gitignore | 5 + .rubocop.yml | 151 +++++++++++++++++++++ Gemfile | 4 + Guardfile | 19 +++ LICENSE.txt | 22 +++ README.md | 20 +++ Rakefile | 23 ++++ danger-undercover.gemspec | 49 +++++++ lib/danger_plugin.rb | 1 + lib/danger_undercover.rb | 1 + lib/undercover/gem_version.rb | 3 + lib/undercover/plugin.rb | 33 +++++ spec/spec_helper.rb | 65 +++++++++ spec/undercover_spec.rb | 46 +++++++ 17 files changed, 489 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_template.md create mode 100644 .github/ISSUE_TEMPLATE/feature_template.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .gitignore create mode 100644 .rubocop.yml create mode 100644 Gemfile create mode 100644 Guardfile create mode 100644 LICENSE.txt create mode 100644 README.md create mode 100644 Rakefile create mode 100644 danger-undercover.gemspec create mode 100644 lib/danger_plugin.rb create mode 100644 lib/danger_undercover.rb create mode 100644 lib/undercover/gem_version.rb create mode 100644 lib/undercover/plugin.rb create mode 100644 spec/spec_helper.rb create mode 100644 spec/undercover_spec.rb diff --git a/.github/ISSUE_TEMPLATE/bug_template.md b/.github/ISSUE_TEMPLATE/bug_template.md new file mode 100644 index 0000000..5eb84c3 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_template.md @@ -0,0 +1,20 @@ +--- +name: "Bug Report" +about: "You found something that is not working. Report it so that it can be fixed. 👷‍" +title: "Fix: " +labels: "type : bug" +--- + +## Issue + +Describe the issue you are facing. Show us the implementation: screenshots, gif, etc. + +## Expected + +Describe what should be the correct behaviour. + +## Steps to reproduce + +1. +2. +3. diff --git a/.github/ISSUE_TEMPLATE/feature_template.md b/.github/ISSUE_TEMPLATE/feature_template.md new file mode 100644 index 0000000..5a26eb9 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_template.md @@ -0,0 +1,14 @@ +--- +name: "Feature" +about: "Open a feature issue to add new functionalities." +title: "Add " +labels: "type : feature" +--- + +## Why + +Describe the big picture of the feature and why it's needed. + +## Who Benefits? + +Describe who will be the beneficiaries e.g. everyone, specific chapters, clients... diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..4d446af --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,13 @@ +https://github.com/nimblehq/git-template/issues/?? + +## What happened 👀 + +Describe the big picture of your changes here to communicate to the team why we should accept this pull request. + +## Insight 📝 + +Describe in details how to test the changes, which solution you tried but did not go with, referenced documentation is welcome as well. + +## Proof Of Work 📹 + +Show us the implementation: screenshots, gif, etc. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1e74d55 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.DS_Store +pkg +.idea/ +.yardoc +.rakeTasks diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..a33d523 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,151 @@ +# Defaults can be found here: https://github.com/bbatsov/rubocop/blob/master/config/default.yml + +# If you don't like these settings, just delete this file :) + +AllCops: + TargetRubyVersion: 2.0 + +Style/StringLiterals: + EnforcedStyle: double_quotes + Enabled: true + +# kind_of? is a good way to check a type +Style/ClassCheck: + EnforcedStyle: kind_of? + +# It's better to be more explicit about the type +Style/BracesAroundHashParameters: + Enabled: false + +# specs sometimes have useless assignments, which is fine +Lint/UselessAssignment: + Exclude: + - '**/spec/**/*' + +# We could potentially enable the 2 below: +Layout/IndentHash: + Enabled: false + +Layout/AlignHash: + Enabled: false + +# HoundCI doesn't like this rule +Layout/DotPosition: + Enabled: false + +# We allow !! as it's an easy way to convert ot boolean +Style/DoubleNegation: + Enabled: false + +# Cop supports --auto-correct. +Lint/UnusedBlockArgument: + Enabled: false + +# We want to allow class Fastlane::Class +Style/ClassAndModuleChildren: + Enabled: false + +Metrics/AbcSize: + Max: 60 + +# The %w might be confusing for new users +Style/WordArray: + MinSize: 19 + +# raise and fail are both okay +Style/SignalException: + Enabled: false + +# Better too much 'return' than one missing +Style/RedundantReturn: + Enabled: false + +# Having if in the same line might not always be good +Style/IfUnlessModifier: + Enabled: false + +# and and or is okay +Style/AndOr: + Enabled: false + +# Configuration parameters: CountComments. +Metrics/ClassLength: + Max: 350 + +Metrics/CyclomaticComplexity: + Max: 17 + +# Configuration parameters: AllowURI, URISchemes. +Metrics/LineLength: + Max: 370 + +# Configuration parameters: CountKeywordArgs. +Metrics/ParameterLists: + Max: 10 + +Metrics/PerceivedComplexity: + Max: 18 + +# Sometimes it's easier to read without guards +Style/GuardClause: + Enabled: false + +# something = if something_else +# that's confusing +Style/ConditionalAssignment: + Enabled: false + +# Better to have too much self than missing a self +Style/RedundantSelf: + Enabled: false + +Metrics/MethodLength: + Max: 60 + +# We're not there yet +Style/Documentation: + Enabled: false + +# Adds complexity +Style/IfInsideElse: + Enabled: false + +# danger specific + +Style/BlockComments: + Enabled: false + +Layout/MultilineMethodCallIndentation: + EnforcedStyle: indented + +Metrics/BlockLength: + Max: 345 + Exclude: + - "**/*_spec.rb" + +Style/MixinGrouping: + Enabled: false + +Style/FileName: + Enabled: false + +Layout/IndentHeredoc: + Enabled: false + +Style/SpecialGlobalVars: + Enabled: false + +PercentLiteralDelimiters: + PreferredDelimiters: + "%": () + "%i": () + "%q": () + "%Q": () + "%r": "{}" + "%s": () + "%w": () + "%W": () + "%x": () + +Security/YAMLLoad: + Enabled: false diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..07ae8d3 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +# Specify your gem's dependencies in danger-undercover.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..a6edce6 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,22 @@ +Copyright (c) 2020 rafayet-monon + +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..d0f5853 --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +# danger-undercover + +A Danger plugin to use with Undercover gem. + +## Installation + + $ gem install danger-undercover + +## Usage + + Methods and attributes from this plugin are available in + your `Dangerfile` under the `undercover` 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-undercover.gemspec b/danger-undercover.gemspec new file mode 100644 index 0000000..e42eb45 --- /dev/null +++ b/danger-undercover.gemspec @@ -0,0 +1,49 @@ +# coding: utf-8 +lib = File.expand_path('../lib', __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require 'undercover/gem_version.rb' + +Gem::Specification.new do |spec| + spec.name = 'danger-undercover' + spec.version = Undercover::VERSION + spec.authors = ['rafayet-monon'] + spec.email = ['rafayet.monon@gmail.com'] + spec.description = %q{Show undercover report to PRs} + spec.summary = %q{A Danger plugin for Undercover gem} + spec.homepage = 'https://github.com/nimblehq/danger-undercover' + 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-plugin-api', '~> 1.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" + spec.add_development_dependency "yard" + + # 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 tests + # 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..5d1a508 --- /dev/null +++ b/lib/danger_plugin.rb @@ -0,0 +1 @@ +require "undercover/plugin" diff --git a/lib/danger_undercover.rb b/lib/danger_undercover.rb new file mode 100644 index 0000000..00a0a5d --- /dev/null +++ b/lib/danger_undercover.rb @@ -0,0 +1 @@ +require "undercover/gem_version" diff --git a/lib/undercover/gem_version.rb b/lib/undercover/gem_version.rb new file mode 100644 index 0000000..7b07c11 --- /dev/null +++ b/lib/undercover/gem_version.rb @@ -0,0 +1,3 @@ +module Undercover + VERSION = "0.0.1".freeze +end diff --git a/lib/undercover/plugin.rb b/lib/undercover/plugin.rb new file mode 100644 index 0000000..7ce9b51 --- /dev/null +++ b/lib/undercover/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 rafayet-monon/danger-undercover + # @tags monday, weekends, time, rattata + # + class DangerUndercover < 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..0a50001 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,65 @@ +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" + +if `git remote -v` == '' + puts "You cannot run tests without setting a local git remote on this repo" + puts "It's a weird side-effect of Danger's internals." + exit(0) +end + +# 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/undercover_spec.rb b/spec/undercover_spec.rb new file mode 100644 index 0000000..6d2ba2e --- /dev/null +++ b/spec/undercover_spec.rb @@ -0,0 +1,46 @@ +require File.expand_path("../spec_helper", __FILE__) + +module Danger + describe Danger::DangerUndercover do + it "should be a plugin" do + expect(Danger::DangerUndercover.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.undercover + + # mock the PR data + # you can then use this, eg. github.pr_author, later in the spec + json = File.read(File.dirname(__FILE__) + '/support/fixtures/github_pr.json') # example json: `curl https://api.github.com/repos/danger/danger-plugin-template/pulls/18 > github_pr.json` + allow(@my_plugin.github).to receive(:pr_json).and_return(json) + 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