github_api 0.10.2 → 0.11.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.
Files changed (95) hide show
  1. data/README.md +78 -59
  2. data/features/cassettes/repos/assets/delete.yml +52 -0
  3. data/features/cassettes/repos/assets/edit.yml +65 -0
  4. data/features/cassettes/repos/assets/get.yml +74 -0
  5. data/features/cassettes/repos/assets/list.yml +73 -0
  6. data/features/cassettes/repos/assets/upload.yml +66 -0
  7. data/features/cassettes/repos/list_org.yml +167 -0
  8. data/features/cassettes/repos/list_org_instance.yml +300 -0
  9. data/features/cassettes/repos/releases/create.yml +64 -0
  10. data/features/cassettes/repos/releases/delete.yml +52 -0
  11. data/features/cassettes/repos/releases/edit.yml +63 -0
  12. data/features/cassettes/repos/releases/get.yml +78 -0
  13. data/features/cassettes/repos/releases/list.yml +81 -0
  14. data/features/cassettes/search/code.yml +252 -0
  15. data/features/cassettes/search/code_query.yml +65 -0
  16. data/features/cassettes/search/issues.yml +616 -170
  17. data/features/cassettes/search/legacy/email.yml +72 -0
  18. data/features/cassettes/search/legacy/issues.yml +119 -0
  19. data/features/cassettes/search/legacy/repos.yml +394 -0
  20. data/features/cassettes/search/legacy/users.yml +72 -0
  21. data/features/cassettes/search/legacy/users_keyword.yml +63 -0
  22. data/features/cassettes/search/repos.yml +375 -364
  23. data/features/cassettes/search/users.yml +40 -22
  24. data/features/cassettes/search/users_keyword.yml +51 -56
  25. data/features/repos.feature +22 -0
  26. data/features/repos/assets.feature +59 -0
  27. data/features/repos/releases.feature +58 -0
  28. data/features/search.feature +24 -13
  29. data/features/search/legacy.feature +59 -0
  30. data/features/settings.yml +2 -5
  31. data/features/step_definitions/github_api_steps.rb +12 -0
  32. data/lib/github_api/configuration.rb +3 -1
  33. data/lib/github_api/error.rb +6 -17
  34. data/lib/github_api/error/unknown_media.rb +18 -0
  35. data/lib/github_api/params_hash.rb +20 -10
  36. data/lib/github_api/repos.rb +26 -15
  37. data/lib/github_api/repos/releases.rb +146 -0
  38. data/lib/github_api/repos/releases/assets.rb +126 -0
  39. data/lib/github_api/request.rb +14 -9
  40. data/lib/github_api/resource.rb +8 -1
  41. data/lib/github_api/search.rb +68 -27
  42. data/lib/github_api/search/legacy.rb +94 -0
  43. data/lib/github_api/ssl_certs/cacert.pem +41 -0
  44. data/lib/github_api/ssl_certs/cacerts.pem +2183 -0
  45. data/lib/github_api/version.rb +2 -2
  46. data/spec/fixtures/repos/asset.json +12 -0
  47. data/spec/fixtures/repos/assets.json +14 -0
  48. data/spec/fixtures/repos/release.json +15 -0
  49. data/spec/fixtures/repos/releases.json +17 -0
  50. data/spec/fixtures/search/code.json +76 -0
  51. data/spec/fixtures/search/issues.json +47 -16
  52. data/spec/fixtures/search/issues_legacy.json +23 -0
  53. data/spec/fixtures/search/repos.json +39 -0
  54. data/spec/fixtures/search/{repositories.json → repos_legacy.json} +0 -0
  55. data/spec/fixtures/search/users.json +15 -19
  56. data/spec/fixtures/search/users_legacy.json +24 -0
  57. data/spec/github/configuration_spec.rb +2 -0
  58. data/spec/github/error/unknown_media_spec.rb +21 -0
  59. data/spec/github/git_data/references/create_spec.rb +1 -1
  60. data/spec/github/git_data/references/get_spec.rb +6 -4
  61. data/spec/github/git_data/references/list_spec.rb +6 -16
  62. data/spec/github/pagination/iterator/number_spec.rb +2 -2
  63. data/spec/github/pagination/iterator/sha_spec.rb +2 -2
  64. data/spec/github/params_hash_spec.rb +6 -0
  65. data/spec/github/repos/assets/delete_spec.rb +40 -0
  66. data/spec/github/repos/assets/edit_spec.rb +40 -0
  67. data/spec/github/repos/assets/get_spec.rb +45 -0
  68. data/spec/github/repos/assets/list_spec.rb +55 -0
  69. data/spec/github/repos/assets/upload_spec.rb +44 -0
  70. data/spec/github/repos/downloads/upload_spec.rb +5 -5
  71. data/spec/github/repos/releases/create_spec.rb +44 -0
  72. data/spec/github/repos/releases/delete_spec.rb +40 -0
  73. data/spec/github/repos/releases/edit_spec.rb +40 -0
  74. data/spec/github/repos/releases/get_spec.rb +45 -0
  75. data/spec/github/repos/releases/list_spec.rb +54 -0
  76. data/spec/github/request/endpoint_spec.rb +1 -3
  77. data/spec/github/request/request_spec.rb +4 -8
  78. data/spec/github/request_spec.rb +3 -3
  79. data/spec/github/response_wrapper_spec.rb +3 -3
  80. data/spec/github/s3_uploader_spec.rb +2 -3
  81. data/spec/github/search/code_spec.rb +38 -0
  82. data/spec/github/search/issues_spec.rb +38 -0
  83. data/spec/github/search/legacy/email_spec.rb +34 -0
  84. data/spec/github/search/legacy/issues_spec.rb +39 -0
  85. data/spec/github/search/legacy/repos_spec.rb +36 -0
  86. data/spec/github/search/legacy/users_spec.rb +36 -0
  87. data/spec/github/search/repos_spec.rb +38 -0
  88. data/spec/github/search/users_spec.rb +38 -0
  89. data/spec/github/users/get_spec.rb +1 -1
  90. data/spec/github/validations/presence_spec.rb +2 -5
  91. data/spec/integration/repos_spec.rb +4 -0
  92. data/spec/integration/search_spec.rb +12 -0
  93. metadata +122 -62
  94. data/features/cassettes/search/email.yml +0 -99
  95. data/spec/github/search_spec.rb +0 -102
@@ -13,8 +13,8 @@ describe Github::PageIterator, 'when number' do
13
13
  let(:last_link) { "https://api.github.com/users/wycats/repos?page=6&per_page=20" }
14
14
 
15
15
  let(:current_api) { Github::Repos.new }
16
- let(:user) { 'wycats' }
17
- let(:response) { stub(:response).as_null_object }
16
+ let(:user) { 'wycats' }
17
+ let(:response) { double(:response).as_null_object }
18
18
 
19
19
  subject(:instance) { described_class.new(links, current_api) }
20
20
 
@@ -15,8 +15,8 @@ describe Github::PageIterator, 'when sha' do
15
15
  let(:last_sha) { "d1e503c02fa770859895dd0d12aedefa28b95723"}
16
16
 
17
17
  let(:current_api) { Github::Repos.new }
18
- let(:user) { 'wycats' }
19
- let(:response) { stub(:response).as_null_object }
18
+ let(:user) { 'wycats' }
19
+ let(:response) { double(:response).as_null_object }
20
20
 
21
21
  subject(:instance) { described_class.new(links, current_api) }
22
22
 
@@ -47,6 +47,12 @@ describe Github::ParamsHash do
47
47
  it { expect(subject.data).to eql('foobar') }
48
48
  end
49
49
 
50
+ context 'extracts options headers' do
51
+ let(:hash) { {:content_type => 'application/octet-stream'} }
52
+
53
+ it { expect(subject.options[:headers]).to eql(hash) }
54
+ end
55
+
50
56
  context 'merges defaults' do
51
57
  let(:hash) { { :homepage => "https://tty.github.io" }}
52
58
  let(:defaults) {
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Releases::Assets, '#delete' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:path) { "/repos/#{user}/#{repo}/releases/assets/#{id}" }
9
+ let(:id) { 1 }
10
+
11
+ before {
12
+ stub_delete(path).to_return(body: body, status: status,
13
+ headers: {content_type: 'application/json; charset=utf-8'})
14
+ }
15
+
16
+ after { reset_authentication_for(subject) }
17
+
18
+ context "resource found successfully" do
19
+ let(:body) { '' }
20
+ let(:status) { 204 }
21
+
22
+ it "should fail to delete without 'user/repo' parameters" do
23
+ expect { subject.delete }.to raise_error(ArgumentError)
24
+ end
25
+
26
+ it "should fail to delete resource without asset id" do
27
+ expect { subject.delete user, repo }.to raise_error(ArgumentError)
28
+ end
29
+
30
+ it "should delete the resource" do
31
+ subject.delete user, repo, id
32
+ a_delete(path).should have_been_made
33
+ end
34
+ end
35
+
36
+ it_should_behave_like 'request failure' do
37
+ let(:requestable) { subject.delete user, repo, id }
38
+ end
39
+
40
+ end # delete
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Releases::Assets, '#edit' do
6
+ let(:owner) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:id) { 1 }
9
+ let(:path) { "/repos/#{owner}/#{repo}/releases/assets/#{id}" }
10
+ let(:inputs) { {'name' => 'readme', 'label' => 'New readme'} }
11
+
12
+ before {
13
+ stub_patch(path).with(inputs).to_return(body: body, status: status,
14
+ headers: {content_type: 'application/json; charset=utf-8'})
15
+ }
16
+
17
+ after { reset_authentication_for(subject) }
18
+
19
+ context "resource edited successfully" do
20
+ let(:body) { fixture("repos/asset.json") }
21
+ let(:status) { 200 }
22
+
23
+ it { expect {subject.edit owner, repo }.to raise_error(ArgumentError) }
24
+
25
+ it "should edit the resource" do
26
+ subject.edit owner, repo, id, inputs
27
+ expect(a_patch(path)).to have_been_made
28
+ end
29
+
30
+ it "should get the asset information back" do
31
+ asset = subject.edit owner, repo, id, inputs
32
+ expect(asset.id).to eq id
33
+ end
34
+ end
35
+
36
+ it_should_behave_like 'request failure' do
37
+ let(:requestable) { subject.edit owner, repo, id, inputs }
38
+ end
39
+
40
+ end # edit
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Releases::Assets, '#get' do
6
+ let(:owner) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:id) { 1 }
9
+ let(:path) { "/repos/#{owner}/#{repo}/releases/assets/#{id}" }
10
+
11
+ before {
12
+ stub_get(path).to_return(body: body, status: status,
13
+ headers: {content_type: 'application/json; charset=utf-8'})
14
+ }
15
+
16
+ after { reset_authentication_for(subject) }
17
+
18
+ context "resource found" do
19
+ let(:body) { fixture("repos/release.json") }
20
+ let(:status) { 200 }
21
+
22
+ it { should respond_to :find }
23
+
24
+ it { expect { subject.get }.to raise_error(ArgumentError) }
25
+
26
+ it "should fail to get resource without id" do
27
+ expect { subject.get owner, repo }.to raise_error(ArgumentError)
28
+ end
29
+
30
+ it "should get the resource" do
31
+ subject.get owner, repo, id
32
+ expect(a_get(path)).to have_been_made
33
+ end
34
+
35
+ it "should get key information" do
36
+ asset = subject.get owner, repo, id
37
+ expect(asset.id).to eq id
38
+ end
39
+ end
40
+
41
+ it_should_behave_like 'request failure' do
42
+ let(:requestable) { subject.get owner, repo, id }
43
+ end
44
+
45
+ end # get
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Releases::Assets, '#list' do
6
+ let(:owner) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:id) { 1 }
9
+ let(:path) { "/repos/#{owner}/#{repo}/releases/#{id}/assets" }
10
+
11
+ before {
12
+ stub_get(path).to_return(body: body, status: status,
13
+ headers: {content_type: 'application/json; charset=utf-8'})
14
+ }
15
+
16
+ after { reset_authentication_for(subject) }
17
+
18
+ context "resource found" do
19
+ let(:body) { fixture("repos/assets.json") }
20
+ let(:status) { 200 }
21
+
22
+ it { should respond_to :all }
23
+
24
+ it { expect { subject.list }.to raise_error(ArgumentError) }
25
+
26
+ it "should fail to get resource without repository" do
27
+ expect { subject.list owner }.to raise_error(ArgumentError)
28
+ end
29
+
30
+ it "should get the resources" do
31
+ subject.list owner, repo, id
32
+ expect(a_get(path)).to have_been_made
33
+ end
34
+
35
+ it_should_behave_like 'an array of resources' do
36
+ let(:requestable) { subject.list owner, repo, id }
37
+ end
38
+
39
+ it "should get asset information" do
40
+ assets = subject.list owner, repo, id
41
+ expect(assets.first.name).to eq 'example.zip'
42
+ end
43
+
44
+ it "should yield to a block" do
45
+ yielded = []
46
+ result = subject.list(owner, repo, id) { |obj| yielded << obj }
47
+ expect(yielded).to eq result
48
+ end
49
+ end
50
+
51
+ it_should_behave_like 'request failure' do
52
+ let(:requestable) { subject.list owner, repo, id }
53
+ end
54
+
55
+ end # list
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Releases::Assets, '#upload' do
6
+ let(:owner) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:id) { 1 }
9
+ let(:filepath) { 'batman.js' }
10
+ let(:file) { double(:file, read: nil, close: nil) }
11
+ let(:endpoint) { 'https://uploads.github.com' }
12
+ let(:inputs) { {name: 'batman.jpg', content_type: 'application/javascript'} }
13
+ let(:path) { "/repos/#{owner}/#{repo}/releases/#{id}/assets" }
14
+
15
+ before {
16
+ Faraday::UploadIO.stub(:new).and_return(file)
17
+ stub_post(path, endpoint).with(query: {name:'batman.jpg'}).to_return(body: body, status: status,
18
+ headers: {content_type: 'application/json; charset=utf-8'})
19
+ }
20
+
21
+ after { reset_authentication_for(subject) }
22
+
23
+ context "resource edited successfully" do
24
+ let(:body) { fixture("repos/asset.json") }
25
+ let(:status) { 201 }
26
+
27
+ it { expect {subject.upload owner, repo }.to raise_error(ArgumentError) }
28
+
29
+ it "should upload the resource" do
30
+ subject.upload owner, repo, id, filepath, inputs
31
+ expect(a_post(path, endpoint).with(query: {name:'batman.jpg'})).to have_been_made
32
+ end
33
+
34
+ it "should get the asset information back" do
35
+ asset = subject.upload owner, repo, id, filepath, inputs
36
+ expect(asset.id).to eq id
37
+ end
38
+ end
39
+
40
+ it_should_behave_like 'request failure' do
41
+ let(:requestable) { subject.upload owner, repo, id, filepath, inputs }
42
+ end
43
+
44
+ end # upload
@@ -9,10 +9,10 @@ describe Github::Repos::Downloads do
9
9
 
10
10
  after { reset_authentication_for(subject) }
11
11
 
12
- let(:resource) { stub(:resource) }
12
+ let(:resource) { double(:resource) }
13
13
  let(:filename) { 'filename' }
14
- let(:res) { stub(:response, :body => 'success') }
15
- let(:uploader) { stub(:uploader, :send => res) }
14
+ let(:res) { double(:response, :body => 'success') }
15
+ let(:uploader) { double(:uploader, :send => res) }
16
16
 
17
17
  before { Github::S3Uploader.stub(:new) { uploader } }
18
18
 
@@ -23,8 +23,8 @@ describe Github::Repos::Downloads do
23
23
  end
24
24
 
25
25
  it "should upload resource successfully" do
26
- res = stub(:response, :body => 'success')
27
- uploader = stub(:uploader, :send => res)
26
+ res = double(:response, :body => 'success')
27
+ uploader = double(:uploader, :send => res)
28
28
  Github::S3Uploader.should_receive(:new).with(resource, filename) { uploader }
29
29
  subject.upload(resource, filename).should == 'success'
30
30
  end
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Releases, '#create' do
6
+ let(:owner) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:tag) { 'v1.0.0' }
9
+ let(:path ) { "/repos/#{owner}/#{repo}/releases" }
10
+ let(:inputs) { {'name' => 'v1.0.0', 'body' => 'New release'} }
11
+
12
+ before {
13
+ stub_post(path).with(inputs).to_return(body: body, status: status,
14
+ headers: {content_type: 'application/json; charset=utf-8'})
15
+ }
16
+
17
+ after { reset_authentication_for(subject) }
18
+
19
+ context 'resource created' do
20
+ let(:body) { fixture('repos/release.json') }
21
+ let(:status) { 201 }
22
+
23
+ it 'should fail to create resource without tag name' do
24
+ expect {
25
+ subject.create owner, repo
26
+ }.to raise_error(ArgumentError)
27
+ end
28
+
29
+ it "should create the resource" do
30
+ subject.create owner, repo, tag, inputs
31
+ expect(a_post(path).with(inputs)).to have_been_made
32
+ end
33
+
34
+ it "should get the key information back" do
35
+ release = subject.create owner, repo, tag, inputs
36
+ expect(release.tag_name).to eq tag
37
+ end
38
+ end
39
+
40
+ it_should_behave_like 'request failure' do
41
+ let(:requestable) { subject.create owner, repo, tag, inputs }
42
+ end
43
+
44
+ end # create
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Releases, '#delete' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:id) { 1 }
9
+ let(:path) { "/repos/#{user}/#{repo}/releases/#{id}" }
10
+
11
+ before {
12
+ stub_delete(path).to_return(body: body, status: status,
13
+ headers: {content_type: 'application/json; charset=utf-8'})
14
+ }
15
+
16
+ after { reset_authentication_for(subject) }
17
+
18
+ context "resource found successfully" do
19
+ let(:body) { '' }
20
+ let(:status) { 204 }
21
+
22
+ it "should fail to delete without 'user/repo' parameters" do
23
+ expect { subject.delete }.to raise_error(ArgumentError)
24
+ end
25
+
26
+ it "should fail to delete resource without key id" do
27
+ expect { subject.delete user, repo }.to raise_error(ArgumentError)
28
+ end
29
+
30
+ it "should delete the resource" do
31
+ subject.delete user, repo, id
32
+ a_delete(path).should have_been_made
33
+ end
34
+ end
35
+
36
+ it_should_behave_like 'request failure' do
37
+ let(:requestable) { subject.delete user, repo, id }
38
+ end
39
+
40
+ end # delete
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Releases, '#edit' do
6
+ let(:owner) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:id) { 1 }
9
+ let(:path) { "/repos/#{owner}/#{repo}/releases/#{id}" }
10
+ let(:inputs) { {'name' => 'v1.0.0', 'body' => 'New release'} }
11
+
12
+ before {
13
+ stub_patch(path).with(inputs).to_return(body: body, status: status,
14
+ headers: {content_type: 'application/json; charset=utf-8'})
15
+ }
16
+
17
+ after { reset_authentication_for(subject) }
18
+
19
+ context "resource edited successfully" do
20
+ let(:body) { fixture("repos/release.json") }
21
+ let(:status) { 200 }
22
+
23
+ it { expect {subject.edit owner, repo }.to raise_error(ArgumentError) }
24
+
25
+ it "should edit the resource" do
26
+ subject.edit owner, repo, id, inputs
27
+ expect(a_patch(path)).to have_been_made
28
+ end
29
+
30
+ it "should get the key information back" do
31
+ release = subject.edit owner, repo, id, inputs
32
+ expect(release.id).to eq id
33
+ end
34
+ end
35
+
36
+ it_should_behave_like 'request failure' do
37
+ let(:requestable) { subject.edit owner, repo, id, inputs }
38
+ end
39
+
40
+ end # edit
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Releases, '#get' do
6
+ let(:owner) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:id) { 1 }
9
+ let(:path) { "/repos/#{owner}/#{repo}/releases/#{id}" }
10
+
11
+ before {
12
+ stub_get(path).to_return(body: body, status: status,
13
+ headers: {content_type: 'application/json; charset=utf-8'})
14
+ }
15
+
16
+ after { reset_authentication_for(subject) }
17
+
18
+ context "resource found" do
19
+ let(:body) { fixture("repos/release.json") }
20
+ let(:status) { 200 }
21
+
22
+ it { should respond_to :find }
23
+
24
+ it { expect { subject.get }.to raise_error(ArgumentError) }
25
+
26
+ it "should fail to get resource without key" do
27
+ expect { subject.get owner, repo }.to raise_error(ArgumentError)
28
+ end
29
+
30
+ it "should get the resource" do
31
+ subject.get owner, repo, id
32
+ expect(a_get(path)).to have_been_made
33
+ end
34
+
35
+ it "should get key information" do
36
+ release = subject.get owner, repo, id
37
+ expect(release.id).to eq id
38
+ end
39
+ end
40
+
41
+ it_should_behave_like 'request failure' do
42
+ let(:requestable) { subject.get owner, repo, id }
43
+ end
44
+
45
+ end # get