relevance-github_hook 0.5.8 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +1 -1
- data/Rakefile +1 -0
- data/github_hook.gemspec +5 -2
- data/lib/github_hook.rb +15 -4
- data/spec/github_hook_spec.rb +67 -36
- metadata +11 -2
data/CHANGELOG
CHANGED
data/Rakefile
CHANGED
data/github_hook.gemspec
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = %q{github_hook}
|
3
|
-
s.version = "0.
|
3
|
+
s.version = "0.6.0"
|
4
4
|
|
5
5
|
s.required_rubygems_version = Gem::Requirement.new("= 1.2") if s.respond_to? :required_rubygems_version=
|
6
6
|
s.authors = ["Rob Sanheim"]
|
7
|
-
s.date = %q{2008-
|
7
|
+
s.date = %q{2008-08-05}
|
8
8
|
s.description = %q{Wrapper around the github post receive JSON payload.}
|
9
9
|
s.email = %q{opensource@thinkrelevance.com}
|
10
10
|
s.extra_rdoc_files = ["CHANGELOG", "lib/github_hook.rb", "README.txt"]
|
@@ -23,11 +23,14 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.specification_version = 2
|
24
24
|
|
25
25
|
if current_version >= 3 then
|
26
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
26
27
|
s.add_development_dependency(%q<echoe>, [">= 0"])
|
27
28
|
else
|
29
|
+
s.add_dependency(%q<json>, [">= 0"])
|
28
30
|
s.add_dependency(%q<echoe>, [">= 0"])
|
29
31
|
end
|
30
32
|
else
|
33
|
+
s.add_dependency(%q<json>, [">= 0"])
|
31
34
|
s.add_dependency(%q<echoe>, [">= 0"])
|
32
35
|
end
|
33
36
|
end
|
data/lib/github_hook.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
+
require 'rubygems'
|
1
2
|
require 'json'
|
2
3
|
require 'ostruct'
|
3
4
|
|
4
5
|
class GithubHook
|
5
|
-
VERSION = '0.
|
6
|
+
VERSION = '0.6.0'
|
6
7
|
attr_reader :before, :after, :ref, :repository, :owner, :commits
|
7
8
|
|
8
9
|
def initialize(json)
|
@@ -10,17 +11,27 @@ class GithubHook
|
|
10
11
|
@before, @after, @ref = payload["before"], payload["after"], payload["ref"]
|
11
12
|
@repository = OpenStruct.new(payload["repository"])
|
12
13
|
@owner = OpenStruct.new(payload["repository"]["owner"])
|
13
|
-
@commits = payload
|
14
|
+
@commits = create_commits(payload)
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_commits(payload)
|
18
|
+
payload['commits'].map do |hash|
|
14
19
|
commit_ostruct = OpenStruct.new(hash)
|
15
20
|
commit_ostruct.sha = hash["id"]
|
16
21
|
commit_ostruct.author = OpenStruct.new(hash["author"])
|
17
22
|
commit_ostruct
|
18
23
|
end
|
24
|
+
rescue NoMethodError
|
25
|
+
payload['commits'].map do |sha, hash|
|
26
|
+
commit_ostruct = OpenStruct.new(hash)
|
27
|
+
commit_ostruct.sha = sha
|
28
|
+
commit_ostruct.author = OpenStruct.new(hash["author"])
|
29
|
+
commit_ostruct
|
30
|
+
end
|
19
31
|
end
|
20
32
|
|
21
|
-
# just the most recent commit
|
22
33
|
def last_commit
|
23
|
-
@commits.
|
34
|
+
@commits.sort_by { |commit| commit.timestamp }.last
|
24
35
|
end
|
25
36
|
|
26
37
|
end
|
data/spec/github_hook_spec.rb
CHANGED
@@ -1,51 +1,82 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), *%w[helper])
|
2
2
|
|
3
3
|
describe GithubHook do
|
4
|
-
before { @pc = GithubHook.new(PayloadAfterJuly30)}
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
describe "old format" do
|
6
|
+
before { @pc = GithubHook.new(PayloadBeforeJuly30)}
|
7
|
+
|
8
|
+
it "has an array of commit objects" do
|
9
|
+
commits = @pc.commits
|
10
|
+
commits[0].sha.should == "de8251ff97ee194a289832576287d6f8ad74e3d0"
|
11
|
+
commits[1].sha.should == "41a212ee83ca127e3c8cf465891ab7216a705f59"
|
12
|
+
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
14
|
+
it "has commit values" do
|
15
|
+
commit = @pc.commits.first
|
16
|
+
commit.url.should == "http://github.com/defunkt/github/commit/de8251ff97ee194a289832576287d6f8ad74e3d0"
|
17
|
+
commit.message.should == "update pricing a tad"
|
18
|
+
commit.timestamp.should == "2008-02-15T14:36:34-08:00"
|
19
|
+
end
|
15
20
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
21
|
+
it "has commit author" do
|
22
|
+
author = @pc.commits.first.author
|
23
|
+
author.name.should == "Chris Wanstrath"
|
24
|
+
author.email.should == "chris@ozmm.org"
|
25
|
+
end
|
20
26
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
owner.name.should == "defunkt"
|
27
|
+
it "has last commit" do
|
28
|
+
@pc.last_commit.sha.should == "41a212ee83ca127e3c8cf465891ab7216a705f59"
|
29
|
+
end
|
25
30
|
end
|
31
|
+
|
32
|
+
describe "new format" do
|
33
|
+
before { @pc = GithubHook.new(PayloadAfterJuly30)}
|
34
|
+
|
35
|
+
it "should have repo" do
|
36
|
+
repository = @pc.repository
|
37
|
+
repository.url.should == "http://github.com/defunkt/github"
|
38
|
+
repository.name.should == "github"
|
39
|
+
end
|
26
40
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
commits[1].sha.should == "de8251ff97ee194a289832576287d6f8ad74e3d0"
|
31
|
-
end
|
41
|
+
it "has reference to branch" do
|
42
|
+
@pc.ref.should == "refs/heads/master"
|
43
|
+
end
|
32
44
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
commit.timestamp.should == "2008-02-15T14:57:17-08:00"
|
38
|
-
end
|
45
|
+
it "has before and after tag" do
|
46
|
+
@pc.before.should == "5aef35982fb2d34e9d9d4502f6ede1072793222d"
|
47
|
+
@pc.after.should == "de8251ff97ee194a289832576287d6f8ad74e3d0"
|
48
|
+
end
|
39
49
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
50
|
+
it "has owner" do
|
51
|
+
owner = @pc.owner
|
52
|
+
owner.email.should == "chris@ozmm.org"
|
53
|
+
owner.name.should == "defunkt"
|
54
|
+
end
|
45
55
|
|
46
|
-
|
47
|
-
|
48
|
-
|
56
|
+
it "has an array of commit objects" do
|
57
|
+
commits = @pc.commits
|
58
|
+
commits[0].sha.should == "41a212ee83ca127e3c8cf465891ab7216a705f59"
|
59
|
+
commits[1].sha.should == "de8251ff97ee194a289832576287d6f8ad74e3d0"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "has commit values" do
|
63
|
+
commit = @pc.commits.first
|
64
|
+
commit.url.should == "http://github.com/defunkt/github/commit/41a212ee83ca127e3c8cf465891ab7216a705f59"
|
65
|
+
commit.message.should == "okay i give in"
|
66
|
+
commit.timestamp.should == "2008-02-15T14:57:17-08:00"
|
67
|
+
end
|
49
68
|
|
69
|
+
it "has commit author" do
|
70
|
+
author = @pc.commits.first.author
|
71
|
+
author.name.should == "Chris Wanstrath"
|
72
|
+
author.email.should == "chris@ozmm.org"
|
73
|
+
end
|
74
|
+
|
75
|
+
it "has last commit" do
|
76
|
+
@pc.last_commit.sha.should == "41a212ee83ca127e3c8cf465891ab7216a705f59"
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
50
81
|
end
|
51
82
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relevance-github_hook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Sanheim
|
@@ -9,9 +9,18 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-08-05 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: json
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
version:
|
15
24
|
- !ruby/object:Gem::Dependency
|
16
25
|
name: echoe
|
17
26
|
version_requirement:
|