github_api 0.15.0 → 0.19.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 (113) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +770 -0
  3. data/README.md +25 -8
  4. data/lib/github_api.rb +37 -76
  5. data/lib/github_api/api.rb +46 -19
  6. data/lib/github_api/api/arguments.rb +6 -1
  7. data/lib/github_api/api/config.rb +3 -5
  8. data/lib/github_api/api/config/property_set.rb +1 -0
  9. data/lib/github_api/authorization.rb +2 -0
  10. data/lib/github_api/client.rb +5 -0
  11. data/lib/github_api/client/activity.rb +2 -0
  12. data/lib/github_api/client/activity/events.rb +2 -0
  13. data/lib/github_api/client/activity/feeds.rb +2 -0
  14. data/lib/github_api/client/activity/notifications.rb +2 -0
  15. data/lib/github_api/client/activity/starring.rb +3 -1
  16. data/lib/github_api/client/activity/watching.rb +3 -1
  17. data/lib/github_api/client/authorizations.rb +2 -0
  18. data/lib/github_api/client/authorizations/app.rb +3 -1
  19. data/lib/github_api/client/emojis.rb +2 -0
  20. data/lib/github_api/client/gists.rb +4 -2
  21. data/lib/github_api/client/gists/comments.rb +3 -1
  22. data/lib/github_api/client/git_data.rb +2 -0
  23. data/lib/github_api/client/git_data/blobs.rb +2 -1
  24. data/lib/github_api/client/git_data/commits.rb +2 -0
  25. data/lib/github_api/client/git_data/references.rb +6 -2
  26. data/lib/github_api/client/git_data/tags.rb +2 -0
  27. data/lib/github_api/client/git_data/trees.rb +2 -0
  28. data/lib/github_api/client/gitignore.rb +2 -0
  29. data/lib/github_api/client/issues.rb +2 -0
  30. data/lib/github_api/client/issues/assignees.rb +35 -0
  31. data/lib/github_api/client/issues/comments.rb +2 -0
  32. data/lib/github_api/client/issues/events.rb +2 -0
  33. data/lib/github_api/client/issues/labels.rb +2 -0
  34. data/lib/github_api/client/issues/milestones.rb +2 -0
  35. data/lib/github_api/client/markdown.rb +4 -2
  36. data/lib/github_api/client/meta.rb +2 -0
  37. data/lib/github_api/client/orgs.rb +6 -0
  38. data/lib/github_api/client/orgs/hooks.rb +2 -0
  39. data/lib/github_api/client/orgs/members.rb +2 -0
  40. data/lib/github_api/client/orgs/memberships.rb +2 -0
  41. data/lib/github_api/client/orgs/projects.rb +57 -0
  42. data/lib/github_api/client/orgs/teams.rb +5 -3
  43. data/lib/github_api/client/projects.rb +83 -0
  44. data/lib/github_api/client/projects/cards.rb +158 -0
  45. data/lib/github_api/client/projects/columns.rb +146 -0
  46. data/lib/github_api/client/pull_requests.rb +2 -0
  47. data/lib/github_api/client/pull_requests/comments.rb +2 -0
  48. data/lib/github_api/client/pull_requests/reviews.rb +2 -0
  49. data/lib/github_api/client/repos.rb +27 -15
  50. data/lib/github_api/client/repos/branches.rb +48 -0
  51. data/lib/github_api/client/repos/branches/protections.rb +75 -0
  52. data/lib/github_api/client/repos/collaborators.rb +2 -1
  53. data/lib/github_api/client/repos/comments.rb +2 -1
  54. data/lib/github_api/client/repos/commits.rb +2 -0
  55. data/lib/github_api/client/repos/contents.rb +26 -4
  56. data/lib/github_api/client/repos/deployments.rb +3 -1
  57. data/lib/github_api/client/repos/downloads.rb +2 -0
  58. data/lib/github_api/client/repos/forks.rb +6 -2
  59. data/lib/github_api/client/repos/hooks.rb +2 -0
  60. data/lib/github_api/client/repos/invitations.rb +41 -0
  61. data/lib/github_api/client/repos/keys.rb +2 -0
  62. data/lib/github_api/client/repos/merging.rb +2 -0
  63. data/lib/github_api/client/repos/pages.rb +2 -0
  64. data/lib/github_api/client/repos/projects.rb +62 -0
  65. data/lib/github_api/client/repos/pub_sub_hubbub.rb +6 -6
  66. data/lib/github_api/client/repos/releases.rb +2 -0
  67. data/lib/github_api/client/repos/releases/assets.rb +3 -1
  68. data/lib/github_api/client/repos/releases/tags.rb +2 -0
  69. data/lib/github_api/client/repos/statistics.rb +2 -0
  70. data/lib/github_api/client/repos/statuses.rb +2 -0
  71. data/lib/github_api/client/say.rb +2 -0
  72. data/lib/github_api/client/scopes.rb +2 -0
  73. data/lib/github_api/client/search.rb +3 -0
  74. data/lib/github_api/client/search/legacy.rb +2 -0
  75. data/lib/github_api/client/users.rb +2 -0
  76. data/lib/github_api/client/users/emails.rb +3 -0
  77. data/lib/github_api/client/users/followers.rb +3 -1
  78. data/lib/github_api/client/users/keys.rb +2 -0
  79. data/lib/github_api/configuration.rb +4 -1
  80. data/lib/github_api/connection.rb +5 -1
  81. data/lib/github_api/error.rb +1 -4
  82. data/lib/github_api/error/client_error.rb +4 -2
  83. data/lib/github_api/error/service_error.rb +9 -2
  84. data/lib/github_api/ext/faraday.rb +3 -1
  85. data/lib/github_api/mash.rb +7 -0
  86. data/lib/github_api/middleware.rb +8 -6
  87. data/lib/github_api/normalizer.rb +3 -5
  88. data/lib/github_api/page_iterator.rb +4 -1
  89. data/lib/github_api/page_links.rb +4 -0
  90. data/lib/github_api/paged_request.rb +2 -0
  91. data/lib/github_api/pagination.rb +10 -7
  92. data/lib/github_api/parameter_filter.rb +4 -1
  93. data/lib/github_api/params_hash.rb +4 -4
  94. data/lib/github_api/request.rb +8 -9
  95. data/lib/github_api/request/basic_auth.rb +1 -1
  96. data/lib/github_api/request/jsonize.rb +0 -1
  97. data/lib/github_api/request/oauth2.rb +2 -0
  98. data/lib/github_api/request/verbs.rb +3 -0
  99. data/lib/github_api/response/follow_redirects.rb +140 -0
  100. data/lib/github_api/response/header.rb +6 -1
  101. data/lib/github_api/response/mashify.rb +2 -3
  102. data/lib/github_api/response/raise_error.rb +2 -1
  103. data/lib/github_api/response_wrapper.rb +5 -0
  104. data/lib/github_api/utils/url.rb +2 -0
  105. data/lib/github_api/validations.rb +5 -8
  106. data/lib/github_api/validations/format.rb +2 -0
  107. data/lib/github_api/validations/presence.rb +3 -1
  108. data/lib/github_api/validations/required.rb +2 -0
  109. data/lib/github_api/version.rb +2 -2
  110. metadata +100 -36
  111. data/lib/github_api/core_ext/ordered_hash.rb +0 -107
  112. data/lib/github_api/requestable.rb +0 -67
  113. data/lib/github_api/resource.rb +0 -13
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../api'
4
+
5
+ module Github
6
+ class Client::Repos::Branches < API
7
+ require_all 'github_api/client/repos/branches', 'protections'
8
+
9
+ # Access to Repos::Branches::Protections API
10
+ namespace :protections
11
+
12
+ # List branches
13
+ #
14
+ # @example
15
+ # github = Github.new
16
+ # github.repos.branches.list 'user-name', 'repo-name'
17
+ # github.repos(user: 'user-name', repo: 'repo-name').branches.list
18
+ #
19
+ # @example
20
+ # repos = Github::Repos.new
21
+ # repos.branches.list 'user-name', 'repo-name'
22
+ #
23
+ # @api public
24
+ def list(*args)
25
+ arguments(args, required: [:user, :repo])
26
+
27
+ response = get_request("/repos/#{arguments.user}/#{arguments.repo}/branches", arguments.params)
28
+ return response unless block_given?
29
+ response.each { |el| yield el }
30
+ end
31
+ alias :all :list
32
+
33
+ # Get branch
34
+ #
35
+ # @example
36
+ # github = Github.new
37
+ # github.repos.branches.get 'user-name', 'repo-name', 'branch-name'
38
+ # github.repos.branches.get user: 'user-name', repo: 'repo-name', branch: 'branch-name'
39
+ # github.repos(user: 'user-name', repo: 'repo-name', branch: 'branch-name').branches.get
40
+ # @api public
41
+ def get(*args)
42
+ arguments(args, required: [:user, :repo, :branch])
43
+
44
+ get_request("/repos/#{arguments.user}/#{arguments.repo}/branches/#{arguments.branch}", arguments.params)
45
+ end
46
+ alias :find :get
47
+ end # Client::Repos::Branches
48
+ end # Github
@@ -0,0 +1,75 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../../api'
4
+
5
+ module Github
6
+ # The Branch Protections API
7
+ class Client::Repos::Branches::Protections < API
8
+ VALID_PROTECTION_PARAM_NAMES = %w[
9
+ required_status_checks
10
+ required_pull_request_reviews
11
+ enforce_admins
12
+ restrictions
13
+ accept
14
+ ].freeze
15
+
16
+ # Get a single branch's protection
17
+ #
18
+ # @example
19
+ # github = Github.new
20
+ # github.repos.branches.protections.get 'user', 'repo', 'branch'
21
+ #
22
+ # @api public
23
+ def get(*args)
24
+ arguments(args, required: [:user, :repo, :branch])
25
+
26
+ get_request("/repos/#{arguments.user}/#{arguments.repo}/branches/#{arguments.branch}/protection", arguments.params)
27
+ end
28
+ alias :find :get
29
+
30
+ # Edit a branch protection
31
+ #
32
+ # Users with push access to the repository can edit a branch protection.
33
+ #
34
+ # @param [Hash] params
35
+ # @input params [String] :required_status_checks
36
+ # Required.
37
+ # @input params [String] :enforce_admins
38
+ # Required.
39
+ # @input params [String] :restrictions
40
+ # Required.
41
+ # @input params [String] :required_pull_request_reviews
42
+ # Required.
43
+ # Look to the branch protection API to see how to use these
44
+ # https://developer.github.com/v3/repos/branches/#update-branch-protection
45
+ #
46
+ # @example
47
+ # github = Github.new
48
+ # github.repos.branches.protections.edit 'user', 'repo', 'branch',
49
+ # required_pull_request_reviews: {dismiss_stale_reviews: false}
50
+ #
51
+ # @api public
52
+ def edit(*args)
53
+ arguments(args, required: [:user, :repo, :branch]) do
54
+ permit VALID_PROTECTION_PARAM_NAMES
55
+ end
56
+
57
+ put_request("/repos/#{arguments.user}/#{arguments.repo}/branches/#{arguments.branch}/protection", arguments.params)
58
+ end
59
+ alias :update :edit
60
+
61
+ # Delete a branch protection
62
+ #
63
+ # @example
64
+ # github = Github.new
65
+ # github.repos.branches.protections.delete 'user', 'repo', 'branch'
66
+ #
67
+ # @api public
68
+ def delete(*args)
69
+ arguments(args, required: [:user, :repo, :branch])
70
+
71
+ delete_request("/repos/#{arguments.user}/#{arguments.repo}/branches/#{arguments.branch}/protection", arguments.params)
72
+ end
73
+ alias :remove :delete
74
+ end # Client::Repos::Branches::Protections
75
+ end # Github
@@ -1,5 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require_relative '../../api'
4
+
3
5
  module Github
4
6
  class Client::Repos::Collaborators < API
5
7
  # List collaborators
@@ -21,7 +23,6 @@ module Github
21
23
  # @api public
22
24
  def list(*args)
23
25
  arguments(args, required: [:user, :repo])
24
- params = arguments.params
25
26
 
26
27
  response = get_request("/repos/#{arguments.user}/#{arguments.repo}/collaborators", arguments.params)
27
28
  return response unless block_given?
@@ -1,5 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require_relative '../../api'
4
+
3
5
  module Github
4
6
  class Client::Repos::Comments < API
5
7
 
@@ -81,7 +83,6 @@ module Github
81
83
  # @api public
82
84
  def create(*args)
83
85
  arguments(args, required: [:user, :repo, :sha]) do
84
- permit VALID_COMMENT_OPTIONS
85
86
  assert_required REQUIRED_COMMENT_OPTIONS
86
87
  end
87
88
 
@@ -1,5 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require_relative '../../api'
4
+
3
5
  module Github
4
6
  class Client::Repos::Commits < API
5
7
 
@@ -1,5 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require_relative '../../api'
4
+
3
5
  module Github
4
6
  # These API methods let you retrieve the contents of files within a repository
5
7
  # as Base64 encoded content.
@@ -31,6 +33,23 @@ module Github
31
33
  get_request("/repos/#{arguments.user}/#{arguments.repo}/readme", arguments.params)
32
34
  end
33
35
 
36
+ # Get the LICENSE
37
+ #
38
+ # This method returns the contents of the repository's license file, if one is detected.
39
+ #
40
+ # @param [Hash] params
41
+ #
42
+ # @example
43
+ # github = Github.new
44
+ # github.repos.contents.license 'user-name', 'repo-name'
45
+ #
46
+ # @api public
47
+ def license(*args)
48
+ arguments(args, required: [:user, :repo])
49
+
50
+ get_request("/repos/#{arguments.user}/#{arguments.repo}/license", arguments.params)
51
+ end
52
+
34
53
  # Get contents
35
54
  #
36
55
  # This method returns the contents of any file or directory in a repository.
@@ -64,12 +83,12 @@ module Github
64
83
  #
65
84
  # @param [Hash] params
66
85
  # @option params [String] :path
67
- # Requried string. The content path
86
+ # Required string. The content path
68
87
  # @option params [String]
69
88
  # @option params [String] :message
70
- # Requried string. The commit message.
89
+ # Required string. The commit message.
71
90
  # @option params [String] :content
72
- # Requried string. The new file content, which will be Base64 encoded
91
+ # Required string. The new file content, which will be Base64 encoded
73
92
  # @option params [String] :branch
74
93
  # The branch name. If not provided, uses the repository’s
75
94
  # default branch (usually master)
@@ -235,7 +254,10 @@ module Github
235
254
  archive_format = params.delete('archive_format') || 'tarball'
236
255
  ref = params.delete('ref') || 'master'
237
256
 
238
- get_request("/repos/#{arguments.user}/#{arguments.repo}/#{archive_format}/#{ref}", params)
257
+ disable_redirects do
258
+ response = get_request("/repos/#{arguments.user}/#{arguments.repo}/#{archive_format}/#{ref}", params)
259
+ response.headers.location
260
+ end
239
261
  end
240
262
  end # Client::Repos::Contents
241
263
  end # Github
@@ -1,5 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require_relative '../../api'
4
+
3
5
  module Github
4
6
  class Client::Repos::Deployments < API
5
7
 
@@ -22,7 +24,7 @@ module Github
22
24
 
23
25
  # List deployments on a repository
24
26
  #
25
- # @xample
27
+ # @example
26
28
  # github = Github.new
27
29
  # github.repos.deployments.list 'user-name', 'repo-name'
28
30
  # github.repos.deployments.list 'user-name', 'repo-name' { |deployment| ... }
@@ -1,5 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require_relative '../../api'
4
+
3
5
  module Github
4
6
  class Client::Repos::Downloads < API
5
7
 
@@ -1,5 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require_relative '../../api'
4
+
3
5
  module Github
4
6
  class Client::Repos::Forks < API
5
7
  # List repository forks
@@ -11,8 +13,10 @@ module Github
11
13
  #
12
14
  # @example
13
15
  # github = Github.new
14
- # github.repos.forks.list 'user-name', 'repo-name'
15
- # github.repos.forks.list 'user-name', 'repo-name' { |fork| ... }
16
+ # github.repos.forks.list('user-name', 'repo-name')
17
+ # github.repos.forks.list('user-name', 'repo-name') { |fork|
18
+ # #...
19
+ # }
16
20
  #
17
21
  # @api public
18
22
  def list(*args)
@@ -1,5 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require_relative '../../api'
4
+
3
5
  module Github
4
6
  # The Repository Hooks API manages the post-receive web and
5
7
  # service hooks for a repository.
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../api'
4
+
5
+ module Github
6
+ class Client::Repos::Invitations < API
7
+ # List repo invitations
8
+ #
9
+ # @example
10
+ # github = Github.new
11
+ # github.repos.invitations.list 'user-name', 'repo-name'
12
+ #
13
+ # @example
14
+ # github.repos.invitations.list 'user-name', 'repo-name' { |cbr| .. }
15
+ #
16
+ # @return [Array]
17
+ #
18
+ # @api public
19
+ def list(*args)
20
+ arguments(args, required: [:user, :repo])
21
+
22
+ response = get_request("/repos/#{arguments.user}/#{arguments.repo}/invitations", arguments.params)
23
+ return response unless block_given?
24
+ response.each { |el| yield el }
25
+ end
26
+ alias :all :list
27
+
28
+ # Deletes a repo invitation
29
+ #
30
+ # @example
31
+ # github = Github.new
32
+ # github.repos.invitations.delete 'user-name', 'repo-name', 'invitation-id'
33
+ #
34
+ # @api public
35
+ def delete(*args)
36
+ arguments(args, required: [:user, :repo, :id])
37
+
38
+ delete_request("/repos/#{arguments.user}/#{arguments.repo}/invitations/#{arguments.id}", arguments.params)
39
+ end
40
+ end
41
+ end
@@ -1,5 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require_relative '../../api'
4
+
3
5
  module Github
4
6
  class Client::Repos::Keys < API
5
7
  # List deploy keys
@@ -1,5 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require_relative '../../api'
4
+
3
5
  module Github
4
6
  # The Repo Merging API supports merging branches in a repository. This
5
7
  # accomplishes essentially the same thing as merging one branch into another
@@ -1,5 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require_relative '../../api'
4
+
3
5
  module Github
4
6
  # The Pages API retrieves information about your GitHub Pages configuration,
5
7
  # and the statuses of your builds. Information about the site and the builds
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../api'
4
+
5
+ module Github
6
+ class Client::Repos::Projects < API
7
+ PREVIEW_MEDIA = "application/vnd.github.inertia-preview+json".freeze # :nodoc:
8
+
9
+ # List a repo's projects
10
+ #
11
+ # @example
12
+ # github = Github.new
13
+ # github.repos.projects.list owner: 'owner-name', repo: 'repo-name'
14
+ #
15
+ # @example
16
+ # github = Github.new
17
+ # github.repos.projects.list state: 'open', owner: 'owner-name', repo: 'repo-name'
18
+ #
19
+ # @example
20
+ # github.repos.projects.list owner: 'owner-name', repo: 'repo-name' { |cbr| .. }
21
+ #
22
+ # @return [Array]
23
+ #
24
+ # @api public
25
+ def list(*args)
26
+ arguments(args, required: [:owner, :repo])
27
+ params = arguments.params
28
+
29
+ params["accept"] ||= PREVIEW_MEDIA
30
+
31
+ response = get_request("/repos/#{arguments.owner}/#{arguments.repo}/projects", params)
32
+ return response unless block_given?
33
+ response.each { |el| yield el }
34
+ end
35
+ alias :all :list
36
+
37
+ # Create a new project for the specified repo
38
+ #
39
+ # @param [Hash] params
40
+ # @option params [String] :name
41
+ # Required string - The name of the project.
42
+ # @option params [String] :body
43
+ # Optional string - The body of the project.
44
+ #
45
+ # @example
46
+ # github = Github.new
47
+ # github.repos.projects.create 'owner-name', 'repo-name', name: 'project-name'
48
+ # github.repos.projects.create name: 'project-name', body: 'project-body', owner: 'owner-name', repo: 'repo-name'
49
+ #
50
+ # @api public
51
+ def create(*args)
52
+ arguments(args, required: [:owner, :repo]) do
53
+ assert_required %w[ name ]
54
+ end
55
+ params = arguments.params
56
+
57
+ params["accept"] ||= PREVIEW_MEDIA
58
+
59
+ post_request("/repos/#{arguments.owner}/#{arguments.repo}/projects", params)
60
+ end
61
+ end # Projects
62
+ end # Github
@@ -1,11 +1,11 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require_relative '../../api'
4
+
3
5
  module Github
4
6
  class Client::Repos::PubSubHubbub < API
5
- OPTIONS = {
6
- :headers => {
7
- CONTENT_TYPE => 'application/x-www-form-urlencoded'
8
- }
7
+ HEADERS = {
8
+ CONTENT_TYPE => 'application/x-www-form-urlencoded'
9
9
  }
10
10
 
11
11
  # Subscribe to existing topic/event through pubsubhubbub
@@ -29,7 +29,7 @@ module Github
29
29
  def subscribe(*args)
30
30
  params = arguments(args, required: [:topic, :callback]).params
31
31
  _merge_action!("subscribe", arguments.topic, arguments.callback, params)
32
- params['options'] = OPTIONS
32
+ params['headers'] = HEADERS
33
33
 
34
34
  post_request("/hub", params)
35
35
  end
@@ -56,7 +56,7 @@ module Github
56
56
  def unsubscribe(*args)
57
57
  params = arguments(args, required: [:topic, :callback]).params
58
58
  _merge_action!("unsubscribe", arguments.topic, arguments.callback, params)
59
- params['options'] = OPTIONS
59
+ params['headers'] = HEADERS
60
60
 
61
61
  post_request("/hub", params)
62
62
  end