octokit 1.24.0 → 1.25.0

Sign up to get free protection for your applications and to get access to all the features.
data/CONTRIBUTING.md CHANGED
@@ -2,9 +2,9 @@
2
2
  1. [Fork the repository.][fork]
3
3
  2. [Create a topic branch.][branch]
4
4
  3. Add specs for your unimplemented feature or bug fix.
5
- 4. Run `bundle exec rake spec`. If your specs pass, return to step 3.
5
+ 4. Run `bundle exec rspec-queue spec`. If your specs pass, return to step 3.
6
6
  5. Implement your feature or bug fix.
7
- 6. Run `bundle exec rake spec`. If your specs fail, return to step 5.
7
+ 6. Run `bundle exec rspec-queue spec`. If your specs fail, return to step 5.
8
8
  7. Run `open coverage/index.html`. If your changes are not completely covered
9
9
  by your tests, return to step 3.
10
10
  8. Add documentation for your feature or bug fix.
data/README.md CHANGED
@@ -1,67 +1,52 @@
1
1
  # Octokit
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/octokit.png)][gem]
4
- [![Build Status](https://secure.travis-ci.org/pengwynn/octokit.png?branch=master)][travis]
5
- [![Dependency Status](https://gemnasium.com/pengwynn/octokit.png?travis)][gemnasium]
6
- [![Code Climate](https://codeclimate.com/github/pengwynn/octokit.png)][codeclimate]
7
- [![Coverage Status](https://coveralls.io/repos/pengwynn/octokit/badge.png?branch=master)][coveralls]
8
-
9
- [gem]: https://rubygems.org/gems/octokit
10
- [travis]: http://travis-ci.org/pengwynn/octokit
11
- [gemnasium]: https://gemnasium.com/pengwynn/octokit
12
- [codeclimate]: https://codeclimate.com/github/pengwynn/octokit
13
- [coveralls]: https://coveralls.io/r/pengwynn/octokit
14
-
15
- Simple Ruby wrapper for the GitHub v3 API.
3
+ Simple Ruby wrapper for the GitHub API.
16
4
 
17
5
  ## Installation
6
+
18
7
  gem install octokit
19
8
 
20
9
  ## Documentation
10
+
21
11
  [http://rdoc.info/gems/octokit][documentation]
22
12
 
23
13
  [documentation]: http://rdoc.info/gems/octokit
24
14
 
25
- ## Examples
26
- ### Show a user
27
- ```ruby
28
- Octokit.user("sferik")
29
- => <#Hashie::Rash blog="http://twitter.com/sferik" company="Code for America" created_at="2008/05/14 13:36:12 -0700" email="sferik@gmail.com" followers_count=177 following_count=83 gravatar_id="1f74b13f1e5c6c69cb5d7fbaabb1e2cb" id=10308 location="San Francisco" login="sferik" name="Erik Michaels-Ober" permission=nil public_gist_count=16 public_repo_count=30 type="User">
30
- ```
15
+ ### Examples
16
+
17
+ #### Show a user
31
18
 
32
- ### Show who a user follows
33
19
  ```ruby
34
- Octokit.following("sferik")
35
- => ["rails", "puls", "wycats", "dhh", "jm3", "joshsusser", "nkallen", "technoweenie", "blaine", "al3x", "defunkt", "schacon", "bmizerany", "rtomayko", "jpr5", "lholden", "140proof", "ephramzerb", "carlhuda", "carllerche", "jnunemaker", "josh", "hoverbird", "jamiew", "jeremyevans", "brynary", "mojodna", "mojombo", "joshbuddy", "igrigorik", "perplexes", "joearasin", "hassox", "nickmarden", "pengwynn", "mmcgrana", "reddavis", "reinh", "mzsanford", "aanand", "pjhyett", "kneath", "tekkub", "adamstac", "timtrueman", "aaronblohowiak", "josevalim", "kaapa", "hurrycane", "jackdempsey", "drogus", "cameronpriest", "danmelton", "marcel", "r", "atmos", "mbleigh", "isaacs", "maxogden", "codeforamerica", "chadk", "laserlemon", "gruber", "lsegal", "bblimke", "wayneeseguin", "brixen", "dkubb", "bhb", "bcardarella", "elliottcable", "fbjork", "mlightner", "dianakimball", "amerine", "danchoi", "develop", "dmfrancisco", "unruthless", "trotter", "hannestyden", "codahale", "ry"]
20
+ Octokit.user "sferik"
21
+ => #<Hashie::Mash avatar_url="https://secure.gravatar.com/avatar/1f74b13f1e5c6c69cb5d7fbaabb1e2cb?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png" bio="" blog="http://twitter.com/sferik" company="" created_at="2008-05-14T20:36:12Z" email="sferik@gmail.com" events_url="https://api.github.com/users/sferik/events{/privacy}" followers=662 followers_url="https://api.github.com/users/sferik/followers" following=102 following_url="https://api.github.com/users/sferik/following{/other_user}" gists_url="https://api.github.com/users/sferik/gists{/gist_id}" gravatar_id="1f74b13f1e5c6c69cb5d7fbaabb1e2cb" hireable=false html_url="https://github.com/sferik" id=10308 location="San Francisco, CA" login="sferik" name="Erik Michaels-Ober" organizations_url="https://api.github.com/users/sferik/orgs" public_gists=59 public_repos=83 received_events_url="https://api.github.com/users/sferik/received_events" repos_url="https://api.github.com/users/sferik/repos" starred_url="https://api.github.com/users/sferik/starred{/owner}{/repo}" subscriptions_url="https://api.github.com/users/sferik/subscriptions" type="User" updated_at="2013-05-31T16:01:08Z" url="https://api.github.com/users/sferik">
36
22
  ```
37
23
 
38
- ### Repositories
24
+ #### Repositories
25
+
39
26
  For convenience, methods that require a repository argument may be passed in
40
27
  any of the following forms:
41
28
 
42
29
  ```ruby
43
- Octokit.repo("pengwynn/octokit")
44
-
45
- Octokit.repo({:username => "pengwynn", :name => "octokit"})
30
+ Octokit.repo "octokit/octokit.rb"
46
31
 
47
- Octokit.repo({:username => "pengwynn", :repo => "octokit"})
32
+ Octokit.repo {:username => "octokit", :name => "octokit.rb"}
48
33
 
49
- Octokit.repo(Repository.new('pengwynn/octokit'))
34
+ Octokit.repo {:username => "octokit", :repo => "octokit.rb"}
50
35
 
51
- => <#Hashie::Rash created_at="2009/12/10 13:41:49 -0800" description="Simple Ruby wrapper for the GitHub API and feeds" fork=false forks=25 has_downloads=true has_issues=true has_wiki=true homepage="http://wynnnetherland.com/projects/octokit" integrate_branch="master" language="Ruby" name="octokit" open_issues=8 owner="pengwynn" private=false pushed_at="2011/05/05 10:48:57 -0700" size=1804 url="https://github.com/pengwynn/octokit" watchers=92>
36
+ Octokit.repo Repository.new('octokit/octokit.rb')
52
37
  ```
53
38
 
54
- ### List the commits for a repository
39
+ #### List the commits for a repository
55
40
 
56
41
  ```ruby
57
- Octokit.commits("pengwynn/octokit")
42
+ Octokit.commits("octokit/octokit.rb")
58
43
 
59
- Octokit.list_commits("pengwynn/octokit")
44
+ Octokit.list_commits("octokit/octokit.rb")
60
45
 
61
- => [#<Hashie::Mash author=#<Hashie::Mash avatar_url="https://secure.gravatar.com/avatar/7e19cd5486b5d6dc1ef90e671ba52ae0?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png" gravatar_id="7e19cd5486b5d6dc1ef90e671ba52ae0" id=865 login="pengwynn" url="https://api.github.com/users/pengwynn"> commit=#<Hashie::Mash author=#<Hashie::Mash date="2012-10-31T15:17:51Z" email="wynn@github.com" name="Wynn Netherland"> comment_count=0 committer=#<Hashie::Mash date="2012-10-31T15:17:51Z" email="wynn@github.com" name="Wynn Netherland"> message="Fix bug with archive_link for private repo" tree=#<Hashie::Mash sha="49bf2a476aa819f29b0fc1a8805f7567f010006d" url="https://api.github.com/repos/pengwynn/octokit/git/trees/49bf2a476aa819f29b0fc1a8805f7567f010006d"> url="https://api.github.com/repos/pengwynn/octokit/git/commits/8db3df37fad3a021eb8036b007c718149836cb32"> committer=#<Hashie::Mash avatar_url="https://secure.gravatar.com/avatar/7e19cd5486b5d6dc1ef90e671ba52ae0?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png" gravatar_id="7e19cd5486b5d6dc1ef90e671ba52ae0" id=865 login="pengwynn" url="https://api.github.com/users/pengwynn"> parents=[#<Hashie::Mash sha="7a67f4b47791cb77de33e491df87cef06012c79f" url="https://api.github.com/repos/pengwynn/octokit/commits/7a67f4b47791cb77de33e491df87cef06012c79f">] sha="8db3df37fad3a021eb8036b007c718149836cb32" url="https://api.github.com/repos/pengwynn/octokit/commits/8db3df37fad3a021eb8036b007c718149836cb32">, ... , ...]
46
+ => [#<Hashie::Mash author=#<Hashie::Mash avatar_url="https://secure.gravatar.com/avatar/7e19cd5486b5d6dc1ef90e671ba52ae0?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png" gravatar_id="7e19cd5486b5d6dc1ef90e671ba52ae0" id=865 login="pengwynn" url="https://api.github.com/users/pengwynn"> commit=#<Hashie::Mash author=#<Hashie::Mash date="2012-10-31T15:17:51Z" email="wynn@github.com" name="Wynn Netherland"> comment_count=0 committer=#<Hashie::Mash date="2012-10-31T15:17:51Z" email="wynn@github.com" name="Wynn Netherland"> message="Fix bug with archive_link for private repo" tree=#<Hashie::Mash sha="49bf2a476aa819f29b0fc1a8805f7567f010006d" url="https://api.github.com/repos/octokit/octokit.rb/git/trees/49bf2a476aa819f29b0fc1a8805f7567f010006d"> url="https://api.github.com/repos/octokit/octokit.rb/git/commits/8db3df37fad3a021eb8036b007c718149836cb32"> committer=#<Hashie::Mash avatar_url="https://secure.gravatar.com/avatar/7e19cd5486b5d6dc1ef90e671ba52ae0?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png" gravatar_id="7e19cd5486b5d6dc1ef90e671ba52ae0" id=865 login="pengwynn" url="https://api.github.com/users/pengwynn"> parents=[#<Hashie::Mash sha="7a67f4b47791cb77de33e491df87cef06012c79f" url="https://api.github.com/repos/octokit/octokit.rb/commits/7a67f4b47791cb77de33e491df87cef06012c79f">] sha="8db3df37fad3a021eb8036b007c718149836cb32" url="https://api.github.com/repos/octokit/octokit.rb/commits/8db3df37fad3a021eb8036b007c718149836cb32">, ... , ...]
62
47
  ```
63
48
 
64
- ## Authenticated Requests
49
+ #### Authenticated Requests
65
50
  For methods that require authentication, you'll need to setup a client with
66
51
  your login and password.
67
52
 
@@ -79,26 +64,7 @@ client = Octokit::Client.new(:login => "me", :oauth_token => "oauth2token")
79
64
  client.follow("sferik")
80
65
  ```
81
66
 
82
- ### Using `.netrc` for stored credentials
83
-
84
- Octokit now supports [`.netrc`][netrc] files for storing your GitHub Basic Auth
85
- credentials. Given a `~/.netrc` like the following
86
-
87
- [netrc]: http://www.gnu.org/software/inetutils/manual/html_node/The-_002enetrc-File.html
88
-
89
- ```
90
- machine api.github.com login pengwynn password 0ct0c4tz4ev3r!
91
- ```
92
-
93
- You can make authenticated calls by telling Octokit to use credentials from
94
- this file:
95
-
96
- ```ruby
97
- Octokit.netrc = true # or /path/to/file
98
- Octokit.user # authenticates as 'pengwynn' user
99
- ```
100
-
101
- ## Requesting a specific media type
67
+ #### Requesting a specific media type
102
68
 
103
69
  You can pass an `:accept` option value to request a particular [media
104
70
  type][media-types].
@@ -106,10 +72,10 @@ type][media-types].
106
72
  [media-types]: http://developer.github.com/v3/media/
107
73
 
108
74
  ```ruby
109
- Octokit.contents 'pengwynn/octokit', :path => 'README.md', :accept => 'application/vnd.github.html'
75
+ Octokit.contents 'octokit/octokit.rb', :path => 'README.md', :accept => 'application/vnd.github.html'
110
76
  ```
111
77
 
112
- ## Using with GitHub Enterprise
78
+ ### Using with GitHub Enterprise
113
79
 
114
80
  To use with [GitHub Enterprise](https://enterprise.github.com/), you'll need to
115
81
  set the API and web endpoints before instantiating a client.
@@ -173,7 +139,7 @@ dependency. Please require it explicitly if you're running Ruby 1.8
173
139
 
174
140
  Octokit was initially created by Wynn Netherland and [Adam
175
141
  Stacoviak](http://twitter.com/adamstac) but has
176
- turned into a true community effort. Special thanks to the following core
142
+ turned into a true community effort. Special thanks to the following
177
143
  contributors:
178
144
 
179
145
  * [Erik Michaels-Ober](http://github.com/sferik)
@@ -182,12 +148,14 @@ contributors:
182
148
 
183
149
 
184
150
  ## Inspiration
151
+
185
152
  Octokit was inspired by [Octopi][] and aims to be a lightweight,
186
153
  less-ActiveResourcey alternative.
187
154
 
188
155
  [octopi]: https://github.com/fcoury/octopi
189
156
 
190
157
  ## Copyright
158
+
191
159
  Copyright (c) 2011-2013 Wynn Netherland, Adam Stacoviak, Erik Michaels-Ober.
192
160
  See [LICENSE][] for details.
193
161
 
@@ -26,6 +26,7 @@ require 'octokit/client/markdown'
26
26
  require 'octokit/client/emojis'
27
27
  require 'octokit/client/statuses'
28
28
  require 'octokit/client/say'
29
+ require 'octokit/client/stats'
29
30
  require 'octokit/client/rate_limit'
30
31
  require 'octokit/client/gitignore'
31
32
  require 'octokit/client/github'
@@ -69,6 +70,7 @@ module Octokit
69
70
  include Octokit::Client::Emojis
70
71
  include Octokit::Client::Statuses
71
72
  include Octokit::Client::Say
73
+ include Octokit::Client::Stats
72
74
  include Octokit::Client::RateLimit
73
75
  include Octokit::Client::Gitignore
74
76
  include Octokit::Client::GitHub
@@ -72,7 +72,7 @@ module Octokit
72
72
  # @see http://developer.github.com/v3/oauth/#scopes for available scopes
73
73
  # @example Update the authorization for user ctshryock's project Zoidberg
74
74
  # client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
75
- # client.create_authorization({:add_scopes => ["gist", "repo"], :note => "Why not Zoidberg possibly?"})
75
+ # client.update_authorization(999999, {:add_scopes => ["gist", "repo"], :note => "Why not Zoidberg possibly?"})
76
76
  def update_authorization(number, options={})
77
77
  # Techincally we can omit scopes as GitHub has a default, however the
78
78
  # API will reject us if we send a POST request with an empty body.
@@ -1,3 +1,5 @@
1
+ require 'base64'
2
+
1
3
  module Octokit
2
4
  class Client
3
5
  module Contents
@@ -28,6 +30,107 @@ module Octokit
28
30
  url = "repos/#{Repository.new repo}/contents/#{repo_path}"
29
31
  get(url, options)
30
32
  end
33
+ alias :content :contents
34
+
35
+ # Add content to a repository
36
+ #
37
+ # @param repo [String, Repository, Hash] A GitHub repository
38
+ # @param path [String] A path for the new content
39
+ # @param message [String] A commit message for adding the content
40
+ # @param optional content [String] The Base64-encoded content for the file
41
+ # @option options [String] :branch The branch on which to add the content
42
+ # @option options [String] :file Path or Ruby File object for content
43
+ # @return [Hash] The contents and commit info for the addition
44
+ # @see http://developer.github.com/v3/repos/contents/#create-a-file
45
+ # @example Add content at lib/octokit.rb
46
+ # Octokit.create_contents("pengwynn/octokit",
47
+ # "lib/octokit.rb",
48
+ # "Adding content",
49
+ # "asdf9as0df9asdf8as0d9f8==...",
50
+ # :branch => "my-new-feature")
51
+ def create_contents(*args)
52
+ options = args.last.is_a?(Hash) ? args.pop : {}
53
+ repo = args.shift
54
+ path = args.shift
55
+ message = args.shift
56
+ content = args.shift
57
+ if content.nil? && file = options.delete(:file)
58
+ case file
59
+ when String
60
+ if File.exists?(file)
61
+ file = File.open(file, "r")
62
+ content = file.read
63
+ file.close
64
+ end
65
+ when File
66
+ content = file.read
67
+ file.close
68
+ end
69
+ end
70
+ raise ArgumentError.new "content or :file option required" if content.nil?
71
+ options[:content] = Base64.encode64(content).delete("\r\n")
72
+ options[:message] = message
73
+ url = "repos/#{Repository.new repo}/contents/#{path}"
74
+ put(url, options)
75
+ end
76
+ alias :create_content :create_contents
77
+ alias :add_content :create_contents
78
+ alias :add_contents :create_contents
79
+
80
+ # Update content in a repository
81
+ #
82
+ # @param repo [String, Repository, Hash] A GitHub repository
83
+ # @param path [String] A path for the content to update
84
+ # @param message [String] A commit message for updating the content
85
+ # @param sha [String] The _blob sha_ of the content to update
86
+ # @param content [String] The Base64-encoded content for the file
87
+ # @option options [String] :branch The branch on which to update the content
88
+ # @option options [String] :file Path or Ruby File object for content
89
+ # @return [Hash] The contents and commit info for the update
90
+ # @see http://developer.github.com/v3/repos/contents/#update-a-file
91
+ # @example Update content at lib/octokit.rb
92
+ # Octokit.update_contents("pengwynn/octokit",
93
+ # "lib/octokit.rb",
94
+ # "Updating content",
95
+ # "7eb95f97e1a0636015df3837478d3f15184a5f49",
96
+ # "asdf9as0df9asdf8as0d9f8==...",
97
+ # :branch => "my-new-feature")
98
+ def update_contents(*args)
99
+ options = args.last.is_a?(Hash) ? args.pop : {}
100
+ repo = args.shift
101
+ path = args.shift
102
+ message = args.shift
103
+ sha = args.shift
104
+ content = args.shift
105
+ options.merge!(:sha => sha)
106
+ create_contents(repo, path, message, content, options)
107
+ end
108
+ alias :update_content :update_contents
109
+
110
+ # Delete content in a repository
111
+ #
112
+ # @param repo [String, Repository, Hash] A GitHub repository
113
+ # @param path [String] A path for the content to delete
114
+ # @param message [String] A commit message for deleting the content
115
+ # @param sha [String] The _blob sha_ of the content to delete
116
+ # @option options [String] :branch The branch on which to delete the content
117
+ # @return [Hash] The commit info for the delete
118
+ # @see http://developer.github.com/v3/repos/contents/#delete-a-file
119
+ # @example Delete content at lib/octokit.rb
120
+ # Octokit.delete_contents("pengwynn/octokit",
121
+ # "lib/octokit.rb",
122
+ # "Deleting content",
123
+ # "7eb95f97e1a0636015df3837478d3f15184a5f49",
124
+ # :branch => "my-new-feature")
125
+ def delete_contents(repo, path, message, sha, options = {})
126
+ options[:message] = message
127
+ options[:sha] = sha
128
+ url = "repos/#{Repository.new repo}/contents/#{path}"
129
+ delete(url, options)
130
+ end
131
+ alias :delete_content :delete_contents
132
+ alias :remove_content :delete_contents
133
+ alias :remove_contents :delete_contents
31
134
 
32
135
  # This method will provide a URL to download a tarball or zipball archive for a repository.
33
136
  #
@@ -155,6 +155,7 @@ module Octokit
155
155
  # @option options [String] :assignee User login.
156
156
  # @option options [Integer] :milestone Milestone number.
157
157
  # @option options [String] :labels List of comma separated Label names. Example: <tt>bug,ui,@high</tt>.
158
+ # @option options [String] :state State of the issue. <tt>open</tt> or <tt>closed</tt>
158
159
  # @return [Issue] The updated Issue
159
160
  # @see http://developer.github.com/v3/issues/#edit-an-issue
160
161
  # @example Change the title of Issue #25
@@ -2,7 +2,7 @@ module Octokit
2
2
  class Client
3
3
  module Markdown
4
4
 
5
- # Receive the default Readme for a repository
5
+ # Render an arbitrary Markdown document
6
6
  #
7
7
  # @param text [String] Markdown source
8
8
  # @option options [String] (optional) :mode (`markdown` or `gfm`)
@@ -6,7 +6,7 @@ module Octokit
6
6
  #
7
7
  # @param repo [String, Repository, Hash] A GitHub repository
8
8
  # @param service_name [String] service name owner
9
- # @param service_arguments [Hash] params that will be passed by subscibed hook.
9
+ # @param service_arguments [Hash] params that will be passed by subscribed hook.
10
10
  # List of services is available @ https://github.com/github/github-services/tree/master/docs.
11
11
  # Please refer Data node for complete list of arguments.
12
12
  # @example Subscribe to push events to one of your repositories to Travis-CI
@@ -131,7 +131,7 @@ module Octokit
131
131
  # :since => '2010-05-04T23:45:02Z'
132
132
  # })
133
133
  def pull_requests_comments(repo, options={})
134
- get("repos/#{Repository.new repo}/pulls/comments")
134
+ get("repos/#{Repository.new repo}/pulls/comments", options)
135
135
  end
136
136
  alias :pulls_comments :pull_requests_comments
137
137
  alias :reviews_comments :pull_requests_comments
@@ -12,6 +12,17 @@ module Octokit
12
12
  end
13
13
  alias :search_repos :search_repositories
14
14
 
15
+ # Check if a repository exists
16
+ #
17
+ # @see http://developer.github.com/v3/repos/#get
18
+ # @param repo [String, Hash, Repository] A GitHub repository
19
+ # @return [Hashie::Mash] if a repository exists, false otherwise
20
+ def repository?(repo, options = {})
21
+ repository(repo, options)
22
+ rescue Octokit::NotFound
23
+ false
24
+ end
25
+
15
26
  # Get a single repository
16
27
  #
17
28
  # @see http://developer.github.com/v3/repos/#get
@@ -75,13 +86,14 @@ module Octokit
75
86
  #
76
87
  # @return [Array] List of repositories.
77
88
  def all_repositories(options={})
78
- get '/repositories', options
89
+ get 'repositories', options
79
90
  end
80
91
 
81
92
  # Star a repository
82
93
  #
83
94
  # @param repo [String, Hash, Repository] A GitHub repository
84
95
  # @return [Boolean] `true` if successfully starred
96
+ # @see http://developer.github.com/v3/activity/starring/#star-a-repository
85
97
  def star(repo, options={})
86
98
  boolean_from_response(:put, "user/starred/#{Repository.new repo}", options)
87
99
  end
@@ -90,6 +102,7 @@ module Octokit
90
102
  #
91
103
  # @param repo [String, Hash, Repository] A GitHub repository
92
104
  # @return [Boolean] `true` if successfully unstarred
105
+ # @see http://developer.github.com/v3/activity/starring/#unstar-a-repository
93
106
  def unstar(repo, options={})
94
107
  boolean_from_response(:delete, "user/starred/#{Repository.new repo}", options)
95
108
  end
@@ -99,6 +112,7 @@ module Octokit
99
112
  # @param repo [String, Hash, Repository] A GitHub repository
100
113
  # @return [Boolean] `true` if successfully watched
101
114
  # @deprecated Use #star instead
115
+ # @see http://developer.github.com/v3/activity/watching/#watch-a-repository-legacy
102
116
  def watch(repo, options={})
103
117
  boolean_from_response(:put, "user/watched/#{Repository.new repo}", options)
104
118
  end
@@ -108,6 +122,7 @@ module Octokit
108
122
  # @param repo [String, Hash, Repository] A GitHub repository
109
123
  # @return [Boolean] `true` if successfully unwatched
110
124
  # @deprecated Use #unstar instead
125
+ # @see http://developer.github.com/v3/activity/watching/#stop-watching-a-repository-legacy
111
126
  def unwatch(repo, options={})
112
127
  boolean_from_response(:delete, "user/watched/#{Repository.new repo}", options)
113
128
  end
@@ -116,6 +131,7 @@ module Octokit
116
131
  #
117
132
  # @param repo [String, Hash, Repository] A GitHub repository
118
133
  # @return [Hashie::Mash] Repository info for the new fork
134
+ # @see http://developer.github.com/v3/repos/forks/#create-a-fork
119
135
  def fork(repo, options={})
120
136
  post "repos/#{Repository.new repo}/forks", options
121
137
  end
@@ -479,6 +495,7 @@ module Octokit
479
495
  # events the hook is triggered for.
480
496
  # @option options [Boolean] :active Determines whether the hook is
481
497
  # actually triggered on pushes.
498
+ # @return [Hashie::Mash] Hook info for the new hook
482
499
  # @see Octokit::Client
483
500
  # @see https://api.github.com/hooks
484
501
  # @see https://github.com/github/github-services
@@ -520,6 +537,7 @@ module Octokit
520
537
  # to be removed from the list of events that the Hook triggers for.
521
538
  # @option options [Boolean] :active Determines whether the hook is
522
539
  # actually triggered on pushes.
540
+ # @return [Hashie::Mash] Hook info for the updated hook
523
541
  # @see Octokit::Client
524
542
  # @see https://api.github.com/hooks
525
543
  # @see https://github.com/github/github-services
@@ -0,0 +1,81 @@
1
+ module Octokit
2
+ class Client
3
+ module Stats
4
+
5
+ # Get contributors list with additions, deletions, and commit counts
6
+ #
7
+ # @param repo [String, Hash, Repository] A GitHub repository
8
+ # @return [Array<Hashie::Mash>] Array of contributor stats
9
+ # @see http://developer.github.com/v3/repos/statistics/#get-contributors-list-with-additions-deletions-and-commit-counts
10
+ # @example Get contributor stats for octokit
11
+ # @client.contributors_stats('pengwynn/octokit')
12
+ def contributors_stats(repo)
13
+ get_stats(repo, "contributors")
14
+ end
15
+ alias :contributor_stats :contributors_stats
16
+
17
+ # Get the last year of commit activity data
18
+ #
19
+ # @param repo [String, Hash, Repository] A GitHub repository
20
+ # @return [Array<Hashie::Mash>] The last year of commit activity grouped by
21
+ # week. The days array is a group of commits per day, starting on Sunday.
22
+ # @see http://developer.github.com/v3/repos/statistics/#get-the-last-year-of-commit-activity-data
23
+ # @example Get commit activity for octokit
24
+ # @client.commit_activity_stats('pengwynn/octokit')
25
+ def commit_activity_stats(repo)
26
+ get_stats(repo, "commit_activity")
27
+ end
28
+
29
+ # Get the number of additions and deletions per week
30
+ #
31
+ # @param repo [String, Hash, Repository] A GitHub repository
32
+ # @return [Array<Hashie::Mash>] Weekly aggregate of the number of additions
33
+ # and deletions pushed to a repository.
34
+ # @see http://developer.github.com/v3/repos/statistics/#get-the-number-of-additions-and-deletions-per-week
35
+ # @example Get code frequency stats for octokit
36
+ # @client.code_frequency_stats('pengwynn/octokit')
37
+ def code_frequency_stats(repo)
38
+ get_stats(repo, "code_frequency")
39
+ end
40
+
41
+ # Get the weekly commit count for the repo owner and everyone else
42
+ #
43
+ # @param repo [String, Hash, Repository] A GitHub repository
44
+ # @return [Hashie::Mash] Total commit counts for the owner and total commit
45
+ # counts in all. all is everyone combined, including the owner in the last
46
+ # 52 weeks. If you’d like to get the commit counts for non-owners, you can
47
+ # subtract all from owner.
48
+ # @see http://developer.github.com/v3/repos/statistics/#get-the-weekly-commit-count-for-the-repo-owner-and-everyone-else
49
+ # @example Get weekly commit counts for octokit
50
+ # @client.participation_stats("pengwynn/octokit")
51
+ def participation_stats(repo)
52
+ get_stats(repo, "participation")
53
+ end
54
+
55
+ # Get the number of commits per hour in each day
56
+ #
57
+ # @param repo [String, Hash, Repository] A GitHub repository
58
+ # @return [Array<Array>] Arrays containing the day number, hour number, and
59
+ # number of commits
60
+ # @see http://developer.github.com/v3/repos/statistics/#get-the-number-of-commits-per-hour-in-each-day
61
+ # @example Get octokit punch card
62
+ # @octokit.punch_card_stats
63
+ def punch_card_stats(repo)
64
+ get_stats(repo, "punch_card")
65
+ end
66
+ alias :punch_card :punch_card_stats
67
+
68
+ private
69
+
70
+ # @private Get stats for a repository
71
+ #
72
+ # @param repo [String, Hash, Repository] A GitHub repository
73
+ # @param metric [String] The metrics you are looking for
74
+ # @return [Array<Hashie::Mash>] Magical unicorn stats
75
+ def get_stats(repo, metric)
76
+ get("repos/#{Repository.new repo}/stats/#{metric}")
77
+ end
78
+
79
+ end
80
+ end
81
+ end