├── .env
├── .gitignore
├── .rspec
├── .ruby-version
├── .travis.yml
├── Gemfile
├── Gemfile.lock
├── Procfile
├── README.md
├── Rakefile
├── app
├── assets
│ ├── images
│ │ └── .keep
│ ├── javascripts
│ │ └── application.js
│ └── stylesheets
│ │ └── application.css
├── controllers
│ ├── application_controller.rb
│ ├── concerns
│ │ └── .keep
│ ├── github_web_hook_controller.rb
│ ├── port_branches_controller.rb
│ ├── reviewerships_controller.rb
│ ├── sessions_controller.rb
│ └── users_controller.rb
├── helpers
│ └── application_helper.rb
├── mailers
│ └── .keep
├── models
│ ├── .keep
│ ├── concerns
│ │ └── .keep
│ ├── port_branch.rb
│ ├── repo.rb
│ ├── reviewership.rb
│ └── user.rb
└── views
│ ├── layouts
│ └── application.html.erb
│ └── users
│ └── show.html.erb
├── bin
├── bundle
├── rails
├── rake
├── setup
└── staging
├── config.ru
├── config
├── application.rb
├── boot.rb
├── database.yml
├── environment.rb
├── environments
│ ├── development.rb
│ ├── production.rb
│ └── test.rb
├── initializers
│ ├── assets.rb
│ ├── backtrace_silencers.rb
│ ├── cookies_serializer.rb
│ ├── filter_parameter_logging.rb
│ ├── inflections.rb
│ ├── mime_types.rb
│ ├── octokit_cache.rb
│ ├── session_store.rb
│ ├── warden_github_rails.rb
│ └── wrap_parameters.rb
├── locales
│ └── en.yml
├── puma.rb
├── routes.rb
└── secrets.yml
├── db
├── migrate
│ ├── 20150802205110_create_users.rb
│ ├── 20150807070756_create_repos.rb
│ ├── 20150807071637_add_github_token_to_user.rb
│ ├── 20150812024841_create_reviewerships.rb
│ ├── 20150813181200_merge_repo_owner_and_name.rb
│ └── 20160626195928_create_port_branches.rb
├── schema.rb
└── seeds.rb
├── lib
├── assets
│ └── .keep
└── tasks
│ └── .keep
├── log
└── .keep
├── public
├── 404.html
├── 422.html
├── 500.html
├── favicon.ico
└── robots.txt
├── spec
├── controllers
│ └── reviewerships_controller_spec.rb
├── models
│ ├── port_branch_spec.rb
│ ├── repo_spec.rb
│ ├── reviewership_spec.rb
│ └── user_spec.rb
├── rails_helper.rb
└── spec_helper.rb
└── vendor
└── assets
├── javascripts
└── .keep
└── stylesheets
└── .keep
/.env:
--------------------------------------------------------------------------------
1 | export GITHUB_CLIENT_ID=565dfdf00f960cdab8a3
2 | export GITHUB_CLIENT_SECRET=9c9e225d831252591931bc17d86fa3b54376dc6b
3 | export GITHUB_WEBHOOK_SECRET=8c0182dc6f270f79b955d0eab426074e7b25c6a65e6151e11e3358194f2b88382f37951e0c7b1e1d15bd3d17d4cd8b8ac46edf98f9d7dcc5c0f54d21d77707df
4 | export GITHUB_WEBHOOK_HOST=http://localhost:3000
5 | export GITHUB_BOT_USERNAME=bundlerbot
6 | export GITHUB_BOT_TOKEN=secret
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2 | #
3 | # If you find yourself ignoring temporary files generated by your text editor
4 | # or operating system, you probably want to add a global ignore instead:
5 | # git config --global core.excludesfile '~/.gitignore_global'
6 |
7 | # Ignore bundler config.
8 | /.bundle
9 |
10 | # Ignore the default SQLite database.
11 | /db/*.sqlite3
12 | /db/*.sqlite3-journal
13 |
14 | # Ignore all logfiles and tempfiles.
15 | /log/*
16 | !/log/.keep
17 | /tmp
18 |
19 | # Ignore Heroku app binstubs
20 | /bin/*
--------------------------------------------------------------------------------
/.rspec:
--------------------------------------------------------------------------------
1 | --color
2 | --require spec_helper
3 |
--------------------------------------------------------------------------------
/.ruby-version:
--------------------------------------------------------------------------------
1 | 2.3.1
2 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: ruby
2 | branches:
3 | only:
4 | - '/^patronus\/.{7,40}/'
5 | cache: bundler
6 | addons:
7 | postgresql: "9.3"
8 | before_script:
9 | - psql -c 'create database patronus_test;' -U postgres
10 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source "https://rubygems.org"
2 |
3 | ruby File.read(".ruby-version").chomp
4 |
5 | gem "rails", "4.2.3"
6 |
7 | gem "faraday-http-cache"
8 | gem "jquery-rails", "~> 4.0"
9 | gem "lograge"
10 | gem "octokit"
11 | gem "pg", "~> 0.18.2"
12 | gem "puma", "~> 3.4.0"
13 | gem "sass-rails", "~> 5.0"
14 | gem "uglifier", ">= 1.3.0"
15 | gem "warden-github-rails", "~> 1.2"
16 |
17 | group :development do
18 | gem "dotenv-rails", "~> 2.0"
19 | gem "pry-byebug", "~> 3.2"
20 | gem "pry-rails", "~> 0.3.4"
21 | gem "web-console", "~> 2.0"
22 | end
23 |
24 | group :development, :test do
25 | gem "rspec-rails", "~> 3.3"
26 | end
27 |
28 | group :production do
29 | gem "memcachier"
30 | gem "dalli"
31 | gem "rails_12factor"
32 | end
33 |
--------------------------------------------------------------------------------
/Gemfile.lock:
--------------------------------------------------------------------------------
1 | GEM
2 | remote: https://rubygems.org/
3 | specs:
4 | actionmailer (4.2.3)
5 | actionpack (= 4.2.3)
6 | actionview (= 4.2.3)
7 | activejob (= 4.2.3)
8 | mail (~> 2.5, >= 2.5.4)
9 | rails-dom-testing (~> 1.0, >= 1.0.5)
10 | actionpack (4.2.3)
11 | actionview (= 4.2.3)
12 | activesupport (= 4.2.3)
13 | rack (~> 1.6)
14 | rack-test (~> 0.6.2)
15 | rails-dom-testing (~> 1.0, >= 1.0.5)
16 | rails-html-sanitizer (~> 1.0, >= 1.0.2)
17 | actionview (4.2.3)
18 | activesupport (= 4.2.3)
19 | builder (~> 3.1)
20 | erubis (~> 2.7.0)
21 | rails-dom-testing (~> 1.0, >= 1.0.5)
22 | rails-html-sanitizer (~> 1.0, >= 1.0.2)
23 | activejob (4.2.3)
24 | activesupport (= 4.2.3)
25 | globalid (>= 0.3.0)
26 | activemodel (4.2.3)
27 | activesupport (= 4.2.3)
28 | builder (~> 3.1)
29 | activerecord (4.2.3)
30 | activemodel (= 4.2.3)
31 | activesupport (= 4.2.3)
32 | arel (~> 6.0)
33 | activesupport (4.2.3)
34 | i18n (~> 0.7)
35 | json (~> 1.7, >= 1.7.7)
36 | minitest (~> 5.1)
37 | thread_safe (~> 0.3, >= 0.3.4)
38 | tzinfo (~> 1.1)
39 | addressable (2.4.0)
40 | arel (6.0.3)
41 | binding_of_caller (0.7.2)
42 | debug_inspector (>= 0.0.1)
43 | builder (3.2.2)
44 | byebug (9.0.5)
45 | coderay (1.1.1)
46 | concurrent-ruby (1.0.2)
47 | dalli (2.7.6)
48 | debug_inspector (0.0.2)
49 | diff-lcs (1.2.5)
50 | dotenv (2.1.1)
51 | dotenv-rails (2.1.1)
52 | dotenv (= 2.1.1)
53 | railties (>= 4.0, < 5.1)
54 | erubis (2.7.0)
55 | execjs (2.7.0)
56 | faraday (0.9.2)
57 | multipart-post (>= 1.2, < 3)
58 | faraday-http-cache (1.3.0)
59 | faraday (~> 0.8)
60 | globalid (0.3.7)
61 | activesupport (>= 4.1.0)
62 | i18n (0.7.0)
63 | jquery-rails (4.1.1)
64 | rails-dom-testing (>= 1, < 3)
65 | railties (>= 4.2.0)
66 | thor (>= 0.14, < 2.0)
67 | json (1.8.3)
68 | lograge (0.4.1)
69 | actionpack (>= 4, < 5.1)
70 | activesupport (>= 4, < 5.1)
71 | railties (>= 4, < 5.1)
72 | loofah (2.0.3)
73 | nokogiri (>= 1.5.9)
74 | mail (2.6.4)
75 | mime-types (>= 1.16, < 4)
76 | memcachier (0.0.2)
77 | method_source (0.8.2)
78 | mime-types (3.1)
79 | mime-types-data (~> 3.2015)
80 | mime-types-data (3.2016.0521)
81 | mini_portile2 (2.1.0)
82 | minitest (5.9.0)
83 | multipart-post (2.0.0)
84 | nokogiri (1.6.8)
85 | mini_portile2 (~> 2.1.0)
86 | pkg-config (~> 1.1.7)
87 | octokit (4.3.0)
88 | sawyer (~> 0.7.0, >= 0.5.3)
89 | pg (0.18.4)
90 | pkg-config (1.1.7)
91 | pry (0.10.4)
92 | coderay (~> 1.1.0)
93 | method_source (~> 0.8.1)
94 | slop (~> 3.4)
95 | pry-byebug (3.4.0)
96 | byebug (~> 9.0)
97 | pry (~> 0.10)
98 | pry-rails (0.3.4)
99 | pry (>= 0.9.10)
100 | puma (3.4.0)
101 | rack (1.6.4)
102 | rack-test (0.6.3)
103 | rack (>= 1.0)
104 | rails (4.2.3)
105 | actionmailer (= 4.2.3)
106 | actionpack (= 4.2.3)
107 | actionview (= 4.2.3)
108 | activejob (= 4.2.3)
109 | activemodel (= 4.2.3)
110 | activerecord (= 4.2.3)
111 | activesupport (= 4.2.3)
112 | bundler (>= 1.3.0, < 2.0)
113 | railties (= 4.2.3)
114 | sprockets-rails
115 | rails-deprecated_sanitizer (1.0.3)
116 | activesupport (>= 4.2.0.alpha)
117 | rails-dom-testing (1.0.7)
118 | activesupport (>= 4.2.0.beta, < 5.0)
119 | nokogiri (~> 1.6.0)
120 | rails-deprecated_sanitizer (>= 1.0.1)
121 | rails-html-sanitizer (1.0.3)
122 | loofah (~> 2.0)
123 | rails_12factor (0.0.3)
124 | rails_serve_static_assets
125 | rails_stdout_logging
126 | rails_serve_static_assets (0.0.5)
127 | rails_stdout_logging (0.0.5)
128 | railties (4.2.3)
129 | actionpack (= 4.2.3)
130 | activesupport (= 4.2.3)
131 | rake (>= 0.8.7)
132 | thor (>= 0.18.1, < 2.0)
133 | rake (11.2.2)
134 | rspec-core (3.5.1)
135 | rspec-support (~> 3.5.0)
136 | rspec-expectations (3.5.0)
137 | diff-lcs (>= 1.2.0, < 2.0)
138 | rspec-support (~> 3.5.0)
139 | rspec-mocks (3.5.0)
140 | diff-lcs (>= 1.2.0, < 2.0)
141 | rspec-support (~> 3.5.0)
142 | rspec-rails (3.5.1)
143 | actionpack (>= 3.0)
144 | activesupport (>= 3.0)
145 | railties (>= 3.0)
146 | rspec-core (~> 3.5.0)
147 | rspec-expectations (~> 3.5.0)
148 | rspec-mocks (~> 3.5.0)
149 | rspec-support (~> 3.5.0)
150 | rspec-support (3.5.0)
151 | sass (3.4.22)
152 | sass-rails (5.0.6)
153 | railties (>= 4.0.0, < 6)
154 | sass (~> 3.1)
155 | sprockets (>= 2.8, < 4.0)
156 | sprockets-rails (>= 2.0, < 4.0)
157 | tilt (>= 1.1, < 3)
158 | sawyer (0.7.0)
159 | addressable (>= 2.3.5, < 2.5)
160 | faraday (~> 0.8, < 0.10)
161 | slop (3.6.0)
162 | sprockets (3.7.0)
163 | concurrent-ruby (~> 1.0)
164 | rack (> 1, < 3)
165 | sprockets-rails (3.1.1)
166 | actionpack (>= 4.0)
167 | activesupport (>= 4.0)
168 | sprockets (>= 3.0.0)
169 | thor (0.19.1)
170 | thread_safe (0.3.5)
171 | tilt (2.0.5)
172 | tzinfo (1.2.2)
173 | thread_safe (~> 0.1)
174 | uglifier (3.0.0)
175 | execjs (>= 0.3.0, < 3)
176 | warden (1.2.6)
177 | rack (>= 1.0)
178 | warden-github (1.3.1)
179 | activesupport (> 3.0)
180 | octokit (> 2.1.0)
181 | warden (> 1.0)
182 | warden-github-rails (1.2.3)
183 | railties (>= 3.1)
184 | warden-github (~> 1.1, >= 1.1.1)
185 | web-console (2.3.0)
186 | activemodel (>= 4.0)
187 | binding_of_caller (>= 0.7.2)
188 | railties (>= 4.0)
189 | sprockets-rails (>= 2.0, < 4.0)
190 |
191 | PLATFORMS
192 | ruby
193 |
194 | DEPENDENCIES
195 | dalli
196 | dotenv-rails (~> 2.0)
197 | faraday-http-cache
198 | jquery-rails (~> 4.0)
199 | lograge
200 | memcachier
201 | octokit
202 | pg (~> 0.18.2)
203 | pry-byebug (~> 3.2)
204 | pry-rails (~> 0.3.4)
205 | puma (~> 3.4.0)
206 | rails (= 4.2.3)
207 | rails_12factor
208 | rspec-rails (~> 3.3)
209 | sass-rails (~> 5.0)
210 | uglifier (>= 1.3.0)
211 | warden-github-rails (~> 1.2)
212 | web-console (~> 2.0)
213 |
214 | RUBY VERSION
215 | ruby 2.3.1p112
216 |
217 | BUNDLED WITH
218 | 1.12.5
219 |
--------------------------------------------------------------------------------
/Procfile:
--------------------------------------------------------------------------------
1 | web: bundle exec puma -C config/puma.rb
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # patronus
2 |
3 | ### keep your integration branch green
4 |
5 | Patronus keeps your integration branch(es) green by monitoring your pull requests. When a pull request is reviewed and approved by a team member, Patronus creates a merge commit, runs the tests, and fast-forwards if the tests pass. Simple.
6 |
7 | ## Architecture
8 |
9 | At a high level, Patronus should need to store no state for any particular build. The only persisted data should be ACL/Auth-related. Everything else should be done in response to webhooks/page views.
10 |
11 | Patronus should not be seek to serve a million users in a single instance. Instead, it should be incredibly simple to deploy to heroku for an individual/team.
12 |
13 | Also, commenting on PRs is rude. Patronus shouldn't do that, and optionally could delete the command comments. (If configured to comment, allow also configuring the GH user to do it as.)
14 |
15 | ### Persisted Data
16 |
17 | #### Project
18 |
19 | Has an associated oauth token to use (the person who authorized). List of reviewers.
20 |
21 | ### Webhooks
22 |
23 | #### Pull Request
24 |
25 | Optionally, run a test against incoming PRs.
26 |
27 | #### Pull Request Issue Comment
28 |
29 | If is approval (`@patronus :+1:`) by an admin, create a new ref (`patronus-HEAD_SHA`) from master, merge in the approved commit. In the merge commit message, track the exact message, so we know what actions to take once testing is finished. Also, create a pending status for the PR ref, with the URL pointing to the PR/commit page on Patronus for that commit.
30 |
31 | Likewise, if `:+1: branch=branch_name`.
32 |
33 | Likewise, if `test`. But this wont cause the target branch to be fast-forwarded to the merge even if it passes.
34 |
35 | If `:-1:`, set Marhsal's status for the merged ref to failed.
36 |
37 | #### Status
38 |
39 | Get the combined status for the ref. If it passed, introspect the commit message. If it has a `@patronus :+1:`, fast forward the target branch to that commit.
40 |
41 | Set the build status of the PR commit to the result of that ref. If configured, send a slack message / post a comment on the PR (and then optionally delete it :P).
42 |
43 | If a `patronus-` branch, delete it.
44 |
45 | ### Web Pages
46 |
47 | #### Project
48 |
49 | List the admin users (and modify that list, if an admin. Use GH auth.) Optionally, be able to set a GH auth token / name / email for the merge commits?
50 |
51 | #### PR
52 |
53 | List all builds for that PR. Optionally, store a set of junit reports that could be rendered (per built commit).
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | # Add your own tasks in files placed in lib/tasks ending in .rake,
2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3 |
4 | require File.expand_path('../config/application', __FILE__)
5 |
6 | Rails.application.load_tasks
7 |
--------------------------------------------------------------------------------
/app/assets/images/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patronus-io/patronus/caaf4cafbcb2a1d139cbc73f220d8f004ef0d1b8/app/assets/images/.keep
--------------------------------------------------------------------------------
/app/assets/javascripts/application.js:
--------------------------------------------------------------------------------
1 | // This is a manifest file that'll be compiled into application.js, which will include all the files
2 | // listed below.
3 | //
4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5 | // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6 | //
7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8 | // compiled file.
9 | //
10 | // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11 | // about supported directives.
12 | //
13 | //= require jquery
14 | //= require jquery_ujs
15 | //= require_tree .
16 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/application.css:
--------------------------------------------------------------------------------
1 | /*
2 | * This is a manifest file that'll be compiled into application.css, which will include all the files
3 | * listed below.
4 | *
5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6 | * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7 | *
8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9 | * compiled file so the styles you add here take precedence over styles defined in any styles
10 | * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11 | * file per style scope.
12 | *
13 | *= require_tree .
14 | *= require_self
15 | */
16 |
--------------------------------------------------------------------------------
/app/controllers/application_controller.rb:
--------------------------------------------------------------------------------
1 | class ApplicationController < ActionController::Base
2 | # Prevent CSRF attacks by raising an exception.
3 | # For APIs, you may want to use :null_session instead.
4 | protect_from_forgery with: :exception
5 |
6 | private
7 |
8 | def current_user
9 | user = User.where(username: github_user.login).first
10 | user ||= User.create_or_update_from_github!(github_user)
11 | end
12 |
13 | end
14 |
--------------------------------------------------------------------------------
/app/controllers/concerns/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patronus-io/patronus/caaf4cafbcb2a1d139cbc73f220d8f004ef0d1b8/app/controllers/concerns/.keep
--------------------------------------------------------------------------------
/app/controllers/github_web_hook_controller.rb:
--------------------------------------------------------------------------------
1 | class GithubWebHookController < ApplicationController
2 | require "openssl"
3 |
4 | GIT_SHA_PATTERN = /[a-f0-9]{40}/
5 | STATUS_CONTEXT = 'merge/patronus'.freeze
6 |
7 | protect_from_forgery with: :null_session
8 |
9 | def create
10 | event = request.headers['X-GitHub-Event'.freeze]
11 | body = request.body.read
12 | verify_signature(body)
13 |
14 | @payload = app_client.parse_payload(body)
15 | find_reviewership!(payload.repository.full_name, payload.sender.login)
16 |
17 | Rails.logger.info { "GitHub: #{repo_name} - #{event}" }
18 |
19 | method_for_event = :"handle_#{event}"
20 | if respond_to?(method_for_event)
21 | send(method_for_event)
22 | render text: "Success!", status: 200
23 | else
24 | render text: "Unrecognized event `#{event}`", status: 501
25 | end
26 | end
27 |
28 | def handle_ping
29 | Rails.logger.info { "-> Ping!" }
30 | end
31 |
32 | def handle_status
33 | regex = /\AAuto merge of PR #(\d+) by patronus from (#{GIT_SHA_PATTERN}).*\n\w+ => (.*)\Z/
34 | return unless payload.commit.commit.message =~ regex
35 | pull_request = $1
36 | parent = $2
37 | comment = $3
38 | Rails.logger.info { "-> PR ##{pull_request}, Parent #{parent[0, 7]}, #{comment.inspect}" }
39 | pull_request = bot_client.pull_request(repo_name, pull_request)
40 | combined_status = bot_client.combined_status(repo_name, payload.commit.sha)
41 | parent_patronus_status = bot_client.statuses(repo_name, parent).find { |s| s.context = STATUS_CONTEXT }
42 | Rails.logger.info { " -> combined: #{combined_status.state}, patronus: #{parent_patronus_status.state}" }
43 | case combined_status.state
44 | when "success", "failure"
45 | unless parent_patronus_status.state == "failure"
46 | bot_client.create_status(repo_name, parent, combined_status.state, context: STATUS_CONTEXT)
47 | end
48 | if combined_status.state == "success" && bot_client.combined_status(repo_name, parent).state == "success" && %w(:+1: retry).include?(comment)
49 | bot_client.update_branch(repo_name, pull_request.base.ref, payload.commit.sha, false)
50 | if pull_request.head.repo.full_name == repo_name
51 | bot_client.delete_branch(repo_name, pull_request.head.ref) rescue nil
52 | end
53 | end
54 | bot_client.delete_branch(repo_name, "patronus/#{parent}") rescue nil
55 | else
56 | # wait until all done
57 | end
58 | end
59 |
60 | def handle_issue_comment
61 | return unless payload.action.eql? 'created'
62 | commenter = payload.comment.user.login
63 | return unless bot_client.collaborator?(repo_name, commenter)
64 | comment = payload.comment.body
65 | return unless comment.gsub!(/\Apatronus: /, "")
66 | comment.strip!
67 | issue_number = payload.issue.number
68 | return unless pull_request = bot_client.pull_request(repo_name, issue_number)
69 | head = pull_request.head.sha
70 |
71 | Rails.logger.info { "-> PR #{issue_number} - #{commenter}: #{comment.inspect}, HEAD #{head[0, 7]}" }
72 |
73 | case comment
74 | when ":+1:", "test", "retry"
75 | test_branch = "patronus/#{head}"
76 | Rails.logger.info { " -> Creating pending status on PR HEAD" }
77 | bot_client.create_status(repo_name, head, "pending", context: STATUS_CONTEXT)
78 | Rails.logger.info { " -> Creating test ref #{test_branch.inspect} based on #{pull_request.base.sha[0, 7]}" }
79 | target_branch = bot_client.branch(repo_name, pull_request.base.ref)
80 | bot_client.create_ref(repo_name, "heads/#{test_branch}", target_branch.commit.sha)
81 | message = <<-MSG.strip_heredoc
82 | Auto merge of PR ##{issue_number} by patronus from #{head} onto #{pull_request.base.label}
83 | #{commenter} => #{comment}
84 | MSG
85 | Rails.logger.info { " -> Merging PR HEAD into test branch" }
86 | bot_client.merge(repo_name, test_branch, head, commit_message: message)
87 | when ":-1:"
88 | Rails.logger.info { " -> Creating failure status on PR HEAD" }
89 | bot_client.create_status(repo_name, head, "failure", context: STATUS_CONTEXT)
90 | when "fork"
91 | Rails.logger.info { " -> Creating a local branch from PR HEAD" }
92 | bot_client.create_ref(repo_name, "heads/patronus-pr-#{issue_number}", head)
93 | end
94 | end
95 |
96 | def handle_pull_request
97 | return unless payload.action.eql? 'closed'
98 | pull_request = payload.pull_request
99 | return unless payload.pull_request and pull_request.merged
100 |
101 | port_branch_base = pull_request.base.ref
102 |
103 | port_branches = repo.port_branches.where(base: port_branch_base)
104 |
105 | port_branches.each do |port_branch|
106 | port_branch_dev = port_branch.dev
107 |
108 | head_sha = pull_request.head.sha
109 |
110 | feature_branch = if repo_name.eql? pull_request.head.repo.full_name
111 | pull_request.head.label
112 | else
113 | branch_name = "patronus-pr-#{port_branch_dev}-#{pull_request.number}"
114 | bot_client.create_ref(repo_name, "heads/#{branch_name}", head_sha)
115 | branch_name
116 | end
117 |
118 | bot_client.create_pull_request(repo_name, port_branch_dev, feature_branch, "[port] #{pull_request.title}", <<-MSG.strip_heredoc)
119 | Introduces changes from pull request ##{pull_request.number} into development branch `#{port_branch_dev}`.
120 |
121 | *Original pull request's description:*
122 | #{pull_request.body}
123 | MSG
124 | end
125 | end
126 |
127 | private
128 |
129 | def verify_signature(payload_body)
130 | secret = ENV['GITHUB_WEBHOOK_SECRET'.freeze]
131 | expected_signature = request.headers['X-HUB-SIGNATURE'.freeze] || ''
132 | return unless secret
133 | signature = 'sha1=' << OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), secret, payload_body)
134 | status = 401 && render(text: "Signatures didn't match!") unless Rack::Utils.secure_compare(signature, expected_signature)
135 | end
136 |
137 | attr_reader :user, :repo_name, :user_client, :payload, :repo, :reviewership
138 | def find_reviewership!(repo, sender)
139 | if sender.eql? ENV['GITHUB_BOT_USERNAME'.freeze]
140 | # fake user and reviewership for the bot
141 | @user = User.new(username: ENV['GITHUB_BOT_USERNAME'.freeze], github_token: ENV['GITHUB_BOT_TOKEN'.freeze])
142 | @repo = Repo.find_by_name repo
143 | @reviewership = Reviewership.new(user: @user, repo: @repo)
144 | @repo_name = repo
145 | @user_client = @user.github
146 | else
147 | @reviewership = Reviewership.joins(:user).where('users.username' => sender).joins(:repo).where('repos.name' => repo).first!
148 | @repo = @reviewership.repo
149 | @user = @reviewership.user
150 | @repo_name = repo
151 | @user_client = @user.github
152 | end
153 | end
154 |
155 | def app_client
156 | @app_client ||= Octokit::Client.new(client_id: ENV['GITHUB_CLIENT_ID'.freeze], client_secret: ENV['GITHUB_CLIENT_SECRET'.freeze])
157 | end
158 |
159 | def bot_client
160 | # uses bot account if it has permissions, otherwise uses user account
161 | @bot_client ||= begin
162 | if @user_client.collaborator?(@repo.name, ENV['GITHUB_BOT_USERNAME'.freeze])
163 | Octokit::Client.new(:access_token => ENV['GITHUB_BOT_TOKEN'.freeze])
164 | else
165 | Rails.logger.warn { 'Bot does not have permissions, using user account to interact' }
166 | @user_client
167 | end
168 | end
169 | end
170 | end
171 |
--------------------------------------------------------------------------------
/app/controllers/port_branches_controller.rb:
--------------------------------------------------------------------------------
1 | class PortBranchesController < ApplicationController
2 | before_filter :set_repo, :only => :create
3 |
4 | def create
5 | if @repo && @port_branch = PortBranch.create(port_branch_params)
6 | @repo.port_branches << @port_branch
7 | end
8 | redirect_to(profile_path)
9 | end
10 |
11 | private
12 |
13 | def set_repo
14 | @repo = Repo.find(params[:repo_id])
15 | end
16 |
17 | def port_branch_params
18 | params.require(:port_branch).permit(:base, :dev)
19 | end
20 | end
21 |
--------------------------------------------------------------------------------
/app/controllers/reviewerships_controller.rb:
--------------------------------------------------------------------------------
1 | class ReviewershipsController < ApplicationController
2 | def create
3 | Reviewership.create!(reviewership_params) do |reviewership|
4 | reviewership.ensure_webhook_installed!
5 | reviewership.ensure_bot_permissions!
6 | end
7 | redirect_to(profile_path)
8 | end
9 |
10 | private
11 |
12 | def reviewership_params
13 | params.require(:reviewership).permit(repo: [:owner, :name]).tap do |p|
14 | p[:repo_attributes] = p.delete(:repo)
15 | p[:user] = current_user
16 | end
17 | end
18 | end
19 |
--------------------------------------------------------------------------------
/app/controllers/sessions_controller.rb:
--------------------------------------------------------------------------------
1 | class SessionsController < ApplicationController
2 | def create
3 | github_authenticate!
4 | User.create_or_update_from_github!(github_user)
5 | redirect_to profile_path
6 | end
7 |
8 | def destroy
9 | github_logout
10 | redirect_to root_path
11 | end
12 | end
13 |
--------------------------------------------------------------------------------
/app/controllers/users_controller.rb:
--------------------------------------------------------------------------------
1 | class UsersController < ApplicationController
2 | def show
3 | @user = current_user
4 | @repos = current_user.repos
5 | end
6 | end
--------------------------------------------------------------------------------
/app/helpers/application_helper.rb:
--------------------------------------------------------------------------------
1 | module ApplicationHelper
2 | end
3 |
--------------------------------------------------------------------------------
/app/mailers/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patronus-io/patronus/caaf4cafbcb2a1d139cbc73f220d8f004ef0d1b8/app/mailers/.keep
--------------------------------------------------------------------------------
/app/models/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patronus-io/patronus/caaf4cafbcb2a1d139cbc73f220d8f004ef0d1b8/app/models/.keep
--------------------------------------------------------------------------------
/app/models/concerns/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patronus-io/patronus/caaf4cafbcb2a1d139cbc73f220d8f004ef0d1b8/app/models/concerns/.keep
--------------------------------------------------------------------------------
/app/models/port_branch.rb:
--------------------------------------------------------------------------------
1 | class PortBranch < ActiveRecord::Base
2 | belongs_to :repo
3 | end
4 |
--------------------------------------------------------------------------------
/app/models/repo.rb:
--------------------------------------------------------------------------------
1 | class Repo < ActiveRecord::Base
2 | has_many :reviewerships
3 | has_many :users, through: :reviewerships
4 | has_many :port_branches
5 |
6 | def to_s
7 | name
8 | end
9 | end
10 |
--------------------------------------------------------------------------------
/app/models/reviewership.rb:
--------------------------------------------------------------------------------
1 | class Reviewership < ActiveRecord::Base
2 | belongs_to :user
3 | belongs_to :repo
4 |
5 | accepts_nested_attributes_for :repo
6 |
7 | def ensure_webhook_installed!
8 | hook_url = Rails.application.routes.url_helpers.url_for controller: "github_web_hook", action: "create", host: ENV['GITHUB_WEBHOOK_HOST'.freeze]
9 | unless user.github.hooks(repo.name).find { |hook| hook.url == hook_url }
10 | config = { url: hook_url, content_type: :json, secret: ENV['GITHUB_WEBHOOK_SECRET'.freeze] }
11 | user.github.create_hook(repo.name, "web", config, { events: ["*"] })
12 | end
13 | end
14 |
15 | def ensure_bot_permissions!
16 | unless user.github.collaborator?(repo.name, ENV['GITHUB_BOT_USERNAME'.freeze])
17 | # adds bot to repo with push access, even on organization-owned repos
18 | user.github.add_collaborator(repo.name, ENV['GITHUB_BOT_USERNAME'.freeze])
19 | end
20 | end
21 | end
22 |
--------------------------------------------------------------------------------
/app/models/user.rb:
--------------------------------------------------------------------------------
1 | class User < ActiveRecord::Base
2 | has_many :reviewerships
3 | has_many :repos, through: :reviewerships
4 |
5 | def self.create_or_update_from_github!(github_user)
6 | with_token = User.create_with(github_token: github_user.token)
7 | user = with_token.find_or_create_by!(username: github_user.login)
8 | user.tap{|u| u.update!(github_token: github_user.token) }
9 | end
10 |
11 | def profile_url
12 | github_info.rels[:html].href
13 | end
14 |
15 | def avatar_url
16 | github_info.rels[:avatar].href
17 | end
18 |
19 | def github_info
20 | @github_info ||= github.user(username)
21 | end
22 |
23 | def github
24 | @github ||= Octokit::Client.new(:access_token => github_token)
25 | end
26 |
27 | end
28 |
--------------------------------------------------------------------------------
/app/views/layouts/application.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Patronus
5 | <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6 | <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7 | <%= csrf_meta_tags %>
8 |
9 |
10 |
11 | <%= yield %>
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/views/users/show.html.erb:
--------------------------------------------------------------------------------
1 |
2 | <%= image_tag @user.avatar_url, width: 50, height: 50 %>
3 | <%= link_to @user.username, @user.profile_url %>
4 |
5 |
6 | Repositories
7 | <%- if @repos.empty? -%>
8 | No repos enabled yet!
9 | <%- else -%>
10 | <%- @repos.group_by { |r| r.name.split('/').first }.each do |org, repos| -%>
11 | <%= link_to org, "https://github.com/#{org}" %>
12 |
13 | <%- repos.each do |repo| -%>
14 | -
15 | <%= link_to repo, "https://github.com/#{repo}" %>
16 |
17 | <%- repo.port_branches.each do |port_branch| -%>
18 | - Port PRs made to <%= port_branch.base %> to development branch <%= port_branch.dev %>
19 | <%- end -%>
20 | -
21 | <%= form_for [repo, PortBranch.new] do |f| %>
22 | New port:
23 | <%= f.label "base", "base branch name" %>
24 | <%= f.text_field "base" %>
25 | <%= f.label "dev", "dev branch name" %>
26 | <%= f.text_field "dev" %>
27 | <%= f.submit "Add" %>
28 | <% end %>
29 |
30 |
31 |
32 | <%- end -%>
33 |
34 | <%- end -%>
35 | <%- end -%>
36 |
37 | Add Repository
38 | <%= form_for Reviewership.new do |f| %>
39 | <%= f.fields_for Repo.new do |r| %>
40 |
41 | <%= r.label "name", "owner/reponame" %>
42 | <%= r.text_field "name" %>
43 |
44 | <% end %>
45 | <%= f.submit "Add" %>
46 | <% end %>
47 |
--------------------------------------------------------------------------------
/bin/bundle:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3 | load Gem.bin_path('bundler', 'bundle')
4 |
--------------------------------------------------------------------------------
/bin/rails:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | APP_PATH = File.expand_path('../../config/application', __FILE__)
3 | require_relative '../config/boot'
4 | require 'rails/commands'
5 |
--------------------------------------------------------------------------------
/bin/rake:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require_relative '../config/boot'
3 | require 'rake'
4 | Rake.application.run
5 |
--------------------------------------------------------------------------------
/bin/setup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require 'pathname'
3 |
4 | # path to your application root.
5 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6 |
7 | Dir.chdir APP_ROOT do
8 | # This script is a starting point to setup your application.
9 | # Add necessary setup steps to this file:
10 |
11 | puts "== Installing dependencies =="
12 | system "gem install bundler --conservative"
13 | system "bundle check || bundle install"
14 |
15 | # puts "\n== Copying sample files =="
16 | # unless File.exist?("config/database.yml")
17 | # system "cp config/database.yml.sample config/database.yml"
18 | # end
19 |
20 | puts "\n== Preparing database =="
21 | system "bin/rake db:setup"
22 |
23 | puts "\n== Removing old logs and tempfiles =="
24 | system "rm -f log/*"
25 | system "rm -rf tmp/cache"
26 |
27 | puts "\n== Restarting application server =="
28 | system "touch tmp/restart.txt"
29 | end
30 |
--------------------------------------------------------------------------------
/bin/staging:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | HEROKU_APP=patronus-staging HKAPP=patronus-staging exec "${HEROKU_COMMAND:-heroku}" "$@"
3 |
--------------------------------------------------------------------------------
/config.ru:
--------------------------------------------------------------------------------
1 | # This file is used by Rack-based servers to start the application.
2 |
3 | require ::File.expand_path('../config/environment', __FILE__)
4 | run Rails.application
5 |
--------------------------------------------------------------------------------
/config/application.rb:
--------------------------------------------------------------------------------
1 | require File.expand_path('../boot', __FILE__)
2 |
3 | require 'rails/all'
4 |
5 | # Require the gems listed in Gemfile, including any gems
6 | # you've limited to :test, :development, or :production.
7 | Bundler.require(*Rails.groups)
8 |
9 | module Patronus
10 | class Application < Rails::Application
11 | # Do not swallow errors in after_commit/after_rollback callbacks.
12 | config.active_record.raise_in_transactional_callbacks = true
13 |
14 | # Filter password out of logs
15 | config.filter_parameters += [:password]
16 | end
17 | end
18 |
--------------------------------------------------------------------------------
/config/boot.rb:
--------------------------------------------------------------------------------
1 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
2 |
3 | require 'bundler/setup' # Set up gems listed in the Gemfile.
4 |
--------------------------------------------------------------------------------
/config/database.yml:
--------------------------------------------------------------------------------
1 | default: &default
2 | adapter: postgresql
3 |
4 | development:
5 | <<: *default
6 | database: patronus
7 |
8 | test:
9 | <<: *default
10 | database: patronus_test
11 |
--------------------------------------------------------------------------------
/config/environment.rb:
--------------------------------------------------------------------------------
1 | # Load the Rails application.
2 | require File.expand_path('../application', __FILE__)
3 |
4 | # Initialize the Rails application.
5 | Rails.application.initialize!
6 |
--------------------------------------------------------------------------------
/config/environments/development.rb:
--------------------------------------------------------------------------------
1 | Rails.application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # In the development environment your application's code is reloaded on
5 | # every request. This slows down response time but is perfect for development
6 | # since you don't have to restart the web server when you make code changes.
7 | config.cache_classes = false
8 |
9 | # Do not eager load code on boot.
10 | config.eager_load = false
11 |
12 | # Show full error reports and disable caching.
13 | config.consider_all_requests_local = true
14 | config.action_controller.perform_caching = false
15 |
16 | # Don't care if the mailer can't send.
17 | config.action_mailer.raise_delivery_errors = false
18 |
19 | # Print deprecation notices to the Rails logger.
20 | config.active_support.deprecation = :log
21 |
22 | # Raise an error on page load if there are pending migrations.
23 | config.active_record.migration_error = :page_load
24 |
25 | # Debug mode disables concatenation and preprocessing of assets.
26 | # This option may cause significant delays in view rendering with a large
27 | # number of complex assets.
28 | config.assets.debug = true
29 |
30 | # Asset digests allow you to set far-future HTTP expiration dates on all assets,
31 | # yet still be able to expire them through the digest params.
32 | config.assets.digest = true
33 |
34 | # Adds additional error checking when serving assets at runtime.
35 | # Checks for improperly declared sprockets dependencies.
36 | # Raises helpful error messages.
37 | config.assets.raise_runtime_errors = true
38 |
39 | # Raises error for missing translations
40 | # config.action_view.raise_on_missing_translations = true
41 | end
42 |
--------------------------------------------------------------------------------
/config/environments/production.rb:
--------------------------------------------------------------------------------
1 | Rails.application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # Code is not reloaded between requests.
5 | config.cache_classes = true
6 |
7 | # Config dalli
8 | config.cache_store = :dalli_store,
9 | (ENV["MEMCACHIER_SERVERS"] || "").split(","),
10 | {:username => ENV["MEMCACHIER_USERNAME"],
11 | :password => ENV["MEMCACHIER_PASSWORD"],
12 | :failover => true,
13 | :socket_timeout => 1.5,
14 | :socket_failure_delay => 0.2
15 | }
16 |
17 | # Eager load code on boot. This eager loads most of Rails and
18 | # your application in memory, allowing both threaded web servers
19 | # and those relying on copy on write to perform better.
20 | # Rake tasks automatically ignore this option for performance.
21 | config.eager_load = true
22 |
23 | # Full error reports are disabled and caching is turned on.
24 | config.consider_all_requests_local = false
25 | config.action_controller.perform_caching = true
26 |
27 | # Enable Rack::Cache to put a simple HTTP cache in front of your application
28 | # Add `rack-cache` to your Gemfile before enabling this.
29 | # For large-scale production use, consider using a caching reverse proxy like
30 | # NGINX, varnish or squid.
31 | # config.action_dispatch.rack_cache = true
32 |
33 | # Disable serving static files from the `/public` folder by default since
34 | # Apache or NGINX already handles this.
35 | config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
36 |
37 | # Compress JavaScripts and CSS.
38 | config.assets.js_compressor = :uglifier
39 | # config.assets.css_compressor = :sass
40 |
41 | # Do not fallback to assets pipeline if a precompiled asset is missed.
42 | config.assets.compile = false
43 |
44 | # Asset digests allow you to set far-future HTTP expiration dates on all assets,
45 | # yet still be able to expire them through the digest params.
46 | config.assets.digest = true
47 |
48 | # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
49 |
50 | # Specifies the header that your server uses for sending files.
51 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
52 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
53 |
54 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
55 | # config.force_ssl = true
56 |
57 | # Use the lowest log level to ensure availability of diagnostic information
58 | # when problems arise.
59 | config.log_level = :debug
60 |
61 | # Keep me sane when reading logs
62 | config.lograge.enabled = true
63 |
64 | # Prepend all log lines with the following tags.
65 | # config.log_tags = [ :subdomain, :uuid ]
66 |
67 | # Use a different logger for distributed setups.
68 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
69 |
70 | # Use a different cache store in production.
71 | config.cache_store = :dalli_store
72 |
73 | # Enable serving of images, stylesheets, and JavaScripts from an asset server.
74 | # config.action_controller.asset_host = 'http://assets.example.com'
75 |
76 | # Ignore bad email addresses and do not raise email delivery errors.
77 | # Set this to true and configure the email server for immediate delivery to raise delivery errors.
78 | # config.action_mailer.raise_delivery_errors = false
79 |
80 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
81 | # the I18n.default_locale when a translation cannot be found).
82 | config.i18n.fallbacks = true
83 |
84 | # Send deprecation notices to registered listeners.
85 | config.active_support.deprecation = :notify
86 |
87 | # Use default logging formatter so that PID and timestamp are not suppressed.
88 | config.log_formatter = ::Logger::Formatter.new
89 |
90 | # Do not dump schema after migrations.
91 | config.active_record.dump_schema_after_migration = false
92 | end
93 |
--------------------------------------------------------------------------------
/config/environments/test.rb:
--------------------------------------------------------------------------------
1 | Rails.application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # The test environment is used exclusively to run your application's
5 | # test suite. You never need to work with it otherwise. Remember that
6 | # your test database is "scratch space" for the test suite and is wiped
7 | # and recreated between test runs. Don't rely on the data there!
8 | config.cache_classes = true
9 |
10 | # Do not eager load code on boot. This avoids loading your whole application
11 | # just for the purpose of running a single test. If you are using a tool that
12 | # preloads Rails for running tests, you may have to set it to true.
13 | config.eager_load = false
14 |
15 | # Configure static file server for tests with Cache-Control for performance.
16 | config.serve_static_files = true
17 | config.static_cache_control = 'public, max-age=3600'
18 |
19 | # Show full error reports and disable caching.
20 | config.consider_all_requests_local = true
21 | config.action_controller.perform_caching = false
22 |
23 | # Raise exceptions instead of rendering exception templates.
24 | config.action_dispatch.show_exceptions = false
25 |
26 | # Disable request forgery protection in test environment.
27 | config.action_controller.allow_forgery_protection = false
28 |
29 | # Tell Action Mailer not to deliver emails to the real world.
30 | # The :test delivery method accumulates sent emails in the
31 | # ActionMailer::Base.deliveries array.
32 | config.action_mailer.delivery_method = :test
33 |
34 | # Randomize the order test cases are executed.
35 | config.active_support.test_order = :random
36 |
37 | # Print deprecation notices to the stderr.
38 | config.active_support.deprecation = :stderr
39 |
40 | # Raises error for missing translations
41 | # config.action_view.raise_on_missing_translations = true
42 | end
43 |
--------------------------------------------------------------------------------
/config/initializers/assets.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Version of your assets, change this if you want to expire all your assets.
4 | Rails.application.config.assets.version = '1.0'
5 |
6 | # Add additional assets to the asset load path
7 | # Rails.application.config.assets.paths << Emoji.images_path
8 |
9 | # Precompile additional assets.
10 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
11 | # Rails.application.config.assets.precompile += %w( search.js )
12 |
--------------------------------------------------------------------------------
/config/initializers/backtrace_silencers.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5 |
6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7 | # Rails.backtrace_cleaner.remove_silencers!
8 |
--------------------------------------------------------------------------------
/config/initializers/cookies_serializer.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | Rails.application.config.action_dispatch.cookies_serializer = :json
4 |
--------------------------------------------------------------------------------
/config/initializers/filter_parameter_logging.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Configure sensitive parameters which will be filtered from the log file.
4 | Rails.application.config.filter_parameters += [:password]
5 |
--------------------------------------------------------------------------------
/config/initializers/inflections.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new inflection rules using the following format. Inflections
4 | # are locale specific, and you may define rules for as many different
5 | # locales as you wish. All of these examples are active by default:
6 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
7 | # inflect.plural /^(ox)$/i, '\1en'
8 | # inflect.singular /^(ox)en/i, '\1'
9 | # inflect.irregular 'person', 'people'
10 | # inflect.uncountable %w( fish sheep )
11 | # end
12 |
13 | # These inflection rules are supported but not enabled by default:
14 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
15 | # inflect.acronym 'RESTful'
16 | # end
17 |
--------------------------------------------------------------------------------
/config/initializers/mime_types.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new mime types for use in respond_to blocks:
4 | # Mime::Type.register "text/richtext", :rtf
5 |
--------------------------------------------------------------------------------
/config/initializers/octokit_cache.rb:
--------------------------------------------------------------------------------
1 | Octokit.middleware = Faraday::RackBuilder.new do |builder|
2 | builder.use Faraday::HttpCache, store: Rails.cache
3 | builder.use Octokit::Response::RaiseError
4 | builder.adapter Faraday.default_adapter
5 | end
6 |
--------------------------------------------------------------------------------
/config/initializers/session_store.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | Rails.application.config.session_store :cookie_store, key: '_patronus_session'
4 |
--------------------------------------------------------------------------------
/config/initializers/warden_github_rails.rb:
--------------------------------------------------------------------------------
1 | Warden::GitHub::Rails.setup do |config|
2 | config.add_scope :user, redirect_uri: '/login', scope: 'user:email,read:org,write:repo_hook,repo'
3 | end
4 |
--------------------------------------------------------------------------------
/config/initializers/wrap_parameters.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # This file contains settings for ActionController::ParamsWrapper which
4 | # is enabled by default.
5 |
6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7 | ActiveSupport.on_load(:action_controller) do
8 | wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
9 | end
10 |
11 | # To enable root element in JSON for ActiveRecord objects.
12 | # ActiveSupport.on_load(:active_record) do
13 | # self.include_root_in_json = true
14 | # end
15 |
--------------------------------------------------------------------------------
/config/locales/en.yml:
--------------------------------------------------------------------------------
1 | # Files in the config/locales directory are used for internationalization
2 | # and are automatically loaded by Rails. If you want to use locales other
3 | # than English, add the necessary files in this directory.
4 | #
5 | # To use the locales, use `I18n.t`:
6 | #
7 | # I18n.t 'hello'
8 | #
9 | # In views, this is aliased to just `t`:
10 | #
11 | # <%= t('hello') %>
12 | #
13 | # To use a different locale, set it with `I18n.locale`:
14 | #
15 | # I18n.locale = :es
16 | #
17 | # This would use the information in config/locales/es.yml.
18 | #
19 | # To learn more, please read the Rails Internationalization guide
20 | # available at http://guides.rubyonrails.org/i18n.html.
21 |
22 | en:
23 | hello: "Hello world"
24 |
--------------------------------------------------------------------------------
/config/puma.rb:
--------------------------------------------------------------------------------
1 | workers Integer(ENV['WEB_CONCURRENCY'] || 2)
2 | threads_count = Integer(ENV['MAX_THREADS'] || 5)
3 | threads threads_count, threads_count
4 |
5 | preload_app!
6 |
7 | rackup DefaultRackup
8 | port ENV['PORT'] || 3000
9 | environment ENV['RACK_ENV'] || 'development'
10 |
11 | on_worker_boot do
12 | # Worker specific setup for Rails 4.1+
13 | # See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
14 | ActiveRecord::Base.establish_connection
15 | end
16 |
--------------------------------------------------------------------------------
/config/routes.rb:
--------------------------------------------------------------------------------
1 | Rails.application.routes.draw do
2 | post "/github/webhook" => "github_web_hook#create"
3 |
4 | github_authenticate do
5 | get '/profile' => 'users#show', as: :profile
6 | resource :reviewerships, only: [:create]
7 | post '/repos/:repo_id/port_branches' => 'port_branches#create', as: :repo_port_branches
8 | end
9 |
10 | get '/login' => 'sessions#create', as: :login
11 | get '/logout' => 'sessions#destroy', as: :logout
12 |
13 | root to: 'sessions#create'
14 | end
15 |
--------------------------------------------------------------------------------
/config/secrets.yml:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Your secret key is used for verifying the integrity of signed cookies.
4 | # If you change this key, all old signed cookies will become invalid!
5 |
6 | # Make sure the secret is at least 30 characters and all random,
7 | # no regular words or you'll be exposed to dictionary attacks.
8 | # You can use `rake secret` to generate a secure secret key.
9 |
10 | # Make sure the secrets in this file are kept private
11 | # if you're sharing your code publicly.
12 |
13 | development:
14 | secret_key_base: fa2d4e4b20fccec4ea278cf9e417aeaf486c4ed795bb6f11b7c8ea612de46f2370efdd555de5b35d4ae5f9c353952ba4f2632dd8620f332c5f82efcd46a4fb97
15 |
16 | test:
17 | secret_key_base: e80b08ca834d923e2368d66f68ecd0f5da12d0f75900d4a905ef4ade99a631e284df0893e30fcdf5fb2ab086575e86dc8d1e866d1a9425d4783b02a58c0ba18e
18 |
19 | # Do not keep production secrets in the repository,
20 | # instead read values from the environment.
21 | production:
22 | secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
23 |
--------------------------------------------------------------------------------
/db/migrate/20150802205110_create_users.rb:
--------------------------------------------------------------------------------
1 | class CreateUsers < ActiveRecord::Migration
2 | def change
3 | create_table :users do |t|
4 | t.string :username, unique: true, null: false
5 | t.timestamps null: false
6 | end
7 |
8 | add_index :users, :username
9 | end
10 | end
11 |
--------------------------------------------------------------------------------
/db/migrate/20150807070756_create_repos.rb:
--------------------------------------------------------------------------------
1 | class CreateRepos < ActiveRecord::Migration
2 | def change
3 | create_table :repos do |t|
4 | t.belongs_to :user
5 | t.string :name, null: false, unique: true
6 | t.timestamps null: false
7 | end
8 | end
9 | end
10 |
--------------------------------------------------------------------------------
/db/migrate/20150807071637_add_github_token_to_user.rb:
--------------------------------------------------------------------------------
1 | class AddGithubTokenToUser < ActiveRecord::Migration
2 | def change
3 | add_column :users, :github_token, :string, null: false
4 | end
5 | end
6 |
--------------------------------------------------------------------------------
/db/migrate/20150812024841_create_reviewerships.rb:
--------------------------------------------------------------------------------
1 | class CreateReviewerships < ActiveRecord::Migration
2 | def change
3 | create_table :reviewerships do |t|
4 | t.belongs_to :user, index: true, foreign_key: true
5 | t.belongs_to :repo, index: true, foreign_key: true
6 | t.timestamps null: false
7 | end
8 |
9 | remove_column :repos, :user_id
10 | add_column :repos, :owner, :string, null: false
11 | end
12 | end
13 |
--------------------------------------------------------------------------------
/db/migrate/20150813181200_merge_repo_owner_and_name.rb:
--------------------------------------------------------------------------------
1 | class MergeRepoOwnerAndName < ActiveRecord::Migration
2 | def change
3 | Repo.find_each{|r| r.update! name: [r.owner, r.name].join("/") }
4 |
5 | remove_column :repos, :owner
6 | end
7 | end
8 |
--------------------------------------------------------------------------------
/db/migrate/20160626195928_create_port_branches.rb:
--------------------------------------------------------------------------------
1 | class CreatePortBranches < ActiveRecord::Migration
2 | def change
3 | create_table :port_branches do |t|
4 | t.belongs_to :repo, index: true, foreign_key: true
5 | t.string :base
6 | t.string :dev
7 |
8 | t.timestamps null: false
9 | end
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/db/schema.rb:
--------------------------------------------------------------------------------
1 | # encoding: UTF-8
2 | # This file is auto-generated from the current state of the database. Instead
3 | # of editing this file, please use the migrations feature of Active Record to
4 | # incrementally modify your database, and then regenerate this schema definition.
5 | #
6 | # Note that this schema.rb definition is the authoritative source for your
7 | # database schema. If you need to create the application database on another
8 | # system, you should be using db:schema:load, not running all the migrations
9 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10 | # you'll amass, the slower it'll run and the greater likelihood for issues).
11 | #
12 | # It's strongly recommended that you check this file into your version control system.
13 |
14 | ActiveRecord::Schema.define(version: 20160626195928) do
15 |
16 | # These are extensions that must be enabled in order to support this database
17 | enable_extension "plpgsql"
18 |
19 | create_table "port_branches", force: :cascade do |t|
20 | t.integer "repo_id"
21 | t.string "base"
22 | t.string "dev"
23 | t.datetime "created_at", null: false
24 | t.datetime "updated_at", null: false
25 | end
26 |
27 | add_index "port_branches", ["repo_id"], name: "index_port_branches_on_repo_id", using: :btree
28 |
29 | create_table "repos", force: :cascade do |t|
30 | t.string "name", null: false
31 | t.datetime "created_at", null: false
32 | t.datetime "updated_at", null: false
33 | end
34 |
35 | create_table "reviewerships", force: :cascade do |t|
36 | t.integer "user_id"
37 | t.integer "repo_id"
38 | t.datetime "created_at", null: false
39 | t.datetime "updated_at", null: false
40 | end
41 |
42 | add_index "reviewerships", ["repo_id"], name: "index_reviewerships_on_repo_id", using: :btree
43 | add_index "reviewerships", ["user_id"], name: "index_reviewerships_on_user_id", using: :btree
44 |
45 | create_table "users", force: :cascade do |t|
46 | t.string "username", null: false
47 | t.datetime "created_at", null: false
48 | t.datetime "updated_at", null: false
49 | t.string "github_token", null: false
50 | end
51 |
52 | add_index "users", ["username"], name: "index_users_on_username", using: :btree
53 |
54 | add_foreign_key "port_branches", "repos"
55 | add_foreign_key "reviewerships", "repos"
56 | add_foreign_key "reviewerships", "users"
57 | end
58 |
--------------------------------------------------------------------------------
/db/seeds.rb:
--------------------------------------------------------------------------------
1 | # This file should contain all the record creation needed to seed the database with its default values.
2 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3 | #
4 | # Examples:
5 | #
6 | # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
7 | # Mayor.create(name: 'Emanuel', city: cities.first)
8 |
--------------------------------------------------------------------------------
/lib/assets/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patronus-io/patronus/caaf4cafbcb2a1d139cbc73f220d8f004ef0d1b8/lib/assets/.keep
--------------------------------------------------------------------------------
/lib/tasks/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patronus-io/patronus/caaf4cafbcb2a1d139cbc73f220d8f004ef0d1b8/lib/tasks/.keep
--------------------------------------------------------------------------------
/log/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patronus-io/patronus/caaf4cafbcb2a1d139cbc73f220d8f004ef0d1b8/log/.keep
--------------------------------------------------------------------------------
/public/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The page you were looking for doesn't exist (404)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
The page you were looking for doesn't exist.
62 |
You may have mistyped the address or the page may have moved.
63 |
64 |
If you are the application owner check the logs for more information.
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/public/422.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The change you wanted was rejected (422)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
The change you wanted was rejected.
62 |
Maybe you tried to change something you didn't have access to.
63 |
64 |
If you are the application owner check the logs for more information.
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/public/500.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | We're sorry, but something went wrong (500)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
We're sorry, but something went wrong.
62 |
63 |
If you are the application owner check the logs for more information.
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patronus-io/patronus/caaf4cafbcb2a1d139cbc73f220d8f004ef0d1b8/public/favicon.ico
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
2 | #
3 | # To ban all spiders from the entire site uncomment the next two lines:
4 | # User-agent: *
5 | # Disallow: /
6 |
--------------------------------------------------------------------------------
/spec/controllers/reviewerships_controller_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rails_helper'
2 |
3 | RSpec.describe ReviewershipsController, type: :controller do
4 | let(:github_user) { double(login: "alice", token: "abc123") }
5 |
6 | describe "POST #create" do
7 | it "returns http success" do
8 | allow(controller).to receive(:github_user).and_return(github_user)
9 | allow_any_instance_of(Reviewership).to receive(:ensure_webhook_installed!)
10 | post :create, reviewership: {repo: {name: "alice/website"}}
11 | expect(response).to redirect_to(profile_path)
12 | end
13 | end
14 |
15 | end
16 |
--------------------------------------------------------------------------------
/spec/models/port_branch_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rails_helper'
2 |
3 | RSpec.describe PortBranch, type: :model do
4 | pending "add some examples to (or delete) #{__FILE__}"
5 | end
6 |
--------------------------------------------------------------------------------
/spec/models/repo_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rails_helper'
2 |
3 | RSpec.describe Repo, type: :model do
4 | pending "add some examples to (or delete) #{__FILE__}"
5 | end
6 |
--------------------------------------------------------------------------------
/spec/models/reviewership_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rails_helper'
2 |
3 | RSpec.describe Reviewership, type: :model do
4 | pending "add some examples to (or delete) #{__FILE__}"
5 | end
6 |
--------------------------------------------------------------------------------
/spec/models/user_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rails_helper'
2 |
3 | RSpec.describe User, type: :model do
4 | pending "add some examples to (or delete) #{__FILE__}"
5 | end
6 |
--------------------------------------------------------------------------------
/spec/rails_helper.rb:
--------------------------------------------------------------------------------
1 | # This file is copied to spec/ when you run 'rails generate rspec:install'
2 | ENV['RAILS_ENV'] ||= 'test'
3 | require File.expand_path('../../config/environment', __FILE__)
4 | # Prevent database truncation if the environment is production
5 | abort("The Rails environment is running in production mode!") if Rails.env.production?
6 | require 'spec_helper'
7 | require 'rspec/rails'
8 | # Add additional requires below this line. Rails is not loaded until this point!
9 |
10 | require 'warden/github/rails/test_helpers'
11 | # Requires supporting ruby files with custom matchers and macros, etc, in
12 | # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
13 | # run as spec files by default. This means that files in spec/support that end
14 | # in _spec.rb will both be required and run as specs, causing the specs to be
15 | # run twice. It is recommended that you do not name files matching this glob to
16 | # end with _spec.rb. You can configure this pattern with the --pattern
17 | # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
18 | #
19 | # The following line is provided for convenience purposes. It has the downside
20 | # of increasing the boot-up time by auto-requiring all files in the support
21 | # directory. Alternatively, in the individual `*_spec.rb` files, manually
22 | # require only the support files necessary.
23 | #
24 | # Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
25 |
26 | # Checks for pending migrations before tests are run.
27 | # If you are not using ActiveRecord, you can remove this line.
28 | ActiveRecord::Migration.maintain_test_schema!
29 |
30 | RSpec.configure do |config|
31 | # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
32 | config.fixture_path = "#{::Rails.root}/spec/fixtures"
33 |
34 | # If you're not using ActiveRecord, or you'd prefer not to run each of your
35 | # examples within a transaction, remove the following line or assign false
36 | # instead of true.
37 | config.use_transactional_fixtures = true
38 |
39 | # RSpec Rails can automatically mix in different behaviours to your tests
40 | # based on their file location, for example enabling you to call `get` and
41 | # `post` in specs under `spec/controllers`.
42 | #
43 | # You can disable this behaviour by removing the line below, and instead
44 | # explicitly tag your specs with their type, e.g.:
45 | #
46 | # RSpec.describe UsersController, :type => :controller do
47 | # # ...
48 | # end
49 | #
50 | # The different available types are documented in the features, such as in
51 | # https://relishapp.com/rspec/rspec-rails/docs
52 | config.infer_spec_type_from_file_location!
53 |
54 | config.include Warden::GitHub::Rails::TestHelpers
55 | end
56 |
--------------------------------------------------------------------------------
/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | # This file was generated by the `rails generate rspec:install` command. Conventionally, all
2 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3 | # The generated `.rspec` file contains `--require spec_helper` which will cause
4 | # this file to always be loaded, without a need to explicitly require it in any
5 | # files.
6 | #
7 | # Given that it is always loaded, you are encouraged to keep this file as
8 | # light-weight as possible. Requiring heavyweight dependencies from this file
9 | # will add to the boot time of your test suite on EVERY test run, even for an
10 | # individual file that may not need all of that loaded. Instead, consider making
11 | # a separate helper file that requires the additional dependencies and performs
12 | # the additional setup, and require it from the spec files that actually need
13 | # it.
14 | #
15 | # The `.rspec` file also contains a few flags that are not defaults but that
16 | # users commonly want.
17 | #
18 | # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19 | RSpec.configure do |config|
20 | # rspec-expectations config goes here. You can use an alternate
21 | # assertion/expectation library such as wrong or the stdlib/minitest
22 | # assertions if you prefer.
23 | config.expect_with :rspec do |expectations|
24 | # This option will default to `true` in RSpec 4. It makes the `description`
25 | # and `failure_message` of custom matchers include text for helper methods
26 | # defined using `chain`, e.g.:
27 | # be_bigger_than(2).and_smaller_than(4).description
28 | # # => "be bigger than 2 and smaller than 4"
29 | # ...rather than:
30 | # # => "be bigger than 2"
31 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32 | end
33 |
34 | # rspec-mocks config goes here. You can use an alternate test double
35 | # library (such as bogus or mocha) by changing the `mock_with` option here.
36 | config.mock_with :rspec do |mocks|
37 | # Prevents you from mocking or stubbing a method that does not exist on
38 | # a real object. This is generally recommended, and will default to
39 | # `true` in RSpec 4.
40 | mocks.verify_partial_doubles = true
41 | end
42 |
43 | # The settings below are suggested to provide a good initial experience
44 | # with RSpec, but feel free to customize to your heart's content.
45 | =begin
46 | # These two settings work together to allow you to limit a spec run
47 | # to individual examples or groups you care about by tagging them with
48 | # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49 | # get run.
50 | config.filter_run :focus
51 | config.run_all_when_everything_filtered = true
52 |
53 | # Allows RSpec to persist some state between runs in order to support
54 | # the `--only-failures` and `--next-failure` CLI options. We recommend
55 | # you configure your source control system to ignore this file.
56 | config.example_status_persistence_file_path = "spec/examples.txt"
57 |
58 | # Limits the available syntax to the non-monkey patched syntax that is
59 | # recommended. For more details, see:
60 | # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
61 | # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
62 | # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
63 | config.disable_monkey_patching!
64 |
65 | # Many RSpec users commonly either run the entire suite or an individual
66 | # file, and it's useful to allow more verbose output when running an
67 | # individual spec file.
68 | if config.files_to_run.one?
69 | # Use the documentation formatter for detailed output,
70 | # unless a formatter has already been configured
71 | # (e.g. via a command-line flag).
72 | config.default_formatter = 'doc'
73 | end
74 |
75 | # Print the 10 slowest examples and example groups at the
76 | # end of the spec run, to help surface which specs are running
77 | # particularly slow.
78 | config.profile_examples = 10
79 |
80 | # Run specs in random order to surface order dependencies. If you find an
81 | # order dependency and want to debug it, you can fix the order by providing
82 | # the seed, which is printed after each run.
83 | # --seed 1234
84 | config.order = :random
85 |
86 | # Seed global randomization in this process using the `--seed` CLI option.
87 | # Setting this allows you to use `--seed` to deterministically reproduce
88 | # test failures related to randomization by passing the same `--seed` value
89 | # as the one that triggered the failure.
90 | Kernel.srand config.seed
91 | =end
92 | end
93 |
--------------------------------------------------------------------------------
/vendor/assets/javascripts/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patronus-io/patronus/caaf4cafbcb2a1d139cbc73f220d8f004ef0d1b8/vendor/assets/javascripts/.keep
--------------------------------------------------------------------------------
/vendor/assets/stylesheets/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patronus-io/patronus/caaf4cafbcb2a1d139cbc73f220d8f004ef0d1b8/vendor/assets/stylesheets/.keep
--------------------------------------------------------------------------------