github_api2 1.0.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 (127) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +770 -0
  3. data/LICENSE.txt +20 -0
  4. data/README.md +741 -0
  5. data/lib/github_api2/api/actions.rb +60 -0
  6. data/lib/github_api2/api/arguments.rb +253 -0
  7. data/lib/github_api2/api/config/property.rb +30 -0
  8. data/lib/github_api2/api/config/property_set.rb +120 -0
  9. data/lib/github_api2/api/config.rb +105 -0
  10. data/lib/github_api2/api/factory.rb +33 -0
  11. data/lib/github_api2/api.rb +398 -0
  12. data/lib/github_api2/authorization.rb +75 -0
  13. data/lib/github_api2/client/activity/events.rb +233 -0
  14. data/lib/github_api2/client/activity/feeds.rb +50 -0
  15. data/lib/github_api2/client/activity/notifications.rb +181 -0
  16. data/lib/github_api2/client/activity/starring.rb +130 -0
  17. data/lib/github_api2/client/activity/watching.rb +176 -0
  18. data/lib/github_api2/client/activity.rb +31 -0
  19. data/lib/github_api2/client/authorizations/app.rb +98 -0
  20. data/lib/github_api2/client/authorizations.rb +142 -0
  21. data/lib/github_api2/client/emojis.rb +19 -0
  22. data/lib/github_api2/client/gists/comments.rb +100 -0
  23. data/lib/github_api2/client/gists.rb +289 -0
  24. data/lib/github_api2/client/git_data/blobs.rb +51 -0
  25. data/lib/github_api2/client/git_data/commits.rb +101 -0
  26. data/lib/github_api2/client/git_data/references.rb +150 -0
  27. data/lib/github_api2/client/git_data/tags.rb +95 -0
  28. data/lib/github_api2/client/git_data/trees.rb +113 -0
  29. data/lib/github_api2/client/git_data.rb +31 -0
  30. data/lib/github_api2/client/gitignore.rb +57 -0
  31. data/lib/github_api2/client/issues/assignees.rb +77 -0
  32. data/lib/github_api2/client/issues/comments.rb +146 -0
  33. data/lib/github_api2/client/issues/events.rb +50 -0
  34. data/lib/github_api2/client/issues/labels.rb +189 -0
  35. data/lib/github_api2/client/issues/milestones.rb +146 -0
  36. data/lib/github_api2/client/issues.rb +248 -0
  37. data/lib/github_api2/client/markdown.rb +62 -0
  38. data/lib/github_api2/client/meta.rb +19 -0
  39. data/lib/github_api2/client/orgs/hooks.rb +182 -0
  40. data/lib/github_api2/client/orgs/members.rb +142 -0
  41. data/lib/github_api2/client/orgs/memberships.rb +131 -0
  42. data/lib/github_api2/client/orgs/projects.rb +57 -0
  43. data/lib/github_api2/client/orgs/teams.rb +407 -0
  44. data/lib/github_api2/client/orgs.rb +127 -0
  45. data/lib/github_api2/client/projects/cards.rb +158 -0
  46. data/lib/github_api2/client/projects/columns.rb +146 -0
  47. data/lib/github_api2/client/projects.rb +83 -0
  48. data/lib/github_api2/client/pull_requests/comments.rb +140 -0
  49. data/lib/github_api2/client/pull_requests/reviews.rb +158 -0
  50. data/lib/github_api2/client/pull_requests.rb +195 -0
  51. data/lib/github_api2/client/repos/branches/protections.rb +75 -0
  52. data/lib/github_api2/client/repos/branches.rb +48 -0
  53. data/lib/github_api2/client/repos/collaborators.rb +84 -0
  54. data/lib/github_api2/client/repos/comments.rb +125 -0
  55. data/lib/github_api2/client/repos/commits.rb +80 -0
  56. data/lib/github_api2/client/repos/contents.rb +263 -0
  57. data/lib/github_api2/client/repos/deployments.rb +138 -0
  58. data/lib/github_api2/client/repos/downloads.rb +62 -0
  59. data/lib/github_api2/client/repos/forks.rb +50 -0
  60. data/lib/github_api2/client/repos/hooks.rb +214 -0
  61. data/lib/github_api2/client/repos/invitations.rb +41 -0
  62. data/lib/github_api2/client/repos/keys.rb +104 -0
  63. data/lib/github_api2/client/repos/merging.rb +47 -0
  64. data/lib/github_api2/client/repos/pages.rb +48 -0
  65. data/lib/github_api2/client/repos/projects.rb +62 -0
  66. data/lib/github_api2/client/repos/pub_sub_hubbub.rb +133 -0
  67. data/lib/github_api2/client/repos/releases/assets.rb +136 -0
  68. data/lib/github_api2/client/repos/releases/tags.rb +24 -0
  69. data/lib/github_api2/client/repos/releases.rb +189 -0
  70. data/lib/github_api2/client/repos/statistics.rb +89 -0
  71. data/lib/github_api2/client/repos/statuses.rb +91 -0
  72. data/lib/github_api2/client/repos.rb +473 -0
  73. data/lib/github_api2/client/say.rb +25 -0
  74. data/lib/github_api2/client/scopes.rb +46 -0
  75. data/lib/github_api2/client/search/legacy.rb +111 -0
  76. data/lib/github_api2/client/search.rb +133 -0
  77. data/lib/github_api2/client/users/emails.rb +65 -0
  78. data/lib/github_api2/client/users/followers.rb +115 -0
  79. data/lib/github_api2/client/users/keys.rb +104 -0
  80. data/lib/github_api2/client/users.rb +117 -0
  81. data/lib/github_api2/client.rb +77 -0
  82. data/lib/github_api2/configuration.rb +70 -0
  83. data/lib/github_api2/connection.rb +82 -0
  84. data/lib/github_api2/constants.rb +61 -0
  85. data/lib/github_api2/core_ext/array.rb +25 -0
  86. data/lib/github_api2/core_ext/hash.rb +91 -0
  87. data/lib/github_api2/deprecation.rb +39 -0
  88. data/lib/github_api2/error/client_error.rb +89 -0
  89. data/lib/github_api2/error/service_error.rb +223 -0
  90. data/lib/github_api2/error.rb +32 -0
  91. data/lib/github_api2/ext/faraday.rb +40 -0
  92. data/lib/github_api2/mash.rb +7 -0
  93. data/lib/github_api2/middleware.rb +37 -0
  94. data/lib/github_api2/mime_type.rb +33 -0
  95. data/lib/github_api2/normalizer.rb +23 -0
  96. data/lib/github_api2/null_encoder.rb +25 -0
  97. data/lib/github_api2/page_iterator.rb +138 -0
  98. data/lib/github_api2/page_links.rb +63 -0
  99. data/lib/github_api2/paged_request.rb +42 -0
  100. data/lib/github_api2/pagination.rb +115 -0
  101. data/lib/github_api2/parameter_filter.rb +35 -0
  102. data/lib/github_api2/params_hash.rb +115 -0
  103. data/lib/github_api2/rate_limit.rb +25 -0
  104. data/lib/github_api2/request/basic_auth.rb +36 -0
  105. data/lib/github_api2/request/jsonize.rb +54 -0
  106. data/lib/github_api2/request/oauth2.rb +45 -0
  107. data/lib/github_api2/request/verbs.rb +63 -0
  108. data/lib/github_api2/request.rb +84 -0
  109. data/lib/github_api2/response/atom_parser.rb +22 -0
  110. data/lib/github_api2/response/follow_redirects.rb +140 -0
  111. data/lib/github_api2/response/header.rb +87 -0
  112. data/lib/github_api2/response/jsonize.rb +28 -0
  113. data/lib/github_api2/response/mashify.rb +24 -0
  114. data/lib/github_api2/response/raise_error.rb +22 -0
  115. data/lib/github_api2/response/xmlize.rb +28 -0
  116. data/lib/github_api2/response.rb +48 -0
  117. data/lib/github_api2/response_wrapper.rb +161 -0
  118. data/lib/github_api2/ssl_certs/cacerts.pem +2183 -0
  119. data/lib/github_api2/utils/url.rb +63 -0
  120. data/lib/github_api2/validations/format.rb +26 -0
  121. data/lib/github_api2/validations/presence.rb +32 -0
  122. data/lib/github_api2/validations/required.rb +21 -0
  123. data/lib/github_api2/validations/token.rb +41 -0
  124. data/lib/github_api2/validations.rb +22 -0
  125. data/lib/github_api2/version.rb +5 -0
  126. data/lib/github_api2.rb +92 -0
  127. metadata +363 -0
@@ -0,0 +1,136 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../../api'
4
+
5
+ module Github
6
+ # The Release Assets API
7
+ class Client::Repos::Releases::Assets < API
8
+
9
+ VALID_ASSET_PARAM_NAMES = %w[
10
+ name
11
+ label
12
+ content_type
13
+ ].freeze # :nodoc:
14
+
15
+ # List assets for a release
16
+ #
17
+ # @example
18
+ # github = Github.new
19
+ # github.repos.releases.assets.list 'owner', 'repo', 'id'
20
+ # github.repos.releases.assets.list 'owner', 'repo', 'id' { |asset| ... }
21
+ #
22
+ # @api public
23
+ def list(*args)
24
+ arguments(args, required: [:owner, :repo, :id]).params
25
+
26
+ response = get_request("/repos/#{arguments.owner}/#{arguments.repo}/releases/#{arguments.id}/assets", arguments.params)
27
+ return response unless block_given?
28
+ response.each { |el| yield el }
29
+ end
30
+ alias :all :list
31
+
32
+ # Get a single release asset
33
+ #
34
+ # @example
35
+ # github = Github.new
36
+ # github.repos.releases.assets.get 'owner', 'repo', 'id'
37
+ #
38
+ # @api public
39
+ def get(*args)
40
+ arguments(args, required: [:owner, :repo, :id]).params
41
+
42
+ get_request("/repos/#{arguments.owner}/#{arguments.repo}/releases/assets/#{arguments.id}" , arguments.params)
43
+ end
44
+ alias :find :get
45
+
46
+ # Upload a release asset
47
+ #
48
+ # @param [Hash] params
49
+ # @input params [String] :name
50
+ # Required string. The file name of the asset
51
+ # @input params [String] :content_type
52
+ # Required string. The content type of the asset.
53
+ # Example: “application/zip”.
54
+ #
55
+ # @example
56
+ # github = Github.new
57
+ # github.repos.releases.assets.upload 'owner', 'repo', 'id', 'file-path'
58
+ # name: "batman.jpg",
59
+ # content_type: "application/octet-stream"
60
+ #
61
+ # @api public
62
+ def upload(*args)
63
+ arguments(args, required: [:owner, :repo, :id, :filepath]) do
64
+ permit VALID_ASSET_PARAM_NAMES
65
+ end
66
+ params = arguments.params
67
+
68
+ unless type = params['content_type']
69
+ type = infer_media(arguments.filepath)
70
+ end
71
+
72
+ file = Faraday::UploadIO.new(arguments.filepath, type)
73
+ options = {
74
+ headers: { content_type: type },
75
+ endpoint: upload_endpoint,
76
+ query: {'name' => params['name']}
77
+ }
78
+ params['data'] = file.read
79
+ params['options'] = options
80
+
81
+ post_request("/repos/#{arguments.owner}/#{arguments.repo}/releases/#{arguments.id}/assets", params)
82
+ ensure
83
+ file.close if file
84
+ end
85
+
86
+ # Infer media type of the asset
87
+ #
88
+ def infer_media(filepath)
89
+ require 'mime/types'
90
+ types = MIME::Types.type_for(filepath)
91
+ types.empty? ? 'application/octet-stream' : types.first
92
+ rescue LoadError
93
+ raise Github::Error::UnknownMedia.new(filepath)
94
+ end
95
+
96
+ # Edit a release asset
97
+ #
98
+ # Users with push access to the repository can edit a release asset.
99
+ #
100
+ # @param [Hash] params
101
+ # @input params [String] :name
102
+ # Required. The file name of the asset.
103
+ # @input params [String] :label
104
+ # An alternate short description of the asset.
105
+ # Used in place of the filename.
106
+ #
107
+ # @example
108
+ # github = Github.new
109
+ # github.repos.releases.assets.edit 'owner', 'repo', 'id',
110
+ # name: "foo-1.0.0-osx.zip",
111
+ # label: "Mac binary"
112
+ #
113
+ # @api public
114
+ def edit(*args)
115
+ arguments(args, required: [:owner, :repo, :id]) do
116
+ permit VALID_ASSET_PARAM_NAMES
117
+ end
118
+
119
+ patch_request("/repos/#{arguments.owner}/#{arguments.repo}/releases/assets/#{arguments.id}", arguments.params)
120
+ end
121
+ alias :update :edit
122
+
123
+ # Delete a release asset
124
+ #
125
+ # @example
126
+ # github = Github.new
127
+ # github.repos.releases.assets.delete 'owner', 'repo', 'id'
128
+ #
129
+ # @api public
130
+ def delete(*args)
131
+ arguments(args, required: [:owner, :repo, :id])
132
+
133
+ delete_request("/repos/#{arguments.owner}/#{arguments.repo}/releases/assets/#{arguments.id}", arguments.params)
134
+ end
135
+ end # Client::Repos::Releases::Assets
136
+ end # Github
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../../api'
4
+
5
+ module Github
6
+ # The Releases API
7
+ class Client::Repos::Releases::Tags < API
8
+ # Get a published release with the specified tag.
9
+ #
10
+ # @see https://developer.github.com/v3/repos/releases/#get-a-release-by-tag-name
11
+ #
12
+ # @example
13
+ # github = Github.new
14
+ # github.repos.releases.tags.get 'owner', 'repo', 'tag'
15
+ #
16
+ # @api public
17
+ def get(*args)
18
+ arguments(args, required: [:owner, :repo, :tag]).params
19
+
20
+ get_request("/repos/#{arguments.owner}/#{arguments.repo}/releases/tags/#{arguments.tag}" , arguments.params)
21
+ end
22
+ alias_method :find, :get
23
+ end # Client::Repos::Releases::Tags
24
+ end # Github
@@ -0,0 +1,189 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../api'
4
+
5
+ module Github
6
+ # The Releases API
7
+ class Client::Repos::Releases < API
8
+
9
+ require_all 'github_api2/client/repos/releases', 'assets', 'tags'
10
+
11
+ # Access to Repos::Releases::Assets API
12
+ namespace :assets
13
+
14
+ # Access to Repos::Releases::Tags API
15
+ namespace :tags
16
+
17
+ # List releases for a repository
18
+ #
19
+ # Users with push access to the repository will receive all releases
20
+ # (i.e., published releases and draft releases). Users with pull access
21
+ # will receive published releases only.
22
+ #
23
+ # @see https://developer.github.com/v3/repos/releases/#list-releases-for-a-repository
24
+ #
25
+ # @example
26
+ # github = Github.new
27
+ # github.repos.releases.list 'owner', 'repo'
28
+ # github.repos.releases.list 'owner', 'repo' { |release| ... }
29
+ #
30
+ # @api public
31
+ def list(*args)
32
+ arguments(args, required: [:owner, :repo])
33
+
34
+ response = get_request("/repos/#{arguments.owner}/#{arguments.repo}/releases", arguments.params)
35
+ return response unless block_given?
36
+ response.each { |el| yield el }
37
+ end
38
+ alias_method :all, :list
39
+
40
+ # Get a single release
41
+ #
42
+ # @see https://developer.github.com/v3/repos/releases/#get-a-single-release
43
+ #
44
+ # @example
45
+ # github = Github.new
46
+ # github.repos.releases.get 'owner', 'repo', 'id'
47
+ #
48
+ # @api public
49
+ def get(*args)
50
+ arguments(args, required: [:owner, :repo, :id]).params
51
+
52
+ get_request("/repos/#{arguments.owner}/#{arguments.repo}/releases/#{arguments.id}" , arguments.params)
53
+ end
54
+ alias_method :find, :get
55
+
56
+ # Create a release
57
+ #
58
+ # Users with push access to the repository can create a release.
59
+ #
60
+ # @see https://developer.github.com/v3/repos/releases/#create-a-release
61
+ #
62
+ # @param [Hash] params
63
+ # @input params [String] :tag_name
64
+ # Required. The name of the tag.
65
+ # @input params [String] :target_commitish
66
+ # Specifies the commitish value that determines where the Git tag
67
+ # is created from. Can be any branch or commit SHA. Defaults to
68
+ # the repository's default branch (usually 'master').
69
+ # Unused if the Git tag already exists.
70
+ # @input params [String] :name
71
+ # The name of the release.
72
+ # @input params [String] :body
73
+ # Text describing the contents of the tag.
74
+ # @input params [Boolean] :draft
75
+ # true to create a draft (unpublished) release,
76
+ # false to create a published one. Default: false
77
+ # @input params [Boolean] :prerelease
78
+ # true to identify the release as a prerelease.
79
+ # false to identify the release as a full release. Default: false
80
+ #
81
+ # @example
82
+ # github = Github.new
83
+ # github.repos.releases.create 'owner', 'repo',
84
+ # tag_name: "v1.0.0",
85
+ # target_commitish: "master",
86
+ # name: "v1.0.0",
87
+ # body: "Description of the release",
88
+ # draft: false,
89
+ # prerelease: false
90
+ #
91
+ # @api public
92
+ def create(*args)
93
+ arguments(args, required: [:owner, :repo]) do
94
+ assert_required :tag_name
95
+ end
96
+
97
+ post_request("/repos/#{arguments.owner}/#{arguments.repo}/releases",
98
+ arguments.params)
99
+ end
100
+
101
+ # Edit a release
102
+ #
103
+ # Users with push access to the repository can edit a release.
104
+ #
105
+ # @see https://developer.github.com/v3/repos/releases/#edit-a-release
106
+ #
107
+ # @param [String] :owner
108
+ # @param [String] :repo
109
+ # @param [Integer] :id
110
+ # @param [Hash] params
111
+ # @input params [String] :tag_name
112
+ # Required. The name of the tag.
113
+ # @input params [String] :target_commitish
114
+ # Specifies the commitish value that determines where the Git tag
115
+ # is created from. Can be any branch or commit SHA. Defaults to
116
+ # the repository's default branch (usually 'master').
117
+ # Unused if the Git tag already exists.
118
+ # @input params [String] :name
119
+ # The name of the release.
120
+ # @input params [String] :body
121
+ # Text describing the contents of the tag.
122
+ # @input params [Boolean] :draft
123
+ # true to create a draft (unpublished) release,
124
+ # false to create a published one. Default: false
125
+ # @input params [Boolean] :prerelease
126
+ # true to identify the release as a prerelease.
127
+ # false to identify the release as a full release. Default: false
128
+ #
129
+ # @example
130
+ # github = Github.new
131
+ # github.repos.releases.edit 'owner', 'repo', 'id',
132
+ # tag_name: "v1.0.0",
133
+ # target_commitish: "master",
134
+ # name: "v1.0.0",
135
+ # body: "Description of the release",
136
+ # draft: false,
137
+ # prerelease: false
138
+ #
139
+ # @api public
140
+ def edit(*args)
141
+ arguments(args, required: [:owner, :repo, :id])
142
+
143
+ patch_request("/repos/#{arguments.owner}/#{arguments.repo}/releases/#{arguments.id}", arguments.params)
144
+ end
145
+ alias_method :update, :edit
146
+
147
+ # Delete a release
148
+ #
149
+ # Users with push access to the repository can delete a release.
150
+ #
151
+ # @see https://developer.github.com/v3/repos/releases/#delete-a-release
152
+ #
153
+ # @param [String] :owner
154
+ # @param [String] :repo
155
+ # @param [Integer] :id
156
+ #
157
+ # @example
158
+ # github = Github.new
159
+ # github.repos.releases.delete 'owner', 'repo', 'id'
160
+ #
161
+ # @api public
162
+ def delete(*args)
163
+ arguments(args, required: [:owner, :repo, :id]).params
164
+
165
+ delete_request("/repos/#{arguments.owner}/#{arguments.repo}/releases/#{arguments.id}", arguments.params)
166
+ end
167
+
168
+ # Get the latest release
169
+ #
170
+ # View the latest published full release for the repository.
171
+ # Draft releases and prereleases are not returned.
172
+ #
173
+ # @see https://developer.github.com/v3/repos/releases/#get-the-latest-release
174
+ #
175
+ # @param [String] :owner
176
+ # @param [String] :repo
177
+ #
178
+ # @example
179
+ # github = Github.new
180
+ # github.repos.releases.latest 'owner', 'repo'
181
+ #
182
+ # @api public
183
+ def latest(*args)
184
+ arguments(args, required: [:owner, :repo]).params
185
+
186
+ get_request("repos/#{arguments.owner}/#{arguments.repo}/releases/latest", arguments.params)
187
+ end
188
+ end # Client::Repos::Statuses
189
+ end # Github
@@ -0,0 +1,89 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../api'
4
+
5
+ module Github
6
+ # The Repository Statistics API allows you to fetch the data that GitHub uses
7
+ # for visualizing different types of repository activity.
8
+ class Client::Repos::Statistics < API
9
+
10
+ # Get contributors list with additions, deletions, and commit counts
11
+ #
12
+ # @example
13
+ # github = Github.new
14
+ # github.repos.stats.contributors user: '...', repo: '...'
15
+ # github.repos.stats.contributors user: '...', repo: '...' { |stat| ... }
16
+ #
17
+ # @api public
18
+ def contributors(*args)
19
+ arguments(args, required: [:user, :repo])
20
+
21
+ response = get_request("/repos/#{arguments.user}/#{arguments.repo}/stats/contributors", arguments.params)
22
+ return response unless block_given?
23
+ response.each { |el| yield el }
24
+ end
25
+
26
+ # Get the last year of commit activity data
27
+ #
28
+ # Returns the last year of commit activity grouped by week.
29
+ # The days array is a group of commits per day, starting on Sunday
30
+ #
31
+ # @example
32
+ # github = Github.new
33
+ # github.repos.stats.commit_activity user: '...', repo: '...'
34
+ # github.repos.stats.commit_activity user: '...', repo: '...' { |stat| ... }
35
+ #
36
+ # @api public
37
+ def commit_activity(*args)
38
+ arguments(args, required: [:user, :repo])
39
+
40
+ response = get_request("/repos/#{arguments.user}/#{arguments.repo}/stats/commit_activity", arguments.params)
41
+ return response unless block_given?
42
+ response.each { |el| yield el }
43
+ end
44
+
45
+ # Get the number of additions and deletions per week
46
+ #
47
+ # @example
48
+ # github = Github.new
49
+ # github.repos.stats.code_frequency user: '...', repo: '...'
50
+ # github.repos.stats.code_frequency user: '...', repo: '...' { |stat| ... }
51
+ #
52
+ # @api public
53
+ def code_frequency(*args)
54
+ arguments(args, required: [:user, :repo])
55
+
56
+ get_request("/repos/#{arguments.user}/#{arguments.repo}/stats/code_frequency", arguments.params)
57
+ end
58
+
59
+ # Get the weekly commit count for the repo owner and everyone else
60
+ #
61
+ # @example
62
+ # github = Github.new
63
+ # github.repos.stats.participation user: '...', repo: '...'
64
+ # github.repos.stats.participation user: '...', repo: '...' { |stat| ... }
65
+ #
66
+ # @api public
67
+ def participation(*args)
68
+ arguments(args, required: [:user, :repo])
69
+
70
+ get_request("/repos/#{arguments.user}/#{arguments.repo}/stats/participation", arguments.params)
71
+ end
72
+
73
+ # Get the number of commits per hour in each day
74
+ #
75
+ # @example
76
+ # github = Github.new
77
+ # github.repos.stats.punch_card user: '...', repo: '...'
78
+ # github.repos.stats.punch_card user: '...', repo: '...' { |stat| ... }
79
+ #
80
+ # @api public
81
+ def punch_card(*args)
82
+ arguments(args, required: [:user, :repo])
83
+
84
+ response = get_request("/repos/#{arguments.user}/#{arguments.repo}/stats/punch_card", arguments.params)
85
+ return response unless block_given?
86
+ response.each { |el| yield el }
87
+ end
88
+ end # Client::Repos::Statistics
89
+ end # Github
@@ -0,0 +1,91 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../api'
4
+
5
+ module Github
6
+ # The Status API allows external services to mark commits with a success,
7
+ # failure, error, or pending state, which is then reflected in pull requests
8
+ # involving those commits.
9
+ class Client::Repos::Statuses < API
10
+
11
+ VALID_STATUS_PARAM_NAMES = %w[
12
+ state
13
+ target_url
14
+ description
15
+ context
16
+ ].freeze # :nodoc:
17
+
18
+ REQUIRED_PARAMS = %w[ state ].freeze # :nodoc:
19
+
20
+ # List Statuses for a specific SHA
21
+ #
22
+ # @param [String] :ref
23
+ # Ref to fetch the status for. It can be a SHA, a branch name,
24
+ # or a tag name.
25
+ #
26
+ # @example
27
+ # github = Github.new
28
+ # github.repos.statuses.list 'user-name', 'repo-name', 'ref'
29
+ # github.repos.statuses.list 'user-name', 'repo-name', 'ref' { |status| ... }
30
+ #
31
+ # Get the combined Status for a specific Ref
32
+ #
33
+ # @example
34
+ # github = Github.new
35
+ # github.repos.statuses.list 'user', 'repo', 'ref', combined: true
36
+ #
37
+ # @api public
38
+ def list(*args)
39
+ arguments(args, required: [:user, :repo, :ref])
40
+ params = arguments.params
41
+ user, repo, ref = arguments.user, arguments.repo, arguments.ref
42
+
43
+ response = if params.delete('combined')
44
+ get_request("/repos/#{user}/#{repo}/commits/#{ref}/status", params)
45
+ else
46
+ get_request("/repos/#{user}/#{repo}/commits/#{ref}/statuses", params)
47
+ end
48
+ return response unless block_given?
49
+ response.each { |el| yield el }
50
+ end
51
+ alias :all :list
52
+
53
+ # Create a status
54
+ #
55
+ # @param [Hash] params
56
+ # @input params [String] :state
57
+ # Required. The state of the status. Can be one of pending,
58
+ # success, error, or failure.
59
+ # @input params [String] :target_url
60
+ # The target URL to associate with this status. This URL will
61
+ # be linked from the GitHub UI to allow users to easily see
62
+ # the ‘source’ of the Status.
63
+ #
64
+ # For example, if your Continuous Integration system is posting
65
+ # build status, you would want to provide the deep link for
66
+ # the build output for this specific SHA:
67
+ # http://ci.example.com/user/repo/build/sha.
68
+ # @input params [String] :description
69
+ # A short description of the status
70
+ # @input params [String] :context
71
+ # A string label to differentiate this status from the
72
+ # status of other systems. Default: "default"
73
+ #
74
+ # @example
75
+ # github = Github.new
76
+ # github.repos.statuses.create 'user-name', 'repo-name', 'sha',
77
+ # state: "success",
78
+ # target_url: "http://ci.example.com/johndoe/my-repo/builds/sha",
79
+ # description: "Successful build #3 from origin/master"
80
+ #
81
+ # @api public
82
+ def create(*args)
83
+ arguments(args, required: [:user, :repo, :sha]) do
84
+ permit VALID_STATUS_PARAM_NAMES, recursive: false
85
+ assert_required REQUIRED_PARAMS
86
+ end
87
+
88
+ post_request("/repos/#{arguments.user}/#{arguments.repo}/statuses/#{arguments.sha}", arguments.params)
89
+ end
90
+ end # Client::Repos::Statuses
91
+ end # Github