Skip to content

Commit 41ccaed

Browse files
committed
Merge branch 'master' of github.com:peter-murach/github
2 parents 94a3d2d + caa69dd commit 41ccaed

8 files changed

Lines changed: 39 additions & 8 deletions

File tree

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -596,11 +596,7 @@ A Rails controller that allows a user to authorize their GitHub account and then
596596
```ruby
597597
class GithubController < ApplicationController
598598

599-
attr_accessor :github
600-
private :github
601-
602599
def authorize
603-
github = Github.new client_id: '...', client_secret: '...'
604600
address = github.authorize_url redirect_uri: 'http://...', scope: 'repo'
605601
redirect_to address
606602
end
@@ -610,6 +606,12 @@ class GithubController < ApplicationController
610606
access_token = github.get_token authorization_code
611607
access_token.token # => returns token value
612608
end
609+
610+
private
611+
612+
def github
613+
@github ||= Github.new client_id: '...', client_secret: '...'
614+
end
613615
end
614616
```
615617

@@ -621,7 +623,7 @@ In order to be able to create/update/remove files you need to use Contents API l
621623
contents = Github::Client::Repos::Contents.new oauth_token: '...'
622624
```
623625

624-
Having instantiaed the contents, to create a file do:
626+
Having instantiated the contents, to create a file do:
625627

626628
```ruby
627629
contents.create 'username', 'repo_name', 'full_path_to/file.ext',

lib/github_api/client/issues/labels.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def add(*args)
143143
# @example
144144
# github = Github.new
145145
# github.issues.labels.remove 'user-name', 'repo-name', 'issue-number',
146-
# lable_name: 'label-name'
146+
# label_name: 'label-name'
147147
#
148148
# Remove all labels from an issue
149149
#

lib/github_api/client/repos/collaborators.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def list(*args)
3333
#
3434
# @example
3535
# github = Github.new
36-
# github.collaborators.add 'user', 'repo', 'username'
36+
# github.repos.collaborators.add 'user', 'repo', 'username'
3737
#
3838
# @example
3939
# collaborators = Github::Repos::Collaborators.new

lib/github_api/client/repos/contents.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class Client::Repos::Contents < API
2020
# github = Github.new
2121
# github.repos.contents.readme 'user-name', 'repo-name'
2222
#
23-
# content = Github::Repos;:Contents.new user: 'user-name', 'repo-name'
23+
# @example
24+
# content = Github::Client::Repos::Contents.new user: 'user-name', repo: 'repo-name'
2425
# content.readme
2526
#
2627
# @api public

lib/github_api/request.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def call(current_options, params)
6161
connection_options = current_options.merge(request_options)
6262
conn = connection(api, connection_options)
6363

64+
self.path = Utils::Url.normalize(self.path)
6465
if conn.path_prefix != '/' && self.path.index(conn.path_prefix) != 0
6566
self.path = (conn.path_prefix + self.path).gsub(/\/(\/)*/, '/')
6667
end

lib/github_api/utils/url.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def escape(s) CGI.escape(s.to_s) end
1616

1717
def unescape(s) CGI.unescape(s.to_s) end
1818

19+
def normalize(s) Addressable::URI.parse(s.to_s).normalize.path end
20+
1921
def build_query(params)
2022
params.map { |k, v|
2123
if v.class == Array

spec/github/request_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,23 @@
3838
expect(request).to receive(:call).with(github.current_options, params)
3939
github.delete_request path, params
4040
end
41+
42+
context "with invalid characters in path" do
43+
let(:wrong_path) { 'github.api/$repos★/!usersÇ' }
44+
let(:normalized_url) { 'https://api.github.com/github.api/$repos%E2%98%85/!users%C3%87' }
45+
46+
before do
47+
expect(params).to receive(:options).exactly(5).times { { raw: false } }
48+
expect(params).to receive(:request_params).exactly(2).times { {} }
49+
end
50+
51+
it "removes invalid characters before making a request" do
52+
[:get, :patch, :post, :put, :delete].each do |request_type|
53+
stub_request(request_type, normalized_url).
54+
to_return(:status => 200, :body => "", :headers => {})
55+
56+
github.send("#{request_type}_request".to_sym, wrong_path, params)
57+
end
58+
end
59+
end
4160
end # Github::Request

spec/github/utils/url_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ def eq_query_to(query)
2121
described_class.unescape('%5C%2F%3F%7D%21%40%23%24%25%5E%26%2A%28%29').should eql '\\/?}!@#$%^&*()'
2222
end
2323

24+
it 'normalizes correctly' do
25+
described_class.normalize('github.api/$repos★/!usersÇ').should eql 'github.api/$repos%E2%98%85/!users%C3%87'
26+
described_class.normalize('123github!@').should eql '123github!@'
27+
described_class.normalize('github.api/repos/users').should eql 'github.api/repos/users'
28+
end
29+
2430
context 'parses query strings correctly' do
2531
it { described_class.parse_query("a=b").should eq 'a' => 'b' }
2632
it { described_class.parse_query("a=b&a=c").should eq 'a' => ['b','c'] }

0 commit comments

Comments
 (0)