lingfennan-github_api 0.18.2

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 (126) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +20 -0
  3. data/README.md +741 -0
  4. data/lib/github_api.rb +93 -0
  5. data/lib/github_api/api.rb +398 -0
  6. data/lib/github_api/api/actions.rb +60 -0
  7. data/lib/github_api/api/arguments.rb +253 -0
  8. data/lib/github_api/api/config.rb +105 -0
  9. data/lib/github_api/api/config/property.rb +30 -0
  10. data/lib/github_api/api/config/property_set.rb +120 -0
  11. data/lib/github_api/api/factory.rb +33 -0
  12. data/lib/github_api/authorization.rb +75 -0
  13. data/lib/github_api/client.rb +77 -0
  14. data/lib/github_api/client/activity.rb +31 -0
  15. data/lib/github_api/client/activity/events.rb +233 -0
  16. data/lib/github_api/client/activity/feeds.rb +50 -0
  17. data/lib/github_api/client/activity/notifications.rb +181 -0
  18. data/lib/github_api/client/activity/starring.rb +130 -0
  19. data/lib/github_api/client/activity/watching.rb +176 -0
  20. data/lib/github_api/client/authorizations.rb +142 -0
  21. data/lib/github_api/client/authorizations/app.rb +98 -0
  22. data/lib/github_api/client/emojis.rb +19 -0
  23. data/lib/github_api/client/gists.rb +289 -0
  24. data/lib/github_api/client/gists/comments.rb +100 -0
  25. data/lib/github_api/client/git_data.rb +31 -0
  26. data/lib/github_api/client/git_data/blobs.rb +51 -0
  27. data/lib/github_api/client/git_data/commits.rb +101 -0
  28. data/lib/github_api/client/git_data/references.rb +150 -0
  29. data/lib/github_api/client/git_data/tags.rb +95 -0
  30. data/lib/github_api/client/git_data/trees.rb +113 -0
  31. data/lib/github_api/client/gitignore.rb +57 -0
  32. data/lib/github_api/client/issues.rb +248 -0
  33. data/lib/github_api/client/issues/assignees.rb +77 -0
  34. data/lib/github_api/client/issues/comments.rb +146 -0
  35. data/lib/github_api/client/issues/events.rb +50 -0
  36. data/lib/github_api/client/issues/labels.rb +189 -0
  37. data/lib/github_api/client/issues/milestones.rb +146 -0
  38. data/lib/github_api/client/markdown.rb +62 -0
  39. data/lib/github_api/client/meta.rb +19 -0
  40. data/lib/github_api/client/orgs.rb +127 -0
  41. data/lib/github_api/client/orgs/hooks.rb +182 -0
  42. data/lib/github_api/client/orgs/members.rb +142 -0
  43. data/lib/github_api/client/orgs/memberships.rb +131 -0
  44. data/lib/github_api/client/orgs/projects.rb +57 -0
  45. data/lib/github_api/client/orgs/teams.rb +407 -0
  46. data/lib/github_api/client/projects.rb +83 -0
  47. data/lib/github_api/client/projects/cards.rb +158 -0
  48. data/lib/github_api/client/projects/columns.rb +146 -0
  49. data/lib/github_api/client/pull_requests.rb +195 -0
  50. data/lib/github_api/client/pull_requests/comments.rb +140 -0
  51. data/lib/github_api/client/pull_requests/reviews.rb +158 -0
  52. data/lib/github_api/client/repos.rb +468 -0
  53. data/lib/github_api/client/repos/branches.rb +48 -0
  54. data/lib/github_api/client/repos/branches/protections.rb +75 -0
  55. data/lib/github_api/client/repos/collaborators.rb +84 -0
  56. data/lib/github_api/client/repos/comments.rb +125 -0
  57. data/lib/github_api/client/repos/commits.rb +80 -0
  58. data/lib/github_api/client/repos/contents.rb +246 -0
  59. data/lib/github_api/client/repos/deployments.rb +138 -0
  60. data/lib/github_api/client/repos/downloads.rb +62 -0
  61. data/lib/github_api/client/repos/forks.rb +48 -0
  62. data/lib/github_api/client/repos/hooks.rb +214 -0
  63. data/lib/github_api/client/repos/keys.rb +104 -0
  64. data/lib/github_api/client/repos/merging.rb +47 -0
  65. data/lib/github_api/client/repos/pages.rb +48 -0
  66. data/lib/github_api/client/repos/projects.rb +62 -0
  67. data/lib/github_api/client/repos/pub_sub_hubbub.rb +133 -0
  68. data/lib/github_api/client/repos/releases.rb +189 -0
  69. data/lib/github_api/client/repos/releases/assets.rb +136 -0
  70. data/lib/github_api/client/repos/releases/tags.rb +24 -0
  71. data/lib/github_api/client/repos/statistics.rb +89 -0
  72. data/lib/github_api/client/repos/statuses.rb +91 -0
  73. data/lib/github_api/client/say.rb +25 -0
  74. data/lib/github_api/client/scopes.rb +46 -0
  75. data/lib/github_api/client/search.rb +133 -0
  76. data/lib/github_api/client/search/legacy.rb +111 -0
  77. data/lib/github_api/client/users.rb +117 -0
  78. data/lib/github_api/client/users/emails.rb +65 -0
  79. data/lib/github_api/client/users/followers.rb +115 -0
  80. data/lib/github_api/client/users/keys.rb +104 -0
  81. data/lib/github_api/configuration.rb +70 -0
  82. data/lib/github_api/connection.rb +82 -0
  83. data/lib/github_api/constants.rb +61 -0
  84. data/lib/github_api/core_ext/array.rb +25 -0
  85. data/lib/github_api/core_ext/hash.rb +91 -0
  86. data/lib/github_api/core_ext/ordered_hash.rb +107 -0
  87. data/lib/github_api/deprecation.rb +39 -0
  88. data/lib/github_api/error.rb +32 -0
  89. data/lib/github_api/error/client_error.rb +89 -0
  90. data/lib/github_api/error/service_error.rb +223 -0
  91. data/lib/github_api/ext/faraday.rb +38 -0
  92. data/lib/github_api/mash.rb +7 -0
  93. data/lib/github_api/middleware.rb +37 -0
  94. data/lib/github_api/mime_type.rb +33 -0
  95. data/lib/github_api/normalizer.rb +23 -0
  96. data/lib/github_api/null_encoder.rb +25 -0
  97. data/lib/github_api/page_iterator.rb +138 -0
  98. data/lib/github_api/page_links.rb +63 -0
  99. data/lib/github_api/paged_request.rb +42 -0
  100. data/lib/github_api/pagination.rb +115 -0
  101. data/lib/github_api/parameter_filter.rb +35 -0
  102. data/lib/github_api/params_hash.rb +115 -0
  103. data/lib/github_api/rate_limit.rb +25 -0
  104. data/lib/github_api/request.rb +85 -0
  105. data/lib/github_api/request/basic_auth.rb +36 -0
  106. data/lib/github_api/request/jsonize.rb +54 -0
  107. data/lib/github_api/request/oauth2.rb +44 -0
  108. data/lib/github_api/request/verbs.rb +63 -0
  109. data/lib/github_api/response.rb +48 -0
  110. data/lib/github_api/response/atom_parser.rb +22 -0
  111. data/lib/github_api/response/follow_redirects.rb +140 -0
  112. data/lib/github_api/response/header.rb +87 -0
  113. data/lib/github_api/response/jsonize.rb +28 -0
  114. data/lib/github_api/response/mashify.rb +24 -0
  115. data/lib/github_api/response/raise_error.rb +22 -0
  116. data/lib/github_api/response/xmlize.rb +27 -0
  117. data/lib/github_api/response_wrapper.rb +161 -0
  118. data/lib/github_api/ssl_certs/cacerts.pem +2183 -0
  119. data/lib/github_api/utils/url.rb +63 -0
  120. data/lib/github_api/validations.rb +22 -0
  121. data/lib/github_api/validations/format.rb +26 -0
  122. data/lib/github_api/validations/presence.rb +32 -0
  123. data/lib/github_api/validations/required.rb +21 -0
  124. data/lib/github_api/validations/token.rb +41 -0
  125. data/lib/github_api/version.rb +5 -0
  126. metadata +338 -0
@@ -0,0 +1,140 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../api'
4
+
5
+ module Github
6
+ class Client::PullRequests::Comments < API
7
+ # List comments on a pull request
8
+ #
9
+ # @example
10
+ # github = Github.new
11
+ # github.pull_requests.comments.list 'user-name', 'repo-name', number: 'id'
12
+ #
13
+ # List comments in a repository
14
+ #
15
+ # By default, Review Comments are ordered by ascending ID.
16
+ #
17
+ # @param [Hash] params
18
+ # @input params [String] :sort
19
+ # Optional string. Can be either created or updated. Default: created
20
+ # @input params [String] :direction
21
+ # Optional string. Can be either asc or desc. Ignored without sort parameter
22
+ # @input params [String] :since
23
+ # Optional string of a timestamp in ISO 8601
24
+ # format: YYYY-MM-DDTHH:MM:SSZ
25
+ # @example
26
+ # github = Github.new
27
+ # github.pull_requests.comments.list 'user-name', 'repo-name'
28
+ # github.pull_requests.comments.list 'user-name', 'repo-name' { |comm| ... }
29
+ #
30
+ # @api public
31
+ def list(*args)
32
+ arguments(args, required: [:user, :repo])
33
+ params = arguments.params
34
+ user = arguments.user
35
+ repo = arguments.repo
36
+
37
+ response = if (number = params.delete('number'))
38
+ get_request("/repos/#{user}/#{repo}/pulls/#{number}/comments", params)
39
+ else
40
+ get_request("/repos/#{user}/#{repo}/pulls/comments", params)
41
+ end
42
+ return response unless block_given?
43
+ response.each { |el| yield el }
44
+ end
45
+ alias_method :all, :list
46
+
47
+ # Get a single comment for pull requests
48
+ #
49
+ # @example
50
+ # github = Github.new
51
+ # github.pull_requests.comments.get 'user-name', 'repo-name', 'number'
52
+ #
53
+ # @example
54
+ # github.pull_requests.comments.get
55
+ # user: 'user-name',
56
+ # repo: 'repo-name',
57
+ # number: 'comment-number
58
+ #
59
+ # @api public
60
+ def get(*args)
61
+ arguments(args, required: [:user, :repo, :number])
62
+
63
+ get_request("/repos/#{arguments.user}/#{arguments.repo}/pulls/#{arguments.number}/comments", arguments.params)
64
+ end
65
+ alias_method :find, :get
66
+
67
+ # Create a pull request comment
68
+ #
69
+ # @param [Hash] params
70
+ # @option params [String] :body
71
+ # Required string. The text of the comment.
72
+ # @option params [String] :commit_id
73
+ # Required string - The SHA of the commit to comment on.
74
+ # @option params [String] :path
75
+ # Required string. The relative path of the file to comment on.
76
+ # @option params [Number] :position
77
+ # Required number. The line index in the diff to comment on.
78
+ #
79
+ # @example
80
+ # github = Github.new
81
+ # github.pull_requests.comments.create 'user-name', 'repo-name', 'number',
82
+ # body: "Nice change",
83
+ # commit_id: "6dcb09b5b57875f334f61aebed695e2e4193db5e",
84
+ # path: "file1.txt",
85
+ # position: 4
86
+ #
87
+ # Alternative Inputs
88
+ #
89
+ # Instead of passing commit_id, path, and position you can reply to
90
+ # an existing Pull Request Comment like this
91
+ # @option params [String] :body
92
+ # Required string. The text of the comment.
93
+ # @option params [Number] :in_reply_to
94
+ # Required number. The comment id to reply to.
95
+ #
96
+ # @example
97
+ # github = Github.new
98
+ # github.pull_requests.comments.create 'user-name','repo-name', 'number',
99
+ # body: "Nice change",
100
+ # in_reply_to: 4
101
+ #
102
+ # @api public
103
+ def create(*args)
104
+ arguments(args, required: [:user, :repo, :number])
105
+
106
+ post_request("/repos/#{arguments.user}/#{arguments.repo}/pulls/#{arguments.number}/comments", arguments.params)
107
+ end
108
+
109
+ # Edit a pull request comment
110
+ #
111
+ # @param [Hash] params
112
+ # @option params [String] :body
113
+ # Required string. The text of the comment.
114
+ #
115
+ # @example
116
+ # github = Github.new
117
+ # github.pull_requests.comments.edit 'user-name', 'repo-name', 'number',
118
+ # body: "Nice change"
119
+ #
120
+ # @api public
121
+ def edit(*args)
122
+ arguments(args, required: [:user, :repo, :number])
123
+
124
+ patch_request("/repos/#{arguments.user}/#{arguments.repo}/pulls/comments/#{arguments.number}", arguments.params)
125
+ end
126
+
127
+ # Delete a pull request comment
128
+ #
129
+ # @example
130
+ # github = Github.new
131
+ # github.pull_requests.comments.delete 'user-name', 'repo-name', 'number'
132
+ #
133
+ # @api public
134
+ def delete(*args)
135
+ arguments(args, required: [:user, :repo, :number])
136
+
137
+ delete_request("/repos/#{arguments.user}/#{arguments.repo}/pulls/comments/#{arguments.number}", arguments.params)
138
+ end
139
+ end # PullRequests::Comments
140
+ end # Github
@@ -0,0 +1,158 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../api'
4
+
5
+ module Github
6
+ class Client::PullRequests::Reviews < API
7
+ PREVIEW_MEDIA = "application/vnd.github.black-cat-preview+json".freeze # :nodoc:
8
+
9
+ # List reviews on a pull request
10
+ #
11
+ # @example
12
+ # github = Github.new
13
+ # github.pull_requests.reviews.list 'user-name', 'repo-name', number: 'pull-request-number'
14
+ #
15
+ # List pull request reviews in a repository
16
+ #
17
+ # @example
18
+ # github = Github.new
19
+ # github.pull_requests.reviews.list 'user-name', 'repo-name', number: 'pull-request-number'
20
+ # github.pull_requests.reviews.list 'user-name', 'repo-name', number: 'pull-request-number' { |comm| ... }
21
+ #
22
+ # @api public
23
+ def list(*args)
24
+ arguments(args, required: [:user, :repo, :number])
25
+ params = arguments.params
26
+
27
+ params["accept"] ||= PREVIEW_MEDIA
28
+
29
+ response = get_request("/repos/#{arguments.user}/#{arguments.repo}/pulls/#{arguments.number}/reviews", params)
30
+ return response unless block_given?
31
+ response.each { |el| yield el }
32
+ end
33
+ alias_method :all, :list
34
+
35
+ # Get a single review for pull requests
36
+ #
37
+ # @example
38
+ # github = Github.new
39
+ # github.pull_requests.reviews.get 'user-name', 'repo-name', 'number', 'id'
40
+ #
41
+ # @example
42
+ # github.pull_requests.reviews.get
43
+ # user: 'user-name',
44
+ # repo: 'repo-name',
45
+ # number: 1,
46
+ # id: 80
47
+ #
48
+ # @api public
49
+ def get(*args)
50
+ arguments(args, required: [:user, :repo, :number, :id])
51
+
52
+ params = arguments.params
53
+ params["accept"] ||= PREVIEW_MEDIA
54
+
55
+ get_request("/repos/#{arguments.user}/#{arguments.repo}/pulls/#{arguments.number}/reviews/#{arguments.id}", params)
56
+ end
57
+ alias_method :find, :get
58
+
59
+ # Create a pull request review
60
+ #
61
+ # @param [Hash] params
62
+ # @option params [String] :event
63
+ # Required string - The review action (event) to perform; can be one of
64
+ # APPROVE, REQUEST_CHANGES, or COMMENT. If left blank, the API returns
65
+ # HTTP 422 (Unrecognizable entity) and the review is left PENDING
66
+ # @option params [String] :body
67
+ # Optional string. The text of the review.
68
+ # @option params [Array] :comments
69
+ # Optional array of draft review comment objects. An array of comments
70
+ # part of the review.
71
+ #
72
+ # @example
73
+ # github = Github.new
74
+ # github.pull_requests.reviews.create 'user-name', 'repo-name', 'number',
75
+ # body: "Nice change",
76
+ # event: "APPROVE",
77
+ # comments: [
78
+ # {
79
+ # path: 'path/to/file/commented/on',
80
+ # position: 10,
81
+ # body: 'This looks good.'
82
+ # }
83
+ # ]
84
+ #
85
+ # @api public
86
+ def create(*args)
87
+ arguments(args, required: [:user, :repo, :number])
88
+
89
+ params = arguments.params
90
+ params["accept"] ||= PREVIEW_MEDIA
91
+
92
+ post_request("/repos/#{arguments.user}/#{arguments.repo}/pulls/#{arguments.number}/reviews", params)
93
+ end
94
+
95
+ # Update a pull request review
96
+ #
97
+ # @param [Hash] params
98
+ # @option params [String] :state
99
+ # Required string - The review action (event) to perform; can be one of
100
+ # APPROVE, REQUEST_CHANGES, or COMMENT. If left blank, the API returns
101
+ # HTTP 422 (Unrecognizable entity) and the review is left PENDING
102
+ # @optoin params [String] :body
103
+ # Optional string
104
+ #
105
+ # @example
106
+ # github = Github.new oauth_token: '...'
107
+ # github.pull_requests.reviews.update 'user-name', 'repo-name', 'number', 'review-id'
108
+ # body: "Update body",
109
+ # event: "APPROVE"
110
+ #
111
+ # @api public
112
+ def update(*args)
113
+ arguments(args, required: [:user, :repo, :number, :id])
114
+ params = arguments.params
115
+
116
+ params["accept"] ||= PREVIEW_MEDIA
117
+
118
+ post_request("/repos/#{arguments.user}/#{arguments.repo}/pulls/#{arguments.number}/reviews/#{arguments.id}/events", params)
119
+ end
120
+
121
+ # @option params [String] :message
122
+ # Optional string - Reason for dismissal
123
+ #
124
+ # @example
125
+ # github = Github.new oauth_token: '...'
126
+ # github.pull_requests.reviews.dismiss 'user-name', 'repo-name', 'number', 'review-id'
127
+ # message: "I can't get to this right now."
128
+ #
129
+ # @api public
130
+ def dismiss(*args)
131
+ arguments(args, required: [:user, :repo, :number, :id])
132
+ params = arguments.params
133
+
134
+ params["accept"] ||= PREVIEW_MEDIA
135
+
136
+ put_request("/repos/#{arguments.user}/#{arguments.repo}/pulls/#{arguments.number}/reviews/#{arguments.id}/dismissals", params)
137
+ end
138
+
139
+ # List comments on a pull request review
140
+ #
141
+ # @example
142
+ # github = Github.new
143
+ # github.pull_requests.revieiws.comments 'user-name', 'repo-name', 'number', 'review-id'
144
+ #
145
+ # @api public
146
+ def comments(*args)
147
+ arguments(args, required: [:user, :repo, :number, :id])
148
+ params = arguments.params
149
+
150
+ params["accept"] ||= PREVIEW_MEDIA
151
+
152
+ response = get_request("/repos/#{arguments.user}/#{arguments.repo}/pulls/#{arguments.number}/reviews/#{arguments.id}/comments", params)
153
+ return response unless block_given?
154
+ response.each { |el| yield el }
155
+ end
156
+
157
+ end
158
+ end
@@ -0,0 +1,468 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../api'
4
+
5
+ module Github
6
+ class Client::Repos < API
7
+ # Load all the modules after initializing Repos to avoid superclass mismatch
8
+ require_all 'github_api/client/repos',
9
+ 'branches',
10
+ 'collaborators',
11
+ 'comments',
12
+ 'commits',
13
+ 'contents',
14
+ 'deployments',
15
+ 'downloads',
16
+ 'forks',
17
+ 'hooks',
18
+ 'keys',
19
+ 'merging',
20
+ 'pages',
21
+ 'projects',
22
+ 'pub_sub_hubbub',
23
+ 'releases',
24
+ 'statistics',
25
+ 'statuses'
26
+
27
+ REQUIRED_REPO_OPTIONS = %w[ name ]
28
+
29
+ VALID_REPO_OPTIONS = %w[
30
+ name
31
+ description
32
+ homepage
33
+ private
34
+ has_issues
35
+ has_wiki
36
+ has_downloads
37
+ team_id
38
+ auto_init
39
+ gitignore_template
40
+ default_branch
41
+ ].freeze
42
+
43
+ VALID_REPO_TYPES = %w[ all public private member ].freeze
44
+
45
+ # Access to Repos::Collaborators API
46
+ namespace :collaborators
47
+
48
+ # Access to Repos::Comments API
49
+ namespace :comments
50
+
51
+ # Access to Repos::Commits API
52
+ namespace :commits
53
+
54
+ # Access to Repos::Contents API
55
+ namespace :contents
56
+
57
+ # Access to Repos::Deployments API
58
+ namespace :deployments
59
+
60
+ # Access to Repos::Downloads API
61
+ namespace :downloads
62
+
63
+ # Access to Repos::Forks API
64
+ namespace :forks
65
+
66
+ # Access to Repos::Hooks API
67
+ namespace :hooks
68
+
69
+ # Access to Repos::Keys API
70
+ namespace :keys
71
+
72
+ # Access to Repos::Merging API
73
+ namespace :merging
74
+
75
+ # Access to Repos::Pages API
76
+ namespace :pages
77
+
78
+ # Access to Repos::Projects API
79
+ namespace :projects
80
+
81
+ # Access to Repos::PubSubHubbub API
82
+ namespace :pubsubhubbub, full_name: :pub_sub_hubbub
83
+
84
+ # Access to Repos::Releases API
85
+ namespace :releases
86
+
87
+ # Access to Repos::Statistics API
88
+ namespace :stats, full_name: :statistics
89
+
90
+ # Access to Repos::Statuses API
91
+ namespace :statuses
92
+
93
+ # Access to Repos::Branches API
94
+ namespace :branches
95
+
96
+ # List repositories for the authenticated user
97
+ #
98
+ # @example
99
+ # github = Github.new oauth_token: '...'
100
+ # github.repos.list
101
+ # github.repos.list { |repo| ... }
102
+ #
103
+ # List all repositories
104
+ #
105
+ # This provides a dump of every repository,
106
+ # in the order that they were created.
107
+ #
108
+ # @param [Hash] params
109
+ # @option params [Integer] :since
110
+ # the integer ID of the last Repository that you've seen.
111
+ #
112
+ # @example
113
+ # github = Github.new
114
+ # github.repos.list :every
115
+ # github.repos.list :every { |repo| ... }
116
+ #
117
+ # List public repositories for the specified user.
118
+ #
119
+ # @example
120
+ # github = Github.new
121
+ # github.repos.list user: 'user-name'
122
+ # github.repos.list user: 'user-name', { |repo| ... }
123
+ #
124
+ # List repositories for the specified organisation.
125
+ #
126
+ # @example
127
+ # github = Github.new
128
+ # github.repos.list org: 'org-name'
129
+ # github.repos.list org: 'org-name', { |repo| ... }
130
+ #
131
+ # @api public
132
+ def list(*args)
133
+ arguments(args) do
134
+ permit %w[ user org type sort direction since ]
135
+ end
136
+ params = arguments.params
137
+ unless params.symbolize_keys[:per_page]
138
+ params.merge!(Pagination.per_page_as_param(current_options[:per_page]))
139
+ end
140
+
141
+ response = if (user_name = params.delete('user') || user)
142
+ get_request("/users/#{user_name}/repos", params)
143
+ elsif (org_name = params.delete('org') || org)
144
+ get_request("/orgs/#{org_name}/repos", params)
145
+ elsif args.map(&:to_s).include?('every')
146
+ get_request('/repositories', params)
147
+ else
148
+ # For authenticated user
149
+ get_request('/user/repos', params)
150
+ end
151
+ return response unless block_given?
152
+ response.each { |el| yield el }
153
+ end
154
+ alias :all :list
155
+
156
+ # Get a repository
157
+ #
158
+ # @example
159
+ # github = Github.new
160
+ # github.repos.get 'user-name', 'repo-name'
161
+ # github.repos.get user: 'user-name', repo: 'repo-name'
162
+ # github.repos(user: 'user-name', repo: 'repo-name').get
163
+ #
164
+ def get(*args)
165
+ arguments(args, required: [:user, :repo])
166
+
167
+ get_request("/repos/#{arguments.user}/#{arguments.repo}", arguments.params)
168
+ end
169
+ alias :find :get
170
+
171
+ # Get a repository
172
+ #
173
+ # @example
174
+ # github = Github.new
175
+ # github.repos.get_by_id 'repo-id'
176
+ # github.repos.get_by_id id: 'repo-id'
177
+ # github.repos(id: 'repo-id').get_by_id
178
+ #
179
+ def get_by_id(*args)
180
+ arguments(args, required: [:id])
181
+
182
+ get_request("/repositories/#{arguments.id}", arguments.params)
183
+ end
184
+ alias :find_by_id :get_by_id
185
+
186
+ # Create a new repository for the autheticated user.
187
+ #
188
+ # @param [Hash] params
189
+ # @option params [String] :name
190
+ # Required string
191
+ # @option params [String] :description
192
+ # Optional string
193
+ # @option params [String] :homepage
194
+ # Optional string
195
+ # @option params [Boolean] :private
196
+ # Optional boolean - true to create a private repository,
197
+ # false to create a public one.
198
+ # @option params [Boolean] :has_issues
199
+ # Optional boolean - true to enable issues for this repository,
200
+ # false to disable them
201
+ # @option params [Boolean] :has_wiki
202
+ # Optional boolean - true to enable the wiki for this repository,
203
+ # false to disable it. Default is true
204
+ # @option params [Boolean] :has_downloads
205
+ # Optional boolean - true to enable downloads for this repository
206
+ # @option params [String] :org
207
+ # Optional string - The organisation in which this
208
+ # repository will be created
209
+ # @option params [Numeric] :team_id
210
+ # Optional number - The id of the team that will be granted
211
+ # access to this repository. This is only valid when creating
212
+ # a repo in an organization
213
+ # @option params [Boolean] :auto_init
214
+ # Optional boolean - true to create an initial commit with
215
+ # empty README. Default is false.
216
+ # @option params [String] :gitignore_template
217
+ # Optional string - Desired language or platform .gitignore
218
+ # template to apply. Use the name of the template without
219
+ # the extension. For example, “Haskell” Ignored if
220
+ # auto_init parameter is not provided.
221
+ #
222
+ # @example
223
+ # github = Github.new
224
+ # github.repos.create "name": 'repo-name'
225
+ # "description": "This is your first repo",
226
+ # "homepage": "https://github.com",
227
+ # "private": false,
228
+ # "has_issues": true,
229
+ # "has_wiki": true,
230
+ # "has_downloads": true
231
+ #
232
+ # Create a new repository in this organisation. The authenticated user
233
+ # must be a member of this organisation
234
+ #
235
+ # @example
236
+ # github = Github.new oauth_token: '...'
237
+ # github.repos.create name: 'repo-name', org: 'organisation-name'
238
+ #
239
+ # @example
240
+ def create(*args)
241
+ arguments(args) do
242
+ assert_required %w[ name ]
243
+ end
244
+ params = arguments.params
245
+
246
+ # Requires authenticated user
247
+ if (org = params.delete('org') || org)
248
+ post_request("/orgs/#{org}/repos", params)
249
+ else
250
+ post_request("/user/repos", params)
251
+ end
252
+ end
253
+
254
+ # Delete a repository
255
+ #
256
+ # Deleting a repository requires admin access.
257
+ # If OAuth is used, the delete_repo scope is required.
258
+ #
259
+ # @example
260
+ # github = Github.new oauth_token: '...'
261
+ # github.repos.delete 'user-name', 'repo-name'
262
+ #
263
+ # @api public
264
+ def delete(*args)
265
+ arguments(args, required: [:user, :repo])
266
+
267
+ delete_request("/repos/#{arguments.user}/#{arguments.repo}", arguments.params)
268
+ end
269
+ alias :remove :delete
270
+
271
+ # List contributors
272
+ #
273
+ # @param [Hash] params
274
+ # @option params [Boolean] :anon
275
+ # Optional flag. Set to 1 or true to include anonymous contributors.
276
+ #
277
+ # @examples
278
+ # github = Github.new
279
+ # github.repos.contributors 'user-name','repo-name'
280
+ # github.repos.contributors 'user-name','repo-name' { |cont| ... }
281
+ #
282
+ # @api public
283
+ def contributors(*args)
284
+ arguments(args, required: [:user, :repo]) do
285
+ permit %w[ anon ]
286
+ end
287
+
288
+ response = get_request("/repos/#{arguments.user}/#{arguments.repo}/contributors", arguments.params)
289
+ return response unless block_given?
290
+ response.each { |el| yield el }
291
+ end
292
+ alias :list_contributors :contributors
293
+ alias :contribs :contributors
294
+
295
+ # Edit a repository
296
+ #
297
+ # @param [Hash] params
298
+ # @option params [String] :name
299
+ # Required string
300
+ # @option params [String] :description
301
+ # Optional string
302
+ # @option params [String] :homepage
303
+ # Optional string
304
+ # @option params [Boolean] :private
305
+ # Optional boolean, true to make this a private repository, false to make it a public one
306
+ # @option params [Boolean] :has_issues
307
+ # Optional boolean - true to enable issues for this repository,
308
+ # false to disable them
309
+ # @option params [Boolean] :has_wiki
310
+ # Optional boolean - true to enable the wiki for this repository,
311
+ # false to disable it. Default is true
312
+ # @option params [Boolean] :has_downloads
313
+ # Optional boolean - true to enable downloads for this repository
314
+ # @option params [String] :default_branch
315
+ # Optional string - Update the default branch for this repository.
316
+ #
317
+ # @example
318
+ # github = Github.new
319
+ # github.repos.edit 'user-name', 'repo-name',
320
+ # name: 'hello-world',
321
+ # description: 'This is your first repo',
322
+ # homepage: "https://github.com",
323
+ # public: true, has_issues: true
324
+ #
325
+ def edit(*args)
326
+ arguments(args, required: [:user, :repo]) do
327
+ permit VALID_REPO_OPTIONS
328
+ assert_required %w[ name ]
329
+ end
330
+
331
+ patch_request("/repos/#{arguments.user}/#{arguments.repo}", arguments.params)
332
+ end
333
+
334
+ # Delete a repository
335
+ #
336
+ # Deleting a repository requires admin access.
337
+ # If OAuth is used, the delete_repo scope is required.
338
+ #
339
+ # @example
340
+ # github = Github.new oauth_token: '...'
341
+ # github.repos.delete 'user-name', 'repo-name'
342
+ #
343
+ # @api public
344
+ def delete(*args)
345
+ arguments(args, required: [:user, :repo])
346
+
347
+ delete_request("/repos/#{arguments.user}/#{arguments.repo}", arguments.params)
348
+ end
349
+ alias :remove :delete
350
+
351
+ # List branches
352
+ #
353
+ # @example
354
+ # github = Github.new
355
+ # github.repos.branches 'user-name', 'repo-name'
356
+ # github.repos(user: 'user-name', repo: 'repo-name').branches
357
+ #
358
+ # @example
359
+ # repos = Github::Repos.new
360
+ # repos.branches 'user-name', 'repo-name'
361
+ #
362
+ # @api public
363
+ # def branches(*args)
364
+ # arguments(args, required: [:user, :repo])
365
+
366
+ # response = get_request("/repos/#{arguments.user}/#{arguments.repo}/branches", arguments.params)
367
+ # return response unless block_given?
368
+ # response.each { |el| yield el }
369
+ # end
370
+ # alias :list_branches :branches
371
+
372
+ # Get branch
373
+ #
374
+ # @example
375
+ # github = Github.new
376
+ # github.repos.branch 'user-name', 'repo-name', 'branch-name'
377
+ # github.repos.branch user: 'user-name', repo: 'repo-name', branch: 'branch-name'
378
+ # github.repos(user: 'user-name', repo: 'repo-name', branch: 'branch-name').branch
379
+ # @api public
380
+ # def branch(*args)
381
+ # arguments(args, required: [:user, :repo, :branch])
382
+
383
+ # get_request("/repos/#{arguments.user}/#{arguments.repo}/branches/#{arguments.branch}", arguments.params)
384
+ # end
385
+
386
+ # List contributors
387
+ #
388
+ # @param [Hash] params
389
+ # @option params [Boolean] :anon
390
+ # Optional flag. Set to 1 or true to include anonymous contributors.
391
+ #
392
+ # @example
393
+ # github = Github.new
394
+ # github.repos.contributors 'user-name','repo-name'
395
+ # github.repos.contributors 'user-name','repo-name' { |cont| ... }
396
+ #
397
+ # @api public
398
+ def contributors(*args)
399
+ arguments(args, required: [:user, :repo]) do
400
+ permit ['anon']
401
+ end
402
+
403
+ response = get_request("/repos/#{arguments.user}/#{arguments.repo}/contributors", arguments.params)
404
+ return response unless block_given?
405
+ response.each { |el| yield el }
406
+ end
407
+ alias :list_contributors :contributors
408
+ alias :contribs :contributors
409
+
410
+ # List languages
411
+ #
412
+ # @examples
413
+ # github = Github.new
414
+ # github.repos.languages 'user-name', 'repo-name'
415
+ # github.repos.languages 'user-name', 'repo-name' { |lang| ... }
416
+ #
417
+ # @api public
418
+ def languages(*args)
419
+ arguments(args, required: [:user, :repo])
420
+
421
+ response = get_request("/repos/#{arguments.user}/#{arguments.repo}/languages", arguments.params)
422
+ return response unless block_given?
423
+ response.each { |el| yield el }
424
+ end
425
+ alias :list_languages :languages
426
+
427
+ # List tags
428
+ #
429
+ # @example
430
+ # github = Github.new
431
+ # github.repos.tags 'user-name', 'repo-name'
432
+ # github.repos.tags 'user-name', 'repo-name' { |tag| ... }
433
+ #
434
+ # @api public
435
+ def tags(*args)
436
+ arguments(args, required: [:user, :repo])
437
+
438
+ response = get_request("/repos/#{arguments.user}/#{arguments.repo}/tags", arguments.params)
439
+ return response unless block_given?
440
+ response.each { |el| yield el }
441
+ end
442
+ alias :list_tags :tags
443
+ alias :repo_tags :tags
444
+ alias :repository_tags :tags
445
+
446
+ # List teams
447
+ #
448
+ # @example
449
+ # github = Github.new
450
+ # github.repos.teams 'user-name', 'repo-name'
451
+ # github.repos.teams 'user-name', 'repo-name' { |team| ... }
452
+ #
453
+ # @example
454
+ # github.repos(user: 'user-name, repo: 'repo-name').teams
455
+ #
456
+ # @api public
457
+ def teams(*args)
458
+ arguments(args, required: [:user, :repo])
459
+
460
+ response = get_request("/repos/#{arguments.user}/#{arguments.repo}/teams", arguments.params)
461
+ return response unless block_given?
462
+ response.each { |el| yield el }
463
+ end
464
+ alias :list_teams :teams
465
+ alias :repo_teams :teams
466
+ alias :repository_teams :teams
467
+ end # Client::Repos
468
+ end # Github