octokit 4.1.0 → 4.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42f87b8ae5be0908f5ebf3ea440b326dfeb90a67
4
- data.tar.gz: c81981cf6ef79e3e12a1af37100ce931b3a5ecbe
3
+ metadata.gz: 94d991c0ebb91eff8b87688e204c80b3820bcdbc
4
+ data.tar.gz: e81a6b01eadef14a4a2680dc192e6915a750af7c
5
5
  SHA512:
6
- metadata.gz: 3b0c8b13dcad559baeaed2e3ffd5eeba73755baaeca30cc0b36514d9050fc3a6f7f6d8638465cb7b1e0bc3c6807c08cba6760eb3ff0bb8453781557ab9d7b42a
7
- data.tar.gz: 4d3967580680dddd45f89fd64c327512ce90f64829070c82070e9dae2109308772f1879b8b5ea1c952b10b63313656b3d9a625aa156b7fec7c6c41354b1ab903
6
+ metadata.gz: a000cbae7cfd114165a405ca9cba6dc2ed847d979ec5b9a427ca5516ccda7705af72494eb82a5ba64c880c30acc9e40ef74b6cce7232d897ef17d39f77dbb5d8
7
+ data.tar.gz: ad4876a4392214c9a8b2c353bb7ff76f81d028c27c765e6b7c2da5c7404ec3c8801cd59a175d0377f129aab1f5c8cc688be846b33ff12d018fe2fbcf59804503
data/README.md CHANGED
@@ -639,8 +639,11 @@ Constraint][pvc] with two digits of precision. For example:
639
639
 
640
640
  spec.add_dependency 'octokit', '~> 3.0'
641
641
 
642
+ The changes made between versions can be seen on the [project releases page][releases].
643
+
642
644
  [semver]: http://semver.org/
643
645
  [pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint
646
+ [releases]: https://github.com/octokit/octokit.rb/releases
644
647
 
645
648
  ## License
646
649
 
@@ -113,12 +113,16 @@ module Octokit
113
113
  # Check scopes for a token
114
114
  #
115
115
  # @param token [String] GitHub OAuth token
116
+ # @param options [Hash] Header params for request
116
117
  # @return [Array<String>] OAuth scopes
117
118
  # @see https://developer.github.com/v3/oauth/#scopes
118
- def scopes(token = @access_token)
119
+ def scopes(token = @access_token, options = {})
119
120
  raise ArgumentError.new("Access token required") if token.nil?
120
121
 
121
- agent.call(:get, "user", :headers => {"Authorization" => "token #{token}" }).
122
+ auth = { "Authorization" => "token #{token}" }
123
+ headers = (options.delete(:headers) || {}).merge(auth)
124
+
125
+ agent.call(:get, "user", :headers => headers).
122
126
  headers['X-OAuth-Scopes'].
123
127
  to_s.
124
128
  split(',').
@@ -13,6 +13,8 @@ module Octokit
13
13
  # @return [Sawyer::Resource] if a repository exists, false otherwise
14
14
  def repository?(repo, options = {})
15
15
  !!repository(repo, options)
16
+ rescue Octokit::InvalidRepository
17
+ false
16
18
  rescue Octokit::NotFound
17
19
  false
18
20
  end
@@ -106,7 +106,7 @@ module Octokit
106
106
 
107
107
  # Deletes a public SSH keys.
108
108
  #
109
- # @param [id] Number The ID of the key to delete.
109
+ # @param id [Number] The ID of the key to delete.
110
110
  # @see https://developer.github.com/v3/users/administration/#delete-a-public-key
111
111
  # @example
112
112
  # @admin_client.delete_key(1)
@@ -238,4 +238,8 @@ module Octokit
238
238
  # Raised when a method requires an application client_id
239
239
  # and secret but none is provided
240
240
  class ApplicationCredentialsRequired < StandardError; end
241
+
242
+ # Raised when a repository is created with an invalid format
243
+ class InvalidRepository < ArgumentError; end
244
+
241
245
  end
@@ -4,6 +4,7 @@ module Octokit
4
4
  # URLs and to generate URLs
5
5
  class Repository
6
6
  attr_accessor :owner, :name, :id
7
+ NAME_WITH_OWNER_PATTERN = /\A[\w.-]+\/[\w.-]+\z/i
7
8
 
8
9
  # Instantiate from a GitHub repository URL
9
10
  #
@@ -12,15 +13,14 @@ module Octokit
12
13
  Repository.new(URI.parse(url).path[1..-1])
13
14
  end
14
15
 
16
+ # @raise [Octokit::InvalidRepository] if the repository
17
+ # has an invalid format
15
18
  def initialize(repo)
16
19
  case repo
17
20
  when Integer
18
21
  @id = repo
19
- when String
20
- @owner, @name = repo.split('/')
21
- unless @owner && @name
22
- raise ArgumentError, "Invalid Repository. Use user/repo format."
23
- end
22
+ when NAME_WITH_OWNER_PATTERN
23
+ @owner, @name = repo.split("/")
24
24
  when Repository
25
25
  @owner = repo.owner
26
26
  @name = repo.name
@@ -28,7 +28,10 @@ module Octokit
28
28
  @name = repo[:repo] ||= repo[:name]
29
29
  @owner = repo[:owner] ||= repo[:user] ||= repo[:username]
30
30
  else
31
- raise ArgumentError, "Invalid Repository. Use user/repo format."
31
+ raise_invalid_repository!
32
+ end
33
+ if @owner && @name
34
+ validate_owner_and_name!
32
35
  end
33
36
  end
34
37
 
@@ -71,5 +74,17 @@ module Octokit
71
74
  alias :user :owner
72
75
  alias :username :owner
73
76
  alias :repo :name
77
+
78
+ private
79
+
80
+ def validate_owner_and_name!
81
+ if @owner.include?('/') || @name.include?('/') || !url.match(/\A#{URI.regexp}\z/)
82
+ raise_invalid_repository!
83
+ end
84
+ end
85
+
86
+ def raise_invalid_repository!
87
+ raise Octokit::InvalidRepository, "Invalid Repository. Use user/repo format."
88
+ end
74
89
  end
75
90
  end
@@ -9,7 +9,7 @@ module Octokit
9
9
 
10
10
  # Current patch level.
11
11
  # @return [Integer]
12
- PATCH = 0
12
+ PATCH = 1
13
13
 
14
14
  # Full release version.
15
15
  # @return [String]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octokit
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wynn Netherland
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-08-22 00:00:00.000000000 Z
13
+ date: 2015-09-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler