gh 0.2.3 → 0.2.4

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/README.md CHANGED
@@ -16,6 +16,7 @@ This will by default use all the middleware that ships with GH, in the following
16
16
  * `GH::Cache` - caches the responses (will use Rails cache if in Rails, in-memory cache otherwise)
17
17
  * `GH::LazyLoader` - will load missing fields when accessed (handy for dealing with incomplete data without sending to many requests)
18
18
  * `GH::LinkFollower` - will add content of hypermedia links as fields (lazyly), allows you to traverse relations
19
+ * `GH::MergeCommit` - adds infos about merge commits to pull request payloads
19
20
 
20
21
  ## Main Entry Points
21
22
 
@@ -88,7 +89,7 @@ end
88
89
  That way, you could create a stack with, for instance, an [access token](http://developer.github.com/v3/oauth/):
89
90
 
90
91
  ``` ruby
91
- authenticated = GH::DefaultStack token: 'e72e16c7e42f292c6912e7710c838347ae178b4a'
92
+ authenticated = GH::DefaultStack.build token: 'e72e16c7e42f292c6912e7710c838347ae178b4a'
92
93
 
93
94
  GH.with(authenticated) do
94
95
  # ...
@@ -111,7 +112,8 @@ I hope so, we use it in production for [Travis CI](http://travis-ci.org/). The w
111
112
 
112
113
  ## History
113
114
 
114
- * 2012-04-10: 0.2.3 - better normalization
115
+ * 2012-04-13: 0.2.3 - added support for merge commits
116
+ * 2012-04-12: 0.2.3 - better normalization
115
117
  * 2012-04-10: 0.2.2 - improved link following
116
118
  * 2012-04-10: 0.2.1 - bug fix release
117
119
  * 2012-04-10: 0.2.0 - added link following plus bug fixes (mainly encoding issues)
data/lib/gh.rb CHANGED
@@ -7,6 +7,7 @@ module GH
7
7
  autoload :Case, 'gh/case'
8
8
  autoload :LazyLoader, 'gh/lazy_loader'
9
9
  autoload :LinkFollower, 'gh/link_follower'
10
+ autoload :MergeCommit, 'gh/merge_commit'
10
11
  autoload :Normalizer, 'gh/normalizer'
11
12
  autoload :Remote, 'gh/remote'
12
13
  autoload :Response, 'gh/response'
@@ -34,6 +35,7 @@ module GH
34
35
 
35
36
  DefaultStack = Stack.new do
36
37
  use LinkFollower
38
+ use MergeCommit
37
39
  use LazyLoader
38
40
  use Cache
39
41
  use Normalizer
@@ -6,9 +6,9 @@ module GH
6
6
  wraps GH::Normalizer
7
7
  double_dispatch
8
8
 
9
- def modify_hash(hash)
10
- hash = super
11
- link = hash['_links'].try(:[], 'self')
9
+ def modify_hash(hash, loaded = false)
10
+ hash = super(hash)
11
+ link = hash['_links'].try(:[], 'self') unless loaded
12
12
  setup_lazy_loading(hash, link['href']) if link
13
13
  hash
14
14
  end
@@ -16,7 +16,7 @@ module GH
16
16
  private
17
17
 
18
18
  def lazy_load(hash, key, link)
19
- backend[link]
19
+ result = modify_hash(backend[link].data, true)
20
20
  end
21
21
  end
22
22
  end
@@ -13,7 +13,7 @@ module GH
13
13
 
14
14
  def lazy_load(hash, key)
15
15
  link = hash['_links'][key]
16
- { key => backend[link['href']] } if link
16
+ { key => self[link['href']] } if link
17
17
  end
18
18
  end
19
19
  end
@@ -0,0 +1,29 @@
1
+ require 'gh'
2
+
3
+ module GH
4
+ # Public: ...
5
+ class MergeCommit < Wrapper
6
+ wraps GH::Normalizer
7
+ double_dispatch
8
+
9
+ def modify_hash(hash)
10
+ hash = super
11
+ setup_lazy_loading(hash) if hash.include? 'mergeable' and hash['mergeable']
12
+ hash
13
+ end
14
+
15
+ private
16
+
17
+ def lazy_load(hash, key)
18
+ return unless key =~ /^(merge|head)_commit$/
19
+ link = hash['_links']['self']['href'].gsub(%r{/pulls/(\d+)$}, '/git/refs/pull/\1')
20
+ commits = self[link].map do |data|
21
+ ref = data['ref']
22
+ name = ref.split('/').last + "_commit"
23
+ object = data['object'].merge 'ref' => ref
24
+ [name, object]
25
+ end
26
+ Hash[commits]
27
+ end
28
+ end
29
+ end
@@ -1,4 +1,4 @@
1
1
  module GH
2
2
  # Public: Library version.
3
- VERSION = "0.2.3"
3
+ VERSION = "0.2.4"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-04-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70266152433620 !ruby/object:Gem::Requirement
16
+ requirement: &70165430138860 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70266152433620
24
+ version_requirements: *70165430138860
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: webmock
27
- requirement: &70266152433160 !ruby/object:Gem::Requirement
27
+ requirement: &70165430138420 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70266152433160
35
+ version_requirements: *70165430138420
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: faraday
38
- requirement: &70266152432640 !ruby/object:Gem::Requirement
38
+ requirement: &70165430137880 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0.7'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70266152432640
46
+ version_requirements: *70165430137880
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: backports
49
- requirement: &70266152432140 !ruby/object:Gem::Requirement
49
+ requirement: &70165430137340 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '2.3'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70266152432140
57
+ version_requirements: *70165430137340
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: multi_json
60
- requirement: &70266152431660 !ruby/object:Gem::Requirement
60
+ requirement: &70165430136480 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '1.0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70266152431660
68
+ version_requirements: *70165430136480
69
69
  description: multi-layer client for the github api v3
70
70
  email:
71
71
  - konstantin.mailinglists@googlemail.com
@@ -85,6 +85,7 @@ files:
85
85
  - lib/gh/faraday.rb
86
86
  - lib/gh/lazy_loader.rb
87
87
  - lib/gh/link_follower.rb
88
+ - lib/gh/merge_commit.rb
88
89
  - lib/gh/normalizer.rb
89
90
  - lib/gh/remote.rb
90
91
  - lib/gh/response.rb