github_api 0.6.5 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/features/cassettes/{repos → issues}/assignees/ckeck.yml +0 -0
  2. data/features/cassettes/{repos → issues}/assignees/ckeck_not.yml +0 -0
  3. data/features/cassettes/{repos → issues}/assignees/list.yml +0 -0
  4. data/features/cassettes/repos/starring/list.yml +98 -0
  5. data/features/cassettes/repos/starring/star.yml +48 -0
  6. data/features/cassettes/repos/starring/starred.yml +195 -0
  7. data/features/cassettes/repos/starring/starring.yml +56 -0
  8. data/features/cassettes/repos/starring/unstar.yml +46 -0
  9. data/features/cassettes/repos/statuses/create.yml +52 -0
  10. data/features/cassettes/repos/statuses/list.yml +64 -0
  11. data/features/cassettes/repos/watching/list.yml +76 -0
  12. data/features/cassettes/repos/watching/unwatch.yml +46 -0
  13. data/features/cassettes/repos/watching/watch.yml +48 -0
  14. data/features/cassettes/repos/watching/watched.yml +166 -0
  15. data/features/cassettes/repos/watching/watching.yml +56 -0
  16. data/features/{repos → issues}/assignees.feature +5 -5
  17. data/features/repos/starring.feature +50 -0
  18. data/features/repos/statuses.feature +27 -0
  19. data/features/repos/watching.feature +50 -0
  20. data/lib/github_api/error/service_error.rb +5 -2
  21. data/lib/github_api/issues.rb +6 -0
  22. data/lib/github_api/{repos → issues}/assignees.rb +2 -2
  23. data/lib/github_api/jsonable.rb +17 -0
  24. data/lib/github_api/orgs/teams.rb +45 -45
  25. data/lib/github_api/repos.rb +23 -11
  26. data/lib/github_api/repos/commits.rb +4 -3
  27. data/lib/github_api/repos/merging.rb +40 -0
  28. data/lib/github_api/repos/starring.rb +97 -0
  29. data/lib/github_api/repos/statuses.rb +64 -0
  30. data/lib/github_api/repos/watching.rb +16 -13
  31. data/lib/github_api/response.rb +1 -0
  32. data/lib/github_api/response/jsonize.rb +4 -5
  33. data/lib/github_api/version.rb +2 -2
  34. data/spec/fixtures/repos/merge.json +48 -0
  35. data/spec/fixtures/repos/stargazers.json +9 -0
  36. data/spec/fixtures/repos/starred.json +34 -0
  37. data/spec/fixtures/repos/status.json +16 -0
  38. data/spec/fixtures/repos/statuses.json +18 -0
  39. data/spec/github/{repos → issues}/assignees_spec.rb +2 -2
  40. data/spec/github/repos/merging_spec.rb +71 -0
  41. data/spec/github/repos/starring_spec.rb +203 -0
  42. data/spec/github/repos/statuses_spec.rb +124 -0
  43. data/spec/github/repos/watching_spec.rb +37 -35
  44. metadata +66 -39
@@ -6,7 +6,6 @@ module Github
6
6
 
7
7
  # Load all the modules after initializing Repos to avoid superclass mismatch
8
8
  autoload_all 'github_api/repos',
9
- :Assignees => 'assignees',
10
9
  :Collaborators => 'collaborators',
11
10
  :Commits => 'commits',
12
11
  :Contents => 'contents',
@@ -14,8 +13,11 @@ module Github
14
13
  :Forks => 'forks',
15
14
  :Hooks => 'hooks',
16
15
  :Keys => 'keys',
17
- :Watching => 'watching',
18
- :PubSubHubbub => 'pub_sub_hubbub'
16
+ :Merging => 'merging',
17
+ :PubSubHubbub => 'pub_sub_hubbub',
18
+ :Starring => 'starring',
19
+ :Statuses => 'statuses',
20
+ :Watching => 'watching'
19
21
 
20
22
  DEFAULT_REPO_OPTIONS = {
21
23
  "homepage" => "https://github.com",
@@ -43,11 +45,6 @@ module Github
43
45
  super(options)
44
46
  end
45
47
 
46
- # Access to Repos::Collaborators API
47
- def assignees
48
- @assignees ||= ApiFactory.new 'Repos::Assignees'
49
- end
50
-
51
48
  # Access to Repos::Collaborators API
52
49
  def collaborators
53
50
  @collaborators ||= ApiFactory.new 'Repos::Collaborators'
@@ -83,9 +80,9 @@ module Github
83
80
  @keys ||= ApiFactory.new 'Repos::Keys'
84
81
  end
85
82
 
86
- # Access to Repos::Watchin API
87
- def watching
88
- @watching ||= ApiFactory.new 'Repos::Watching'
83
+ # Access to Repos::Merging API
84
+ def merging
85
+ @mergin ||= ApiFactory.new 'Repos::Merging'
89
86
  end
90
87
 
91
88
  # Access to Repos::Watchin API
@@ -93,6 +90,21 @@ module Github
93
90
  @pubsubhubbub ||= ApiFactory.new 'Repos::PubSubHubbub'
94
91
  end
95
92
 
93
+ # Access to Repos::Starring API
94
+ def starring
95
+ @starring ||= ApiFactory.new 'Repos::Starring'
96
+ end
97
+
98
+ # Access to Repos::Statuses API
99
+ def statuses
100
+ @statuses ||= ApiFactory.new 'Repos::Statuses'
101
+ end
102
+
103
+ # Access to Repos::Watching API
104
+ def watching
105
+ @watching ||= ApiFactory.new 'Repos::Watching'
106
+ end
107
+
96
108
  # List branches
97
109
  #
98
110
  # = Examples
@@ -77,8 +77,9 @@ module Github
77
77
  # List commits on a repository
78
78
  #
79
79
  # = Parameters
80
- # * <tt>:sha</tt> Optional string. Sha or branch to start listing commits from.
81
- # * <tt>:path</tt> Optional string. Only commits containing this file path will be returned
80
+ # * <tt>:sha</tt> Optional string. Sha or branch to start listing commits from.
81
+ # * <tt>:path</tt> Optional string. Only commits containing this file path will be returned.
82
+ # * <tt>:author</tt> GitHub login, name, or email by which to filter by commit author.
82
83
  #
83
84
  # = Examples
84
85
  # github = Github.new
@@ -89,7 +90,7 @@ module Github
89
90
  _update_user_repo_params(user_name, repo_name)
90
91
  _validate_user_repo_params(user, repo) unless user? && repo?
91
92
  normalize! params
92
- filter! %w[ sha path], params
93
+ filter! %w[sha path author], params
93
94
 
94
95
  response = get_request("/repos/#{user}/#{repo}/commits", params)
95
96
  return response unless block_given?
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ # The Repo Merging API supports merging branches in a repository. This
5
+ # accomplishes essentially the same thing as merging one branch into another
6
+ # in a local repository and then pushing to GitHub.
7
+ class Repos::Merging < API
8
+
9
+ VALID_MERGE_PARAM_NAMES = %w[
10
+ base
11
+ head
12
+ commit_message
13
+ ].freeze # :nodoc:
14
+
15
+ REQUIRED_MERGE_PARAMS = %w[ base head ].freeze # :nodoc:
16
+
17
+ # Perform a merge
18
+ #
19
+ # = Inputs
20
+ # * <tt>:base</tt> - Required String - The name of the base branch that the head will be merged into.
21
+ # * <tt>:head</tt> - Required String - The head to merge. This can be a branch name or a commit SHA1.
22
+ # * <tt>:commit_message</tt> - Optional String - Commit message to use for the merge commit. If omitted, a default message will be used.
23
+ #
24
+ # = Examples
25
+ # github = Github.new
26
+ # github.repos.merging.merge 'user', 'repo',
27
+ # "base": "master",
28
+ # "head": "cool_feature",
29
+ # "commit_message": "Shipped cool_feature!"
30
+ #
31
+ def merge(user_name, repo_name, params={})
32
+ normalize! params
33
+ filter! VALID_MERGE_PARAM_NAMES, params
34
+ assert_required_keys REQUIRED_MERGE_PARAMS, params
35
+
36
+ post_request("/repos/#{user_name}/#{repo_name}/merges", params)
37
+ end
38
+
39
+ end # Repos::Merging
40
+ end # Github
@@ -0,0 +1,97 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ # Repository Starring is a feature that lets users bookmark repositories.
5
+ # Stars are shown next to repositories to show an approximate level of interest. # Stars have no effect on notifications or the activity feed.
6
+ class Repos::Starring < API
7
+
8
+ # List stargazers
9
+ #
10
+ # = Examples
11
+ # github = Github.new :user => 'user-name', :repo => 'repo-name'
12
+ # github.repos.starring.list
13
+ # github.repos.starring.list { |star| ... }
14
+ #
15
+ def list(user_name, repo_name, params={})
16
+ _update_user_repo_params(user_name, repo_name)
17
+ _validate_user_repo_params(user, repo) unless user? && repo?
18
+ normalize! params
19
+
20
+ response = get_request("/repos/#{user}/#{repo}/stargazers", params)
21
+ return response unless block_given?
22
+ response.each { |el| yield el }
23
+ end
24
+ alias :all :list
25
+
26
+ # List repos being starred by a user
27
+ #
28
+ # = Examples
29
+ # github = Github.new
30
+ # github.repos.starring.starred :user => 'user-name'
31
+ #
32
+ # List repos being starred by the authenticated user
33
+ #
34
+ # = Examples
35
+ # github = Github.new :oauth_token => '...'
36
+ # github.repos.starring.starred
37
+ #
38
+ def starred(*args)
39
+ params = args.extract_options!
40
+ normalize! params
41
+
42
+ response = if (user_name = params.delete('user'))
43
+ get_request("/users/#{user_name}/starred", params)
44
+ else
45
+ get_request("/user/starred", params)
46
+ end
47
+ return response unless block_given?
48
+ response.each { |el| yield el }
49
+ end
50
+
51
+ # Check if you are starring a repository
52
+ #
53
+ # Returns <tt>true</tt> if this repo is starred by you,<tt>false</tt> otherwise
54
+ #
55
+ # = Examples
56
+ # github = Github.new
57
+ # github.repos.starring.starring? 'user-name', 'repo-name'
58
+ #
59
+ def starring?(user_name, repo_name, params={})
60
+ _validate_presence_of user_name, repo_name
61
+ normalize! params
62
+ get_request("/user/starred/#{user_name}/#{repo_name}", params)
63
+ true
64
+ rescue Github::Error::NotFound
65
+ false
66
+ end
67
+
68
+ # Star a repository
69
+ #
70
+ # You need to be authenticated to star a repository
71
+ #
72
+ # = Examples
73
+ # github = Github.new
74
+ # github.repos.starring.star 'user-name', 'repo-name'
75
+ #
76
+ def star(user_name, repo_name, params={})
77
+ _validate_presence_of user_name, repo_name
78
+ normalize! params
79
+ put_request("/user/starred/#{user_name}/#{repo_name}", params)
80
+ end
81
+
82
+ # Unstar a repository
83
+ #
84
+ # You need to be authenticated to unstar a repository.
85
+ #
86
+ # = Examples
87
+ # github = Github.new
88
+ # github.repos.starring.unstar 'user-name', 'repo-name'
89
+ #
90
+ def unstar(user_name, repo_name, params={})
91
+ _validate_presence_of user_name, repo_name
92
+ normalize! params
93
+ delete_request("/user/starred/#{user_name}/#{repo_name}", params)
94
+ end
95
+
96
+ end # Repos::Starring
97
+ end # Github
@@ -0,0 +1,64 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ class Repos::Statuses < API
5
+ # The Status API allows external services to mark commits with a success,
6
+ # failure, error, or pending state, which is then reflected in pull requests
7
+ # involving those commits.
8
+
9
+ VALID_STATUS_PARAM_NAMES = %w[
10
+ state
11
+ target_url
12
+ description
13
+ ].freeze # :nodoc:
14
+
15
+ REQUIRED_PARAMS = %w[ state ].freeze # :nodoc:
16
+
17
+ # List Statuses for a specific SHA
18
+ #
19
+ # = Examples
20
+ # github = Github.new
21
+ # github.repos.statuses.list 'user-name', 'repo-name', 'sha'
22
+ # github.repos.statuses.list 'user-name', 'repo-name', 'sha' { |status| ... }
23
+ #
24
+ def list(user_name, repo_name, sha, params={})
25
+ _update_user_repo_params(user_name, repo_name)
26
+ _validate_user_repo_params(user, repo) unless user? && repo?
27
+ normalize! params
28
+
29
+ response = get_request("/repos/#{user}/#{repo}/statuses/#{sha}", params)
30
+ return response unless block_given?
31
+ response.each { |el| yield el }
32
+ end
33
+ alias :all :list
34
+
35
+ # Create a status
36
+ #
37
+ # = Inputs
38
+ # * <tt>:state</tt> - Required string - State of the status - can be one of
39
+ # pending, success, error, or failure.
40
+ # * <tt>:target_url</tt> - Optional string - Target url to associate with this
41
+ # status. This URL will be linked from the GitHub UI to allow users
42
+ # to easily see the ‘source’ of the Status.
43
+ # * <tt>:description</tt> - Optional string - Short description of the status
44
+ #
45
+ # = Examples
46
+ # github = Github.new
47
+ # github.repos.statuses.create 'user-name', 'repo-name', 'sha',
48
+ # "state" => "success",
49
+ # "target_url" => "http://ci.example.com/johndoe/my-repo/builds/sha",
50
+ # "description" => "Successful build #3 from origin/master"
51
+ #
52
+ def create(user_name, repo_name, sha, params={})
53
+ _update_user_repo_params(user_name, repo_name)
54
+ _validate_user_repo_params(user, repo) unless user? && repo?
55
+
56
+ normalize! params
57
+ filter! VALID_STATUS_PARAM_NAMES, params, :recursive => false
58
+ assert_required_keys(REQUIRED_PARAMS, params)
59
+
60
+ post_request("/repos/#{user}/#{repo}/statuses/#{sha}", params)
61
+ end
62
+
63
+ end # Repos::Statuses
64
+ end # Github
@@ -1,24 +1,27 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Github
4
+ # Watching a Repository registers the user to receive notificactions on new
5
+ # discussions, as well as events in the user’s activity feed.
4
6
  class Repos::Watching < API
5
7
 
6
8
  # List repo watchers
7
9
  #
8
10
  # = Examples
9
11
  # github = Github.new :user => 'user-name', :repo => 'repo-name'
10
- # github.repos.watching.watchers
11
- # github.repos.watching.watchers { |watcher| ... }
12
+ # github.repos.watching.list
13
+ # github.repos.watching.list { |watcher| ... }
12
14
  #
13
- def watchers(user_name, repo_name, params={})
15
+ def list(user_name, repo_name, params={})
14
16
  _update_user_repo_params(user_name, repo_name)
15
17
  _validate_user_repo_params(user, repo) unless user? && repo?
16
18
  normalize! params
17
19
 
18
- response = get_request("/repos/#{user}/#{repo}/watchers", params)
20
+ response = get_request("/repos/#{user}/#{repo}/subscribers", params)
19
21
  return response unless block_given?
20
22
  response.each { |el| yield el }
21
23
  end
24
+ alias :all :list
22
25
 
23
26
  # List repos being watched by a user
24
27
  #
@@ -37,9 +40,9 @@ module Github
37
40
  normalize! params
38
41
 
39
42
  response = if (user_name = params.delete('user'))
40
- get_request("/users/#{user_name}/watched", params)
43
+ get_request("/users/#{user_name}/subscriptions", params)
41
44
  else
42
- get_request("/user/watched", params)
45
+ get_request("/user/subscriptions", params)
43
46
  end
44
47
  return response unless block_given?
45
48
  response.each { |el| yield el }
@@ -55,7 +58,7 @@ module Github
55
58
  def watching?(user_name, repo_name, params={})
56
59
  _validate_presence_of user_name, repo_name
57
60
  normalize! params
58
- get_request("/user/watched/#{user_name}/#{repo_name}", params)
61
+ get_request("/user/subscriptions/#{user_name}/#{repo_name}", params)
59
62
  true
60
63
  rescue Github::Error::NotFound
61
64
  false
@@ -67,12 +70,12 @@ module Github
67
70
  #
68
71
  # = Examples
69
72
  # github = Github.new
70
- # github.repos.watching.start_watching 'user-name', 'repo-name'
73
+ # github.repos.watching.watch 'user-name', 'repo-name'
71
74
  #
72
- def start_watching(user_name, repo_name, params={})
75
+ def watch(user_name, repo_name, params={})
73
76
  _validate_presence_of user_name, repo_name
74
77
  normalize! params
75
- put_request("/user/watched/#{user_name}/#{repo_name}", params)
78
+ put_request("/user/subscriptions/#{user_name}/#{repo_name}", params)
76
79
  end
77
80
 
78
81
  # Stop watching a repository
@@ -80,12 +83,12 @@ module Github
80
83
  # You need to be authenticated to stop watching a repository.
81
84
  # = Examples
82
85
  # github = Github.new
83
- # github.repos.watching.start_watching 'user-name', 'repo-name'
86
+ # github.repos.watching.unwatch 'user-name', 'repo-name'
84
87
  #
85
- def stop_watching(user_name, repo_name, params={})
88
+ def unwatch(user_name, repo_name, params={})
86
89
  _validate_presence_of user_name, repo_name
87
90
  normalize! params
88
- delete_request("/user/watched/#{user_name}/#{repo_name}", params)
91
+ delete_request("/user/subscriptions/#{user_name}/#{repo_name}", params)
89
92
  end
90
93
 
91
94
  end # Repos::Watching
@@ -6,6 +6,7 @@ module Github
6
6
  # Contains methods and attributes that act on the response returned from the
7
7
  # request
8
8
  class Response < Faraday::Response::Middleware
9
+
9
10
  CONTENT_TYPE = 'Content-Type'.freeze
10
11
 
11
12
  class << self
@@ -1,17 +1,16 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'faraday'
4
+ require 'github_api/jsonable'
4
5
 
5
6
  module Github
6
7
  class Response::Jsonize < Response
8
+ include Github::Jsonable
9
+
7
10
  dependency 'multi_json'
8
11
 
9
12
  define_parser do |body|
10
- if MultiJson.respond_to?(:load)
11
- MultiJson.load body
12
- else
13
- MultiJson.decode body
14
- end
13
+ Github::Jsonable.decode body
15
14
  end
16
15
 
17
16
  def parse(body)
@@ -3,8 +3,8 @@
3
3
  module Github
4
4
  module VERSION
5
5
  MAJOR = 0
6
- MINOR = 6
7
- PATCH = 5
6
+ MINOR = 7
7
+ PATCH = 0
8
8
  BUILD = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.');
@@ -0,0 +1,48 @@
1
+ {
2
+ "commit": {
3
+ "sha": "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d",
4
+ "commit": {
5
+ "author": {
6
+ "name": "The Octocat",
7
+ "date": "2012-03-06T15:06:50-08:00",
8
+ "email": "octocat@nowhere.com"
9
+ },
10
+ "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/7fd1a60b01f91b314f59955a4e4d4e80d8edf11d",
11
+ "message": "Shipped cool_feature!",
12
+ "tree": {
13
+ "sha": "b4eecafa9be2f2006ce1b709d6857b07069b4608",
14
+ "url": "https://api.github.com/repos/octocat/Hello-World/git/trees/b4eecafa9be2f2006ce1b709d6857b07069b4608"
15
+ },
16
+ "committer": {
17
+ "name": "The Octocat",
18
+ "date": "2012-03-06T15:06:50-08:00",
19
+ "email": "octocat@nowhere.com"
20
+ }
21
+ },
22
+ "author": {
23
+ "gravatar_id": "7ad39074b0584bc555d0417ae3e7d974",
24
+ "avatar_url": "https://secure.gravatar.com/avatar/7ad39074b0584bc555d0417ae3e7d974?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
25
+ "url": "https://api.github.com/users/octocat",
26
+ "id": 583231,
27
+ "login": "octocat"
28
+ },
29
+ "parents": [
30
+ {
31
+ "sha": "553c2077f0edc3d5dc5d17262f6aa498e69d6f8e",
32
+ "url": "https://api.github.com/repos/octocat/Hello-World/commits/553c2077f0edc3d5dc5d17262f6aa498e69d6f8e"
33
+ },
34
+ {
35
+ "sha": "762941318ee16e59dabbacb1b4049eec22f0d303",
36
+ "url": "https://api.github.com/repos/octocat/Hello-World/commits/762941318ee16e59dabbacb1b4049eec22f0d303"
37
+ }
38
+ ],
39
+ "url": "https://api.github.com/repos/octocat/Hello-World/commits/7fd1a60b01f91b314f59955a4e4d4e80d8edf11d",
40
+ "committer": {
41
+ "gravatar_id": "7ad39074b0584bc555d0417ae3e7d974",
42
+ "avatar_url": "https://secure.gravatar.com/avatar/7ad39074b0584bc555d0417ae3e7d974?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
43
+ "url": "https://api.github.com/users/octocat",
44
+ "id": 583231,
45
+ "login": "octocat"
46
+ }
47
+ }
48
+ }