got_fixed 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +22 -0
- data/README.rdoc +3 -0
- data/Rakefile +21 -0
- data/app/assets/javascripts/got_fixed/application.js +15 -0
- data/app/assets/javascripts/got_fixed/issues.js +2 -0
- data/app/assets/stylesheets/got_fixed/application.css +13 -0
- data/app/assets/stylesheets/got_fixed/issues.css +4 -0
- data/app/assets/stylesheets/scaffold.css +56 -0
- data/app/controllers/got_fixed/application_controller.rb +4 -0
- data/app/controllers/got_fixed/issues_controller.rb +84 -0
- data/app/helpers/got_fixed/application_helper.rb +4 -0
- data/app/helpers/got_fixed/issues_helper.rb +4 -0
- data/app/mailers/got_fixed/user_mailer.rb +16 -0
- data/app/models/got_fixed/issue.rb +36 -0
- data/app/models/got_fixed/user.rb +25 -0
- data/app/views/got_fixed/issues/index.html.erb +21 -0
- data/app/views/got_fixed/issues/subscribe.js.erb +1 -0
- data/app/views/got_fixed/user_mailer/issue_got_fixed_email.text.erb +13 -0
- data/app/views/layouts/got_fixed/application.html.erb +14 -0
- data/config/initializers/got_fixed.rb +17 -0
- data/config/routes.rb +12 -0
- data/db/migrate/20130912175851_create_got_fixed_issues.rb +10 -0
- data/db/migrate/20130913195152_add_number_to_got_fixed_issue.rb +6 -0
- data/db/migrate/20130914085003_add_vendor_to_got_fixed_issue.rb +5 -0
- data/db/migrate/20130924121816_create_got_fixed_users.rb +9 -0
- data/db/migrate/20130924123004_has_and_belongs_to_many_issues_user.rb +8 -0
- data/db/migrate/20130929180909_unique_user_emails.rb +5 -0
- data/lib/got_fixed/adapters/github.rb +78 -0
- data/lib/got_fixed/engine.rb +12 -0
- data/lib/got_fixed/issue_factory.rb +11 -0
- data/lib/got_fixed/receivers/github_webhook.rb +21 -0
- data/lib/got_fixed/version.rb +3 -0
- data/lib/got_fixed.rb +10 -0
- data/lib/tasks/auto_annotate_models.rake +34 -0
- data/lib/tasks/got_fixed_tasks.rake +56 -0
- data/spec/controllers/got_fixed/issues_controller_spec.rb +194 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config/application.rb +65 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +39 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/got_fixed.yml +15 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +5 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +44 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +3113 -0
- data/spec/dummy/log/production.log +0 -0
- data/spec/dummy/log/test.log +11243 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/0ec0faefe9b37b9024c6fb43e9577379 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1ad476961916298df66abf55b6b446de +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2286292795a62721269b8a751f3ce3de +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/34f9216c794a67fd776c9e8dfe99f905 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/37a2b058893add5bb1b23726e10e90f1 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3d7c2feaa3d73a9b02a2523a2bf8c6c9 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/41bea58eab5eb570004a03e4c0cb9bfe +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/43e404632c89edec855c1fe4e66bbfe8 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/52a4f1330e8756eedff2b67442d10802 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/79b7d2d69028ec9f2efa155d4bf7067a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8407d75ea9f26f3effb102acd4b2746d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/962e8b0955e30143673ce7bf6b31f8d5 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/98b0301bcea3ebb889faa9d47cbf2419 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/aaf7d9ec41e452e8a7e8a9b8ee74f1cd +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b1f9d4de39dbaca4f213e1d9df6bd0bd +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c12af3e3ef3886081600da84f6d72c52 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/db5ae29d7657f4561f01010b7442354a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f310f9446657cf410e5ef48cc74de9d2 +0 -0
- data/spec/factories/github/closed.json +222 -0
- data/spec/factories/github/hook-issues-event.json +164 -0
- data/spec/factories/github/open.json +50 -0
- data/spec/factories/got_fixed_issues.rb +10 -0
- data/spec/factories/got_fixed_users.rb +9 -0
- data/spec/lib/got_fixed/adapters/github_spec.rb +70 -0
- data/spec/lib/got_fixed/issue_factory_spec.rb +33 -0
- data/spec/lib/got_fixed/receivers/github_webhook_spec.rb +16 -0
- data/spec/mailers/got_fixed/user_mailer_spec.rb +20 -0
- data/spec/models/got_fixed/issue_spec.rb +52 -0
- data/spec/models/got_fixed/user_spec.rb +35 -0
- data/spec/routing/got_fixed/issues_routing_spec.rb +15 -0
- data/spec/spec_helper.rb +23 -0
- metadata +311 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 06053ffaa7bbed644b183004e7cd0472244b5eca
|
4
|
+
data.tar.gz: 794581561dc0dadb1419dde9fb7b74ff70551c7c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2b02a550514de17c217f974db7762817b4f192eb23ae300d82a8cdc105d536412a979aa7c5f2bb7c9a6befbe1b8198375d167e814fe83066994efa087f8d9e54
|
7
|
+
data.tar.gz: ce6827d303f5777f1f37c7b58ee381a77ba0d9e85ede71295a137680eefa2519cc02be6be163f3c74e7fcd70ddcca5e93a2b275e9d3b46635a1a46a78aae137a
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Sébastien Saunier
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
|
8
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
9
|
+
load 'rails/tasks/engine.rake'
|
10
|
+
|
11
|
+
Bundler::GemHelper.install_tasks
|
12
|
+
|
13
|
+
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
|
14
|
+
|
15
|
+
require 'rspec/core'
|
16
|
+
require 'rspec/core/rake_task'
|
17
|
+
|
18
|
+
desc "Run all specs in spec directory (excluding plugin specs)"
|
19
|
+
RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
|
20
|
+
|
21
|
+
task :default => :spec
|
@@ -0,0 +1,15 @@
|
|
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 vendor/assets/javascripts of plugins, if any, 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
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
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 vendor/assets/stylesheets of plugins, if any, 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 top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,56 @@
|
|
1
|
+
body { background-color: #fff; color: #333; }
|
2
|
+
|
3
|
+
body, p, ol, ul, td {
|
4
|
+
font-family: verdana, arial, helvetica, sans-serif;
|
5
|
+
font-size: 13px;
|
6
|
+
line-height: 18px;
|
7
|
+
}
|
8
|
+
|
9
|
+
pre {
|
10
|
+
background-color: #eee;
|
11
|
+
padding: 10px;
|
12
|
+
font-size: 11px;
|
13
|
+
}
|
14
|
+
|
15
|
+
a { color: #000; }
|
16
|
+
a:visited { color: #666; }
|
17
|
+
a:hover { color: #fff; background-color:#000; }
|
18
|
+
|
19
|
+
div.field, div.actions {
|
20
|
+
margin-bottom: 10px;
|
21
|
+
}
|
22
|
+
|
23
|
+
#notice {
|
24
|
+
color: green;
|
25
|
+
}
|
26
|
+
|
27
|
+
.field_with_errors {
|
28
|
+
padding: 2px;
|
29
|
+
background-color: red;
|
30
|
+
display: table;
|
31
|
+
}
|
32
|
+
|
33
|
+
#error_explanation {
|
34
|
+
width: 450px;
|
35
|
+
border: 2px solid red;
|
36
|
+
padding: 7px;
|
37
|
+
padding-bottom: 0;
|
38
|
+
margin-bottom: 20px;
|
39
|
+
background-color: #f0f0f0;
|
40
|
+
}
|
41
|
+
|
42
|
+
#error_explanation h2 {
|
43
|
+
text-align: left;
|
44
|
+
font-weight: bold;
|
45
|
+
padding: 5px 5px 5px 15px;
|
46
|
+
font-size: 12px;
|
47
|
+
margin: -7px;
|
48
|
+
margin-bottom: 0px;
|
49
|
+
background-color: #c00;
|
50
|
+
color: #fff;
|
51
|
+
}
|
52
|
+
|
53
|
+
#error_explanation ul li {
|
54
|
+
font-size: 12px;
|
55
|
+
list-style: square;
|
56
|
+
}
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require_dependency "got_fixed/application_controller"
|
2
|
+
|
3
|
+
module GotFixed
|
4
|
+
class IssuesController < ApplicationController
|
5
|
+
# before_action :set_issue, only: [:destroy]
|
6
|
+
before_action :check_hub_signature!, :only => :github_webhook
|
7
|
+
|
8
|
+
respond_to :json
|
9
|
+
respond_to :js
|
10
|
+
|
11
|
+
# GET /issues
|
12
|
+
def index
|
13
|
+
@issues = Issue.all
|
14
|
+
end
|
15
|
+
|
16
|
+
def github_webhook
|
17
|
+
# TODO(ssaunier): json payload as "action" set to opened, closed or repoend
|
18
|
+
# figure out how to get it (conflict with rails action param...)
|
19
|
+
@issue = Issue.find_or_initialize_by :vendor_id => params[:issue][:id], :vendor => "github"
|
20
|
+
@issue.title = params[:issue][:title]
|
21
|
+
@issue.closed = params[:issue][:state] == "closed"
|
22
|
+
@issue.save
|
23
|
+
render :json => @issue
|
24
|
+
end
|
25
|
+
|
26
|
+
def subscribe
|
27
|
+
@user = User.find_or_initialize_by :email => params[:user][:email]
|
28
|
+
@issue = Issue.find params[:id]
|
29
|
+
unless @issue.users.include?(@user)
|
30
|
+
@issue.users << @user
|
31
|
+
@issue.save
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def check_hub_signature!
|
38
|
+
owner, repo = params[:repository][:full_name].split("/")
|
39
|
+
options = GotFixed.config[:github].find(:owner => owner, :repo => repo).first
|
40
|
+
request.body.rewind
|
41
|
+
request_body = request.body.read
|
42
|
+
|
43
|
+
github_webhook = Receivers::GithubWebhook.new :secret => options[:webhook_secret]
|
44
|
+
github_webhook.check_hub_signature! request.headers['X-Hub-Signature'], request_body
|
45
|
+
end
|
46
|
+
|
47
|
+
# # POST /issues
|
48
|
+
# def create
|
49
|
+
# @issue = Issue.new(issue_params)
|
50
|
+
|
51
|
+
# if @issue.save
|
52
|
+
# redirect_to @issue, notice: 'Issue was successfully created.'
|
53
|
+
# else
|
54
|
+
# respond_with @issue
|
55
|
+
# end
|
56
|
+
# end
|
57
|
+
|
58
|
+
# # PATCH/PUT /issues/1
|
59
|
+
# def update
|
60
|
+
# if @issue.update(issue_params)
|
61
|
+
# redirect_to @issue, notice: 'Issue was successfully updated.'
|
62
|
+
# else
|
63
|
+
# render action: 'edit'
|
64
|
+
# end
|
65
|
+
# end
|
66
|
+
|
67
|
+
# # DELETE /issues/1
|
68
|
+
# def destroy
|
69
|
+
# @issue.destroy
|
70
|
+
# redirect_to issues_url, notice: 'Issue was successfully destroyed.'
|
71
|
+
# end
|
72
|
+
|
73
|
+
# private
|
74
|
+
# # Use callbacks to share common setup or constraints between actions.
|
75
|
+
# def set_issue
|
76
|
+
# @issue = Issue.find(params[:id])
|
77
|
+
# end
|
78
|
+
|
79
|
+
# # Only allow a trusted parameter "white list" through.
|
80
|
+
# def issue_params
|
81
|
+
# params.require(:issue).permit(:title, :closed)
|
82
|
+
# end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module GotFixed
|
2
|
+
class UserMailer < ActionMailer::Base
|
3
|
+
default from: GotFixed.config[:user_mailer][:from]
|
4
|
+
|
5
|
+
def issue_got_fixed_email(user, issue)
|
6
|
+
@user = user
|
7
|
+
@issue = issue
|
8
|
+
mail(to: @user.email, subject: subject(issue))
|
9
|
+
end
|
10
|
+
|
11
|
+
def subject(issue)
|
12
|
+
template = GotFixed.config[:user_mailer][:subject_template]
|
13
|
+
template % issue.attributes.symbolize_keys
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# == Schema Information
|
2
|
+
#
|
3
|
+
# Table name: got_fixed_issues
|
4
|
+
#
|
5
|
+
# id :integer not null, primary key
|
6
|
+
# title :string(255)
|
7
|
+
# closed :boolean
|
8
|
+
# created_at :datetime
|
9
|
+
# updated_at :datetime
|
10
|
+
# number :integer
|
11
|
+
# vendor_id :string(255)
|
12
|
+
# vendor :string(255)
|
13
|
+
#
|
14
|
+
|
15
|
+
module GotFixed
|
16
|
+
class Issue < ActiveRecord::Base
|
17
|
+
default_scope { order("updated_at DESC") }
|
18
|
+
validates_uniqueness_of :vendor_id, :scope => :vendor
|
19
|
+
|
20
|
+
has_and_belongs_to_many :users
|
21
|
+
|
22
|
+
after_update :send_notifications, :if => :just_closed?
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def just_closed?
|
27
|
+
!closed_was && closed
|
28
|
+
end
|
29
|
+
|
30
|
+
def send_notifications
|
31
|
+
users.each do |user|
|
32
|
+
user.send_notification self
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# == Schema Information
|
2
|
+
#
|
3
|
+
# Table name: got_fixed_users
|
4
|
+
#
|
5
|
+
# id :integer not null, primary key
|
6
|
+
# email :string(255)
|
7
|
+
# created_at :datetime
|
8
|
+
# updated_at :datetime
|
9
|
+
#
|
10
|
+
|
11
|
+
module GotFixed
|
12
|
+
class User < ActiveRecord::Base
|
13
|
+
validates_presence_of :email
|
14
|
+
validates_uniqueness_of :email
|
15
|
+
validates_format_of :email, :with => /\A([-a-z0-9!\#$%&'*+\/=?^_`{|}~]+\.)*[-a-z0-9!\#$%&'*+\/=?^_`{|}~]+@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
|
16
|
+
|
17
|
+
has_and_belongs_to_many :issues
|
18
|
+
|
19
|
+
def send_notification(issue)
|
20
|
+
# TODO(ssaunier): async send (SMTP is slow !!)
|
21
|
+
mail = UserMailer.issue_got_fixed_email(self, issue)
|
22
|
+
mail.deliver
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<h1>Listing issues</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<thead>
|
5
|
+
<tr>
|
6
|
+
<th></th>
|
7
|
+
<th>Title</th>
|
8
|
+
<th>Resolved?</th>
|
9
|
+
</tr>
|
10
|
+
</thead>
|
11
|
+
|
12
|
+
<tbody>
|
13
|
+
<% @issues.each do |issue| %>
|
14
|
+
<tr>
|
15
|
+
<td>#<%= issue.number %></td>
|
16
|
+
<td><%= issue.title %></td>
|
17
|
+
<td><%= issue.closed ? "yes" : "no" %></td>
|
18
|
+
</tr>
|
19
|
+
<% end %>
|
20
|
+
</tbody>
|
21
|
+
</table>
|
@@ -0,0 +1 @@
|
|
1
|
+
alert('<%= j @user.email %> subscribed to issue #<%= @issue.vendor_id %>');
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Hello,
|
2
|
+
|
3
|
+
We are happy to announce you that the issue
|
4
|
+
"<%= @issue.title %>"
|
5
|
+
has been closed.
|
6
|
+
|
7
|
+
In a few minutes, this change will be promoted to production which should fix your problem.
|
8
|
+
|
9
|
+
Best regards.
|
10
|
+
|
11
|
+
--
|
12
|
+
You received this email because you subscribed to issue updates.
|
13
|
+
You will only receive emails for issues you registered for.
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>GotFixed</title>
|
5
|
+
<%= stylesheet_link_tag "got_fixed/application", :media => "all" %>
|
6
|
+
<%= javascript_include_tag "got_fixed/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
config = YAML.load(ERB.new(File.read(Rails.root.join('config', 'got_fixed.yml'))).result)
|
2
|
+
|
3
|
+
# https://gist.github.com/ssaunier/3866812
|
4
|
+
def symbolize(object)
|
5
|
+
if object.kind_of? Hash
|
6
|
+
object.keys.each do |k|
|
7
|
+
object[k.to_sym] = symbolize(object.delete k)
|
8
|
+
end
|
9
|
+
object
|
10
|
+
elsif object.kind_of? Array
|
11
|
+
object.map { |e| symbolize e }
|
12
|
+
else
|
13
|
+
object
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
GotFixed.config = symbolize(config)
|
data/config/routes.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require "httparty"
|
2
|
+
|
3
|
+
module GotFixed
|
4
|
+
module Adapters
|
5
|
+
class Github
|
6
|
+
include HTTParty
|
7
|
+
base_uri "https://api.github.com"
|
8
|
+
|
9
|
+
attr_accessor :access_token, :owner, :repo
|
10
|
+
|
11
|
+
def initialize(options = {})
|
12
|
+
ensure_mandatory_parameters options, true
|
13
|
+
end
|
14
|
+
|
15
|
+
# Retrieve all issues of a given GitHub repository matching given labels
|
16
|
+
# Labels must be comma separated, e.g. "public,foo,bar"
|
17
|
+
#
|
18
|
+
# Doc: http://developer.github.com/v3/issues/#list-issues-for-a-repository
|
19
|
+
def issues(options = {})
|
20
|
+
ensure_mandatory_parameters options
|
21
|
+
labels = options[:labels]
|
22
|
+
|
23
|
+
opened = issues_with_state(labels, :open)
|
24
|
+
closed = issues_with_state(labels, :closed)
|
25
|
+
opened + closed
|
26
|
+
end
|
27
|
+
|
28
|
+
def hooks(options = {})
|
29
|
+
ensure_mandatory_parameters options
|
30
|
+
self.class.get "/repos/#{@owner}/#{@repo}/hooks", :headers => headers
|
31
|
+
end
|
32
|
+
|
33
|
+
def create_hook(options = {})
|
34
|
+
ensure_mandatory_parameters options
|
35
|
+
url = options[:url] || "http://requestb.in/xy043uxy"
|
36
|
+
secret = options[:secret] # TODO(ssaunier): Raise error if secret not set.
|
37
|
+
|
38
|
+
body = {
|
39
|
+
:name => "web",
|
40
|
+
:config => {
|
41
|
+
:url => url,
|
42
|
+
:content_type => "json",
|
43
|
+
:secret => secret
|
44
|
+
},
|
45
|
+
:events => [ 'issues' ]
|
46
|
+
}
|
47
|
+
self.class.post "/repos/#{@owner}/#{@repo}/hooks", :body => body.to_json, :headers => headers
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def ensure_mandatory_parameters(options, allow_empty = false)
|
53
|
+
[:access_token, :owner, :repo].each do |option|
|
54
|
+
self.send :"#{option}=", options[option] unless blank?(options[option])
|
55
|
+
if !allow_empty && blank?(self.send option)
|
56
|
+
raise ArgumentError.new "Missing mandatory :#{option} option"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def issues_with_state(labels, state)
|
62
|
+
query = { :labels => labels, :state => state }
|
63
|
+
self.class.get "/repos/#{@owner}/#{@repo}/issues", :query => query, :headers => headers
|
64
|
+
end
|
65
|
+
|
66
|
+
def headers
|
67
|
+
{
|
68
|
+
"Authorization" => "token #{@access_token}"
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
def blank?(str)
|
73
|
+
str.nil? || str == ""
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module GotFixed
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace GotFixed
|
4
|
+
|
5
|
+
config.generators do |g|
|
6
|
+
g.test_framework :rspec, :fixture => false, :view_specs => false
|
7
|
+
g.fixture_replacement :factory_girl, :dir => 'spec/factories'
|
8
|
+
g.assets false
|
9
|
+
g.helper false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module GotFixed
|
2
|
+
class IssueFactory
|
3
|
+
def from_github(github_issue)
|
4
|
+
issue = Issue.find_or_initialize_by :vendor_id => github_issue["id"], :vendor => "github"
|
5
|
+
issue.title = github_issue["title"]
|
6
|
+
issue.closed = github_issue["state"] == "closed"
|
7
|
+
issue.number = github_issue["number"]
|
8
|
+
issue
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module GotFixed
|
2
|
+
module Receivers
|
3
|
+
class GithubWebhook
|
4
|
+
HMAC_DIGEST = OpenSSL::Digest::Digest.new('sha1')
|
5
|
+
class SignatureError < StandardError; end
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
@secret = options[:secret]
|
9
|
+
end
|
10
|
+
|
11
|
+
# Incoming request:
|
12
|
+
# https://github.com/github/github-services/blob/14f4da01ce29bc6a02427a9fbf37b08b141e81d9/lib/services/web.rb#L48
|
13
|
+
def check_hub_signature!(header, body)
|
14
|
+
expected_signature = "sha1=#{OpenSSL::HMAC.hexdigest(HMAC_DIGEST, @secret, body)}"
|
15
|
+
if header != expected_signature
|
16
|
+
raise SignatureError.new "#{header} != #{expected_signature}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/got_fixed.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# NOTE: only doing this in development as some production environments (Heroku)
|
2
|
+
# NOTE: are sensitive to local FS writes, and besides -- it's just not proper
|
3
|
+
# NOTE: to have a dev-mode tool do its thing in production.
|
4
|
+
if(Rails.env.development?)
|
5
|
+
task :set_annotation_options do
|
6
|
+
# You can override any of these by setting an environment variable of the
|
7
|
+
# same name.
|
8
|
+
Annotate.set_defaults({
|
9
|
+
'position_in_routes' => "before",
|
10
|
+
'position_in_class' => "before",
|
11
|
+
'position_in_test' => "before",
|
12
|
+
'position_in_fixture' => "before",
|
13
|
+
'position_in_factory' => "before",
|
14
|
+
'show_indexes' => "true",
|
15
|
+
'simple_indexes' => "false",
|
16
|
+
'model_dir' => "app/models",
|
17
|
+
'include_version' => "false",
|
18
|
+
'require' => "",
|
19
|
+
'exclude_tests' => "false",
|
20
|
+
'exclude_fixtures' => "false",
|
21
|
+
'exclude_factories' => "false",
|
22
|
+
'ignore_model_sub_dir' => "false",
|
23
|
+
'skip_on_db_migrate' => "false",
|
24
|
+
'format_bare' => "true",
|
25
|
+
'format_rdoc' => "false",
|
26
|
+
'format_markdown' => "false",
|
27
|
+
'sort' => "false",
|
28
|
+
'force' => "false",
|
29
|
+
'trace' => "false",
|
30
|
+
})
|
31
|
+
end
|
32
|
+
|
33
|
+
Annotate.load_tasks
|
34
|
+
end
|