github_concern 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +2 -1
- data/app/controllers/github_controller.rb +1 -0
- data/lib/github_concern/engine.rb +9 -0
- data/lib/github_concern/version.rb +1 -1
- data/spec/controllers/github_controller_spec.rb +14 -3
- data/spec/internal/config/initializers/github_concern.rb +1 -0
- data/spec/internal/db/combustion_test.sqlite +0 -0
- data/spec/internal/log/test.log +938 -0
- metadata +14 -14
data/README.markdown
CHANGED
@@ -24,7 +24,7 @@ gem 'github_concern', :git => 'http://github.com/adamgamble/github_concern.git'
|
|
24
24
|
bundle install
|
25
25
|
|
26
26
|
Now github\_concern is available to your application. Next, add a service hook
|
27
|
-
to your github repo that posts to http://your\_url/github\_integration
|
27
|
+
to your github repo that posts to http://your\_url/github\_integration?token=some_unique_token
|
28
28
|
|
29
29
|
Add this to config/initializers/github\_concern.rb:
|
30
30
|
|
@@ -32,6 +32,7 @@ Add this to config/initializers/github\_concern.rb:
|
|
32
32
|
GithubConcern::Engine.config do |gc|
|
33
33
|
gc.user_lambda = lambda {|email| User.find_by_email email}
|
34
34
|
gc.user_class = User
|
35
|
+
gc.token = "some_unique_token"
|
35
36
|
end
|
36
37
|
```
|
37
38
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
class GithubController < ApplicationController
|
2
2
|
def payload
|
3
|
+
render :nothing => true, :status => 404 and return unless params.keys.include?("token") && params["token"] == GithubConcern::Engine.token
|
3
4
|
render :nothing => true, :status => 500 and return unless params["payload"]
|
4
5
|
GitPush.create(:payload => JSON.parse(params["payload"]))
|
5
6
|
render :nothing => true, :status => 200
|
@@ -3,6 +3,7 @@ module GithubConcern
|
|
3
3
|
class Engine < Rails::Engine
|
4
4
|
@@github_concerns = {}
|
5
5
|
@@callback_lambdas = []
|
6
|
+
@@token = ""
|
6
7
|
|
7
8
|
def self.config
|
8
9
|
yield(self)
|
@@ -26,6 +27,14 @@ module GithubConcern
|
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
30
|
+
def self.token= _token
|
31
|
+
@@token = _token
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.token
|
35
|
+
@@token
|
36
|
+
end
|
37
|
+
|
29
38
|
def self.user_lambda= find_user_lambda
|
30
39
|
@@user_lambda = find_user_lambda
|
31
40
|
end
|
@@ -3,14 +3,25 @@ require 'spec_helper'
|
|
3
3
|
describe GithubController do
|
4
4
|
describe "POST payload" do
|
5
5
|
it "returns 500 when not sending a payload" do
|
6
|
-
post :payload
|
6
|
+
post :payload, :token => GithubConcern::Engine.token
|
7
7
|
response.code.should == "500"
|
8
8
|
end
|
9
9
|
|
10
|
-
describe "when sending a valid payload" do
|
10
|
+
describe "when sending a valid payload with an invalid token" do
|
11
11
|
before(:each) do
|
12
12
|
payload = valid_payload_hash.to_json
|
13
|
-
post :payload, :payload => payload
|
13
|
+
post :payload, :payload => payload, :token => "my_token"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return a 404" do
|
17
|
+
response.code.should == "404"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "when sending a valid payload and a valid token" do
|
22
|
+
before(:each) do
|
23
|
+
payload = valid_payload_hash.to_json
|
24
|
+
post :payload, :payload => payload, :token => GithubConcern::Engine.token
|
14
25
|
end
|
15
26
|
|
16
27
|
it "returns 200 when sending a valid payload" do
|
Binary file
|