lois 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 574bd9efe2959fd2df975834b6bb91b278dfcb75
4
+ data.tar.gz: 81aca5bd9f00f804254e9cc2a14774af3c50394e
5
+ SHA512:
6
+ metadata.gz: 25ddc829832f64aa3f9275b945119fe026b2f2ed020377678fd87e3b0425c7ed67cc26827e16e7b52e16d25166d4d4dea34c8227ad4851e4662cdf1dd7cb7cbc
7
+ data.tar.gz: 6e009f91ca4d11a894f4f34876e59e085eef300f74feed54b445e564fc429e63704759b7ef6204baa7e2b6759f740dc798e44ca2ba687f0004cc49b1a1ff2855
@@ -0,0 +1,80 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ # specify the version you desire here
10
+ - image: circleci/ruby:2.4.1-node-browsers
11
+ environment:
12
+ COVERAGE: true
13
+
14
+ # Specify service dependencies here if necessary
15
+ # CircleCI maintains a library of pre-built images
16
+ # documented at https://circleci.com/docs/2.0/circleci-images/
17
+ # - image: circleci/postgres:9.4
18
+
19
+ working_directory: ~/repo
20
+
21
+ steps:
22
+ - checkout
23
+
24
+ # Download and cache dependencies
25
+ - restore_cache:
26
+ keys:
27
+ - v2-dependencies-{{ checksum "lois.gemspec" }}
28
+ # fallback to using the latest cache if no exact match is found
29
+ - v2-dependencies-
30
+
31
+ - run:
32
+ name: install dependencies
33
+ command: |
34
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
35
+
36
+ - save_cache:
37
+ paths:
38
+ - vendor/bundle
39
+ key: v2-dependencies-{{ checksum "lois.gemspec" }}
40
+
41
+ # run tests!
42
+ - run:
43
+ name: install
44
+ command: |
45
+ bin/rake install
46
+
47
+ - run:
48
+ name: Bundler-Audit
49
+ command: |
50
+ lois bundler_audit -g $GITHUB_CREDENTIALS -c circleci
51
+
52
+ - run:
53
+ name: Rubocop
54
+ command: |
55
+ lois rubocop -g $GITHUB_CREDENTIALS -c circleci
56
+
57
+ - run:
58
+ name: Reek
59
+ command: |
60
+ lois reek -g $GITHUB_CREDENTIALS -c circleci
61
+
62
+ # run tests!
63
+ - run:
64
+ name: run tests
65
+ command: |
66
+ mkdir results
67
+ bundle exec rspec --format progress \
68
+ --format RspecJunitFormatter \
69
+ --out results/rspec.xml \
70
+ --format progress \
71
+
72
+ # collect reports
73
+ - store_test_results:
74
+ path: results
75
+ - store_artifacts:
76
+ path: results
77
+ destination: results
78
+ - store_artifacts:
79
+ path: lois
80
+ destination: lois
@@ -0,0 +1,60 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /.bundle/
7
+ /.yardoc
8
+ /Gemfile.lock
9
+ /_yardoc/
10
+ /coverage/
11
+ /doc/
12
+ /pkg/
13
+ /spec/reports/
14
+ /spec/examples.txt
15
+ /test/tmp/
16
+ /test/version_tmp/
17
+ /tmp/
18
+
19
+ # Used by dotenv library to load environment variables.
20
+ # .env
21
+
22
+ ## Specific to RubyMotion:
23
+ .dat*
24
+ .repl_history
25
+ build/
26
+ *.bridgesupport
27
+ build-iPhoneOS/
28
+ build-iPhoneSimulator/
29
+
30
+ ## Specific to RubyMotion (use of CocoaPods):
31
+ #
32
+ # We recommend against adding the Pods directory to your .gitignore. However
33
+ # you should judge for yourself, the pros and cons are mentioned at:
34
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
35
+ #
36
+ # vendor/Pods/
37
+
38
+ ## Documentation cache and generated files:
39
+ /.yardoc/
40
+ /_yardoc/
41
+ /doc/
42
+ /rdoc/
43
+
44
+ ## Environment normalization:
45
+ /.bundle/
46
+ /vendor/bundle
47
+ /lib/bundler/man/
48
+
49
+ # for a library or gem, you might want to ignore these files since the code is
50
+ # intended to run in multiple environments; otherwise, check them in:
51
+ # Gemfile.lock
52
+ # .ruby-version
53
+ # .ruby-gemset
54
+
55
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
56
+ .rvmrc
57
+ # rspec failure tracking
58
+ .rspec_status
59
+ *.orig
60
+ .env
data/.reek ADDED
@@ -0,0 +1,61 @@
1
+ ---
2
+ Attribute:
3
+ enabled: false
4
+
5
+ IrresponsibleModule:
6
+ enabled: false
7
+
8
+ UncommunicativeVariableName:
9
+ enabled: false
10
+
11
+ UncommunicativeModuleName:
12
+ enabled: false
13
+
14
+ NestedIterators:
15
+ enabled: false
16
+
17
+ UnusedPrivateMethod:
18
+ enabled: false
19
+
20
+ TooManyMethods:
21
+ enabled: true
22
+ exclude:
23
+ - 'User'
24
+
25
+ TooManyStatements:
26
+ enabled: false
27
+
28
+ DuplicateMethodCall:
29
+ enabled: false
30
+
31
+ PrimaDonnaMethod:
32
+ enabled: false
33
+
34
+ NilCheck:
35
+ enabled: false
36
+
37
+ UtilityFunction:
38
+ enabled: false
39
+
40
+ LongParameterList:
41
+ max_params: 7
42
+
43
+ TooManyInstanceVariables:
44
+ enabled: false
45
+
46
+ InstanceVariableAssumption:
47
+ enabled: false
48
+
49
+ FeatureEnvy:
50
+ enabled: false
51
+
52
+ ManualDispatch:
53
+ enabled: false
54
+
55
+ DataClump:
56
+ exclude:
57
+ - Lois::Github
58
+
59
+ exclude_paths:
60
+ - lib/tasks
61
+ - vendor/bundle
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --order random
3
+ --format documentation
@@ -0,0 +1,18 @@
1
+ Metrics/AbcSize:
2
+ Max: 50
3
+
4
+ Metrics/BlockLength:
5
+ Max: 50
6
+
7
+ Metrics/LineLength:
8
+ Max: 100
9
+
10
+ Metrics/ClassLength:
11
+ Exclude:
12
+ - lib/lois/cli.rb
13
+
14
+ Style/Documentation:
15
+ Enabled: false
16
+
17
+ Metrics/MethodLength:
18
+ Max: 20
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in lois.gemspec
6
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Ryan Hansen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,98 @@
1
+ # Lois [![CircleCI](https://circleci.com/gh/ketiko/lois.svg?style=svg)](https://circleci.com/gh/ketiko/lois)
2
+
3
+ Lois reports statuses of CI results to Github Pull Request Statuses.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'lois'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install lois
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ bundle exec lois help
25
+
26
+ Commands:
27
+ lois brakeman -g, --github-credentials=GITHUB_CREDENTIALS # Run brakeman
28
+ lois bundler-audit -g, --github-credentials=GITHUB_CREDENTIALS # Run bundler-audit
29
+ lois help [COMMAND] # Describe available commands or one specific command
30
+ lois reek -g, --github-credentials=GITHUB_CREDENTIALS # Run reek
31
+ lois rubocop -g, --github-credentials=GITHUB_CREDENTIALS # Run Rubocop
32
+ lois simplecov -g, --github-credentials=GITHUB_CREDENTIALS # Run simplecov
33
+ ```
34
+
35
+ Lois has commands to run and report ruby quality metrics to Github PR Statuses. All it requires is
36
+ a github basic auth credentials for a user to report the statuses. The user needs write access to the repo to post
37
+ PR status updates.
38
+
39
+ See [https://developer.github.com/v3/auth/#basic-authentication](https://developer.github.com/v3/auth/#basic-authentication).
40
+ We recommend using oauth tokens and not your password.
41
+
42
+ Currently we only support reporting through [CircleCI](https://circleci.com/), but PRs for additional continuous integration systems are welcome.
43
+
44
+ Lois will output all the results of the checks to a `lois` directory. You can add this to your artifact path to view the html representation of the results later.
45
+
46
+ A sample `.circleci/config.yml` would look like:
47
+
48
+ ```
49
+ - run:
50
+ name: Bundler-Audit
51
+ command: bin/lois bundler-audit -g $GITHUB_CREDENTIALS
52
+
53
+ - run:
54
+ name: Brakeman
55
+ command: bin/lois brakeman -g $GITHUB_CREDENTIALS
56
+
57
+ - run:
58
+ name: Rubocop
59
+ command: bin/lois rubocop -g $GITHUB_CREDENTIALS
60
+
61
+ - run:
62
+ name: Reek
63
+ command: bin/lois reek -g $GITHUB_CREDENTIALS
64
+
65
+ - store_artifacts:
66
+ path: lois
67
+ destination: lois
68
+ ```
69
+
70
+ ### SimpleCov
71
+
72
+ To get SimpleCov output you must have an `at_exit` hook. A sample SimpleCov setup looks like:
73
+
74
+ ```
75
+ if ENV['COVERAGE']
76
+ require 'simplecov'
77
+ SimpleCov.start
78
+ SimpleCov.minimum_coverage 55
79
+ SimpleCov.at_exit do
80
+ if ENV['CI']
81
+ min = SimpleCov.minimum_coverage
82
+ actual = SimpleCov.result.covered_percent
83
+ system("lois simplecov -g $GITHUB_CREDENTIALS -m #{min} -a #{actual}")
84
+ end
85
+ SimpleCov.result.format!
86
+ end
87
+ end
88
+ ```
89
+
90
+ ## Development
91
+
92
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
93
+
94
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
95
+
96
+ ## Contributing
97
+
98
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/lois.
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'brakeman' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ require 'rubygems'
16
+ require 'bundler/setup'
17
+
18
+ load Gem.bin_path('brakeman', 'brakeman')
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'bundle-audit' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ require 'rubygems'
16
+ require 'bundler/setup'
17
+
18
+ load Gem.bin_path('bundler-audit', 'bundle-audit')
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'bundler-audit' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ require 'rubygems'
16
+ require 'bundler/setup'
17
+
18
+ load Gem.bin_path('bundler-audit', 'bundler-audit')
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'code_climate_reek' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ require 'rubygems'
16
+ require 'bundler/setup'
17
+
18
+ load Gem.bin_path('reek', 'code_climate_reek')
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'lois'
5
+ require 'dotenv/load'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'pry'
15
+ Pry.start
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ require 'rubygems'
16
+ require 'bundler/setup'
17
+
18
+ load Gem.bin_path('rake', 'rake')
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'reek' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ require 'rubygems'
16
+ require 'bundler/setup'
17
+
18
+ load Gem.bin_path('reek', 'reek')
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ require 'rubygems'
16
+ require 'bundler/setup'
17
+
18
+ load Gem.bin_path('rspec-core', 'rspec')
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rubocop' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ require 'rubygems'
16
+ require 'bundler/setup'
17
+
18
+ load Gem.bin_path('rubocop', 'rubocop')
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,4 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'lois'
4
+ Lois::CLI.start(ARGV)
@@ -0,0 +1,13 @@
1
+ require 'active_support/configurable'
2
+ require 'lois/version'
3
+ require 'lois/github'
4
+ require 'lois/ci'
5
+ require 'lois/cli'
6
+
7
+ module Lois
8
+ include ActiveSupport::Configurable
9
+
10
+ config_accessor :ci
11
+ config_accessor :github_credentials
12
+ config_accessor :github
13
+ end
@@ -0,0 +1,6 @@
1
+ require 'lois/ci/circleci'
2
+
3
+ module Lois
4
+ module Ci
5
+ end
6
+ end
@@ -0,0 +1,17 @@
1
+ module Lois
2
+ module Ci
3
+ class Circleci
4
+ def organization
5
+ ENV.fetch('CIRCLE_PROJECT_USERNAME')
6
+ end
7
+
8
+ def repository
9
+ ENV.fetch('CIRCLE_PROJECT_REPONAME')
10
+ end
11
+
12
+ def pull_request_sha
13
+ ENV.fetch('CIRCLE_SHA1')
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,141 @@
1
+ require 'thor'
2
+
3
+ module Lois
4
+ class CLI < Thor
5
+ desc 'rubocop', 'Run Rubocop'
6
+ method_option :github_credentials,
7
+ aliases: '-g',
8
+ required: true,
9
+ desc: 'Github credentials to log PR Status.'
10
+ method_option :ci,
11
+ default: 'circleci',
12
+ aliases: '-c',
13
+ desc: 'CI to load env vars from.'
14
+ def rubocop
15
+ puts 'Checking Rubocop'
16
+ configure(options)
17
+
18
+ if system('bundle exec rubocop -f html -o lois/rubocop.html -f p')
19
+ Lois.config.github.success('rubocop', 'Rubocop passed')
20
+ else
21
+ Lois.config.github.failure('rubocop', 'Rubocop failed')
22
+ end
23
+ end
24
+
25
+ desc 'bundler-audit', 'Run bundler-audit'
26
+ method_option :github_credentials,
27
+ aliases: '-g',
28
+ required: true,
29
+ desc: 'Github credentials to log PR Status.'
30
+ method_option :ci,
31
+ default: 'circleci',
32
+ aliases: '-c',
33
+ desc: 'CI to load env vars from.'
34
+ def bundler_audit
35
+ puts 'Checking bundler-audit'
36
+ configure(options)
37
+
38
+ output = `bundle exec bundle-audit check --verbose --update`
39
+ result = $CHILD_STATUS
40
+ File.write('lois/bundler-audit.log', output)
41
+ puts output
42
+
43
+ if result.success?
44
+ Lois.config.github.success('bundler-audit', 'No gem vulnerabilities found.')
45
+ else
46
+ Lois.config.github.failure('bundler-audit', 'Gem vulnerabilities detected!')
47
+ end
48
+ end
49
+
50
+ desc 'reek', 'Run reek'
51
+ method_option :github_credentials,
52
+ aliases: '-g',
53
+ required: true,
54
+ desc: 'Github credentials to log PR Status.'
55
+ method_option :ci,
56
+ default: 'circleci',
57
+ aliases: '-c',
58
+ desc: 'CI to load env vars from.'
59
+ def reek
60
+ puts 'Checking reek'
61
+ configure(options)
62
+
63
+ system('bundle exec reek -f html > lois/reek.html')
64
+ if system('bundle exec reek -n --sort-by smelliness')
65
+ Lois.config.github.success('reek', 'No code smells.')
66
+ else
67
+ Lois.config.github.failure('reek', 'Code smells found.')
68
+ end
69
+ end
70
+
71
+ desc 'brakeman', 'Run brakeman'
72
+ method_option :github_credentials,
73
+ aliases: '-g',
74
+ required: true,
75
+ desc: 'Github credentials to log PR Status.'
76
+ method_option :ci,
77
+ default: 'circleci',
78
+ aliases: '-c',
79
+ desc: 'CI to load env vars from.'
80
+ def brakeman
81
+ puts 'Checking brakeman'
82
+ configure(options)
83
+ if system('bundle exec brakeman -o lois/brakeman.html -o /dev/stdout')
84
+ Lois.config.github.success('brakeman', 'No rails vulnerabilities found.')
85
+ else
86
+ Lois.config.github.failure('brakeman', 'Rails vulnerabilities found.')
87
+ end
88
+ end
89
+
90
+ desc 'simplecov', 'Run simplecov'
91
+ method_option :github_credentials,
92
+ aliases: '-g',
93
+ required: true,
94
+ desc: 'Github credentials to log PR Status.'
95
+ method_option :ci,
96
+ default: 'circleci',
97
+ aliases: '-c',
98
+ desc: 'CI to load env vars from.'
99
+ method_option :minimum,
100
+ aliases: '-m',
101
+ desc: 'Minimum required coverage percentage'
102
+ method_option :actual,
103
+ aliases: '-a',
104
+ desc: 'Actual required coverage percentage'
105
+ def simplecov
106
+ puts 'Checking simplecov'
107
+ configure(options)
108
+
109
+ actual = options[:actual].to_f
110
+ actual_formatted = format('%.2f%', actual)
111
+
112
+ if actual >= options[:minimum].to_f
113
+ Lois.config.github.success('simplecov', "#{actual_formatted} coverage.")
114
+ else
115
+ Lois.config.github.failure('simplecov', "#{actual_formatted} is too low.")
116
+ end
117
+ end
118
+
119
+ private
120
+
121
+ def configure(options)
122
+ Lois.configure do |config|
123
+ config.github_credentials = options[:github_credentials]
124
+
125
+ case options[:ci]
126
+ when 'circleci'
127
+ config.ci = Lois::Ci::Circleci.new
128
+ end
129
+
130
+ Dir.mkdir('lois') unless Dir.exist?('lois')
131
+
132
+ config.github = Lois::Github.new(
133
+ config.github_credentials,
134
+ config.ci.organization,
135
+ config.ci.repository,
136
+ config.ci.pull_request_sha
137
+ )
138
+ end
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,55 @@
1
+ require 'httparty'
2
+
3
+ module Lois
4
+ class Github
5
+ Status = Struct.new(:state, :context, :description, :artifact_url)
6
+
7
+ attr_reader :credentials, :organization, :repository, :pull_request_sha
8
+
9
+ def initialize(credentials, organization, repository, pull_request_sha)
10
+ @credentials = credentials
11
+ @organization = organization
12
+ @repository = repository
13
+ @pull_request_sha = pull_request_sha
14
+ end
15
+
16
+ def pending(context, description, artifact_url = nil)
17
+ update_status(Status.new('pending', context, description, artifact_url))
18
+ end
19
+
20
+ def success(context, description, artifact_url = nil)
21
+ update_status(Status.new('success', context, description, artifact_url))
22
+ end
23
+
24
+ def failure(context, description, artifact_url = nil)
25
+ update_status(Status.new('failure', context, description, artifact_url))
26
+ end
27
+
28
+ def pull_request_status_api_url
29
+ @pull_request_status_api_url ||= File.join(
30
+ 'https://api.github.com/repos',
31
+ organization,
32
+ repository,
33
+ 'statuses',
34
+ pull_request_sha
35
+ )
36
+ end
37
+
38
+ private
39
+
40
+ def update_status(status)
41
+ username, password = credentials.split(':')
42
+ auth = { username: username, password: password }
43
+ body = {
44
+ state: status.state,
45
+ context: status.context,
46
+ description: status.description
47
+ }
48
+ body[:target_url] = status.artifact_url if status.artifact_url
49
+ response = ::HTTParty.post(pull_request_status_api_url, basic_auth: auth, body: body.to_json)
50
+ return if response.success?
51
+
52
+ puts "Failed to update github: #{response.code}-#{response.body}"
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ module Lois
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'lois/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'lois'
9
+ spec.version = Lois::VERSION
10
+ spec.authors = ['Ryan Hansen']
11
+ spec.email = ['ketiko@gmail.com']
12
+
13
+ spec.summary = 'Lois reports statuses of CI results to Github Pull Request Statuses.'
14
+ spec.description = 'Lois reports statuses of CI results to Github Pull Request Statuses.'
15
+ spec.homepage = 'https://www.github.com/ketiko/lois'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'awesome_print'
25
+ spec.add_development_dependency 'bundler'
26
+ spec.add_development_dependency 'dotenv'
27
+ spec.add_development_dependency 'pry'
28
+ spec.add_development_dependency 'rake'
29
+ spec.add_development_dependency 'rspec'
30
+ spec.add_development_dependency 'rspec_junit_formatter'
31
+ spec.add_development_dependency 'pry-byebug'
32
+
33
+ spec.add_dependency 'activesupport'
34
+ spec.add_dependency 'httparty'
35
+ spec.add_dependency 'thor'
36
+ spec.add_dependency 'rubocop'
37
+ spec.add_dependency 'reek'
38
+ spec.add_dependency 'bundler-audit'
39
+ spec.add_dependency 'brakeman'
40
+ spec.add_dependency 'simplecov'
41
+ end
metadata ADDED
@@ -0,0 +1,295 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lois
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Hansen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: awesome_print
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dotenv
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec_junit_formatter
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-byebug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: activesupport
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: httparty
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: thor
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rubocop
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: reek
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: bundler-audit
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :runtime
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: brakeman
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :runtime
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: simplecov
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :runtime
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ description: Lois reports statuses of CI results to Github Pull Request Statuses.
238
+ email:
239
+ - ketiko@gmail.com
240
+ executables:
241
+ - lois
242
+ extensions: []
243
+ extra_rdoc_files: []
244
+ files:
245
+ - ".circleci/config.yml"
246
+ - ".gitignore"
247
+ - ".reek"
248
+ - ".rspec"
249
+ - ".rubocop.yml"
250
+ - Gemfile
251
+ - LICENSE
252
+ - README.md
253
+ - Rakefile
254
+ - bin/brakeman
255
+ - bin/bundle-audit
256
+ - bin/bundler-audit
257
+ - bin/code_climate_reek
258
+ - bin/console
259
+ - bin/rake
260
+ - bin/reek
261
+ - bin/rspec
262
+ - bin/rubocop
263
+ - bin/setup
264
+ - exe/lois
265
+ - lib/lois.rb
266
+ - lib/lois/ci.rb
267
+ - lib/lois/ci/circleci.rb
268
+ - lib/lois/cli.rb
269
+ - lib/lois/github.rb
270
+ - lib/lois/version.rb
271
+ - lois.gemspec
272
+ homepage: https://www.github.com/ketiko/lois
273
+ licenses: []
274
+ metadata: {}
275
+ post_install_message:
276
+ rdoc_options: []
277
+ require_paths:
278
+ - lib
279
+ required_ruby_version: !ruby/object:Gem::Requirement
280
+ requirements:
281
+ - - ">="
282
+ - !ruby/object:Gem::Version
283
+ version: '0'
284
+ required_rubygems_version: !ruby/object:Gem::Requirement
285
+ requirements:
286
+ - - ">="
287
+ - !ruby/object:Gem::Version
288
+ version: '0'
289
+ requirements: []
290
+ rubyforge_project:
291
+ rubygems_version: 2.6.12
292
+ signing_key:
293
+ specification_version: 4
294
+ summary: Lois reports statuses of CI results to Github Pull Request Statuses.
295
+ test_files: []