pronto-circleci 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.rubocop.yml +6 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +75 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/circle.yml +6 -0
- data/config/pronto-circleci.yml +7 -0
- data/exe/pronto-circleci +5 -0
- data/lib/pronto/circleci.rb +20 -0
- data/lib/pronto/circleci/config.rb +26 -0
- data/lib/pronto/circleci/pull_request.rb +44 -0
- data/lib/pronto/circleci/runner.rb +44 -0
- data/lib/pronto/circleci/version.rb +5 -0
- data/pronto-circleci.gemspec +32 -0
- metadata +162 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 51c68722b1924b7ab73bd57bdc7d11caac6d061b
|
4
|
+
data.tar.gz: '04813905e572cfecb4facc71d421db448699328d'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 600e263590c6c49e10c58f59b46677de644568c9c9ec765f4e569c20d9e2d1e5ffa7e9fda8a79b533b18b9f41017f3df3ec2b9c01ef954f23511b9d9a69020f6
|
7
|
+
data.tar.gz: fea36915805883164f6991d5ba3a89980d6d4c87767ca39640dbe8ab87027fbc8fbbbc38438089d1853dd335ebe1a8f35770c798d592798496983b60aa5e64d2
|
data/.gitignore
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
|
11
|
+
# rspec failure tracking
|
12
|
+
.rspec_status
|
13
|
+
.byebug_history
|
14
|
+
.rubocop-https---raw-githubusercontent-com-comparaonline-ruby-lint-master-rubocop-yml
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Joaquín Moreira
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# pronto-circleci
|
2
|
+
|
3
|
+
This gem allows to simply setup [pronto](https://github.com/prontolabs/pronto) along with **circleci** and **github**.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
### Application setup
|
8
|
+
|
9
|
+
Add the gem to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'pronto-circleci'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then add the pronto runners of your choice (e.g. `pronto-rubocop`)
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'pronto-rubocop'
|
19
|
+
```
|
20
|
+
|
21
|
+
After that update your bundle:
|
22
|
+
```
|
23
|
+
$ bundle
|
24
|
+
```
|
25
|
+
|
26
|
+
### CircleCI setup
|
27
|
+
|
28
|
+
Setup circle to run pronto before your tests adding this to your `circle.yml`
|
29
|
+
|
30
|
+
```
|
31
|
+
test:
|
32
|
+
pre:
|
33
|
+
- bundle exec pronto-circleci
|
34
|
+
```
|
35
|
+
|
36
|
+
And finally setup an environment variable with a [Github access token](https://help.github.com/articles/creating-an-access-token-for-command-line-use) in the [circleci environment configuration](https://circleci.com/docs/1.0/environment-variables/) of your repo with the name of: `GITHUB_ACCESS_TOKEN`.
|
37
|
+
|
38
|
+
|
39
|
+
## Usage
|
40
|
+
|
41
|
+
Place a `pronto-circleci.yml` under the `config` folder of your app:
|
42
|
+
|
43
|
+
```
|
44
|
+
github:
|
45
|
+
org: 'comparaonline'
|
46
|
+
repo: 'pronto-circleci'
|
47
|
+
pronto:
|
48
|
+
comments_on_diff: true
|
49
|
+
reviews_on_diff: true
|
50
|
+
report_status: true
|
51
|
+
```
|
52
|
+
|
53
|
+
### Config
|
54
|
+
The config flags under the pronto key map to the regular pronto configuration flags:
|
55
|
+
|
56
|
+
`comments_on_diff`: Comments appear on pull request diff.
|
57
|
+
`reviews_on_diff`: Review appear on pull request diff.
|
58
|
+
`report_status`: Report status check on pull request.
|
59
|
+
|
60
|
+
Please note that these are optional and disabled by default.
|
61
|
+
|
62
|
+
|
63
|
+
## Development
|
64
|
+
|
65
|
+
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.
|
66
|
+
|
67
|
+
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).
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pronto-circleci.
|
72
|
+
|
73
|
+
## License
|
74
|
+
|
75
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "pronto/circleci"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/circle.yml
ADDED
data/exe/pronto-circleci
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'pronto/circleci/version'
|
2
|
+
require 'pronto/circleci/runner'
|
3
|
+
|
4
|
+
module Pronto
|
5
|
+
module CircleCI
|
6
|
+
module_function
|
7
|
+
|
8
|
+
def run
|
9
|
+
Runner.run(pull_requests_urls)
|
10
|
+
end
|
11
|
+
|
12
|
+
def pull_requests_urls
|
13
|
+
ENV['CI_PULL_REQUESTS'].split(',')
|
14
|
+
end
|
15
|
+
|
16
|
+
def gem_root
|
17
|
+
Dir.pwd
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'singleton'
|
3
|
+
|
4
|
+
module Pronto
|
5
|
+
module CircleCI
|
6
|
+
class Config
|
7
|
+
include ::Singleton
|
8
|
+
|
9
|
+
CONFIG_FILE_NAME = 'pronto-circleci.yml'.freeze
|
10
|
+
CONFIG_FOLDER = 'config'.freeze
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
file_path = File.join(
|
14
|
+
CircleCI.gem_root,
|
15
|
+
CONFIG_FOLDER,
|
16
|
+
CONFIG_FILE_NAME
|
17
|
+
)
|
18
|
+
@values = YAML.load_file(file_path)
|
19
|
+
end
|
20
|
+
|
21
|
+
def get(*keys)
|
22
|
+
@values.dig(*keys)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'pronto/circleci/config'
|
2
|
+
require 'json'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
module Pronto
|
6
|
+
module CircleCI
|
7
|
+
class PullRequest
|
8
|
+
GITHUB_API_URL = 'https://api.github.com/repos/%{org}/%{repo}/pulls/'\
|
9
|
+
"%{pull_request_id}?access_token=#{ENV['GITHUB_ACCESS_TOKEN']}".freeze
|
10
|
+
|
11
|
+
attr_reader :id, :base_branch
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def load_from_url(url)
|
15
|
+
id = id_from_url(url).to_i
|
16
|
+
api_url = format(
|
17
|
+
GITHUB_API_URL,
|
18
|
+
org: Config.instance.get('github', 'org'),
|
19
|
+
repo: Config.instance.get('github', 'repo'),
|
20
|
+
pull_request_id: id
|
21
|
+
)
|
22
|
+
|
23
|
+
response = JSON.parse(open(api_url).read)
|
24
|
+
new(id, extract_base_branch(response))
|
25
|
+
end
|
26
|
+
|
27
|
+
def id_from_url(url)
|
28
|
+
url.split('/').last
|
29
|
+
end
|
30
|
+
|
31
|
+
def extract_base_branch(response)
|
32
|
+
response.dig('base', 'ref')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def initialize(id, base_branch)
|
39
|
+
@id = id
|
40
|
+
@base_branch = base_branch
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'pronto/circleci/pull_request'
|
2
|
+
|
3
|
+
module Pronto
|
4
|
+
module CircleCI
|
5
|
+
module Runner
|
6
|
+
COMMAND = "PRONTO_GITHUB_ACCESS_TOKEN=#{ENV['GITHUB_ACCESS_TOKEN']} "\
|
7
|
+
'PRONTO_PULL_REQUEST_ID=%{pull_request_id} '\
|
8
|
+
'bundle exec pronto run -f %{flags} -c origin/%{base_branch}'.freeze
|
9
|
+
|
10
|
+
FLAGS_MAP = {
|
11
|
+
'comments_on_diff' => 'github_pr',
|
12
|
+
'reviews_on_diff' => 'github_pr_review',
|
13
|
+
'report_status' => 'github_status'
|
14
|
+
}.freeze
|
15
|
+
|
16
|
+
DEFAULT_FLAG = 'github'.freeze
|
17
|
+
|
18
|
+
module_function
|
19
|
+
|
20
|
+
def run(pull_requests_urls)
|
21
|
+
pull_requests_urls.each do |pr_url|
|
22
|
+
pull_request = PullRequest.load_from_url(pr_url)
|
23
|
+
system(cmd(pull_request))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def cmd(pull_request)
|
28
|
+
format(
|
29
|
+
COMMAND,
|
30
|
+
pull_request_id: pull_request.id,
|
31
|
+
base_branch: pull_request.base_branch,
|
32
|
+
flags: flags
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
def flags
|
37
|
+
flag_list = FLAGS_MAP.inject([]) do |memo, (config_key, flag)|
|
38
|
+
Config.instance.get('pronto', config_key) ? memo << flag : memo
|
39
|
+
end
|
40
|
+
flag_list.any? ? flag_list.join(' ') : DEFAULT_FLAG
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "pronto/circleci/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pronto-circleci"
|
8
|
+
spec.version = Pronto::CircleCI::VERSION
|
9
|
+
spec.authors = ["Joaquín Moreira"]
|
10
|
+
spec.email = ["jmoreiras@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Automate pronto run for use with circleci and github"
|
13
|
+
spec.description = "Easily setup pronto runners with github and circleci"
|
14
|
+
spec.homepage = "https://github.com/comparaonline/pronto-circleci"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.required_ruby_version = '>= 2.3'
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_dependency "pronto", "~> 0.9"
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.2"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
spec.add_development_dependency "webmock", "~> 3.0"
|
30
|
+
spec.add_development_dependency "pronto-rubocop"
|
31
|
+
spec.add_development_dependency "byebug"
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pronto-circleci
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joaquín Moreira
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pronto
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.2'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pronto-rubocop
|
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: byebug
|
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
|
+
description: Easily setup pronto runners with github and circleci
|
112
|
+
email:
|
113
|
+
- jmoreiras@gmail.com
|
114
|
+
executables:
|
115
|
+
- pronto-circleci
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".rubocop.yml"
|
122
|
+
- ".travis.yml"
|
123
|
+
- Gemfile
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/console
|
128
|
+
- bin/setup
|
129
|
+
- circle.yml
|
130
|
+
- config/pronto-circleci.yml
|
131
|
+
- exe/pronto-circleci
|
132
|
+
- lib/pronto/circleci.rb
|
133
|
+
- lib/pronto/circleci/config.rb
|
134
|
+
- lib/pronto/circleci/pull_request.rb
|
135
|
+
- lib/pronto/circleci/runner.rb
|
136
|
+
- lib/pronto/circleci/version.rb
|
137
|
+
- pronto-circleci.gemspec
|
138
|
+
homepage: https://github.com/comparaonline/pronto-circleci
|
139
|
+
licenses:
|
140
|
+
- MIT
|
141
|
+
metadata: {}
|
142
|
+
post_install_message:
|
143
|
+
rdoc_options: []
|
144
|
+
require_paths:
|
145
|
+
- lib
|
146
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '2.3'
|
151
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
156
|
+
requirements: []
|
157
|
+
rubyforge_project:
|
158
|
+
rubygems_version: 2.6.11
|
159
|
+
signing_key:
|
160
|
+
specification_version: 4
|
161
|
+
summary: Automate pronto run for use with circleci and github
|
162
|
+
test_files: []
|