File: projects.rb

package info (click to toggle)
ruby-octokit 10.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,092 kB
  • sloc: ruby: 13,339; sh: 99; makefile: 7; javascript: 3
file content (294 lines) | stat: -rw-r--r-- 11,334 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# frozen_string_literal: true

module Octokit
  class Client
    # Methods for Projects API
    #
    # @see https://docs.github.com/en/rest/projects
    module Projects
      # List projects for a repository
      #
      # Requires authenticated client
      #
      # @param repo [Integer, String, Repository, Hash] A GitHub repository
      # @return [Array<Sawyer::Resource>] Repository projects
      # @see https://developer.github.com/v3/projects/#list-repository-projects
      # @example
      #   @client.projects('octokit/octokit.rb')
      def projects(repo, options = {})
        paginate "#{Repository.path repo}/projects", options
      end

      # Create a project
      #
      # Requires authenticated client
      #
      # @param repo [Integer, String, Repository, Hash] A GitHub repository
      # @param name [String] Project name
      # @option options [String] :body Body of the project
      # @return [Sawyer::Resource] Fresh new project
      # @see https://developer.github.com/v3/projects/#create-a-repository-project
      # @example Create project with only a name
      #   @client.create_project('octokit/octokit.rb', 'implement new APIs')
      #
      # @example Create project with name and body
      #   @client.create_project('octokit/octokit.rb', 'bugs be gone', body: 'Fix all the bugs @joeyw creates')
      def create_project(repo, name, options = {})
        options[:name] = name
        post "#{Repository.path repo}/projects", options
      end

      # List organization projects
      #
      # Requires authenticated client
      #
      # @param org [String] A GitHub organization
      # @return [Array<Sawyer::Resource>] Organization projects
      # @see https://developer.github.com/v3/projects/#list-organization-projects
      # @example
      #   @client.org_projects("octokit")
      def org_projects(org, options = {})
        paginate "orgs/#{org}/projects", options
      end
      alias organization_projects org_projects

      # Create organization project
      #
      # Requires authenticated client
      #
      # @param org [String] A GitHub organization
      # @param name [String] Project name
      # @option options [String] :body Project body
      # @return [Sawyer::Resource] Organization project
      # @see https://developer.github.com/v3/projects/#create-an-organization-project
      # @example Create with only a name
      #   @client.create_org_project("octocat", "make more octocats")
      # @example Create a project with name and body
      #   @client.create_org_project("octokit", "octocan", body: 'Improve clients')
      def create_org_project(org, name, options = {})
        options[:name] = name
        post "orgs/#{org}/projects", options
      end
      alias create_organization_project create_org_project

      # Get a project by id
      #
      # @param id [Integer] Project id
      # @return [Sawyer::Resource] Project
      # @see https://developer.github.com/v3/projects/#get-a-project
      # @example
      #   Octokit.project(123942)
      def project(id, options = {})
        get "projects/#{id}", options
      end

      # Update a project
      #
      # Requires authenticated client
      #
      # @param id [Integer] Project id
      # @option options [String] :name Project name
      # @option options [String] :body Project body
      # @return [Sawyer::Resource] Project
      # @see https://developer.github.com/v3/projects/#update-a-project
      # @example Update project name
      #   @client.update_project(123942, name: 'New name')
      def update_project(id, options = {})
        patch "projects/#{id}", options
      end

      # Delete a project
      #
      # Requires authenticated client
      #
      # @param id [Integer] Project id
      # @return [Boolean] Result of deletion
      # @see https://developer.github.com/v3/projects/#delete-a-project
      # @example
      #   @client.delete_project(123942)
      def delete_project(id, options = {})
        boolean_from_response :delete, "projects/#{id}", options
      end

      # List project columns
      #
      # @param id [Integer] Project id
      # @return [Array<Sawyer::Resource>] List of project columns
      # @see https://developer.github.com/v3/projects/columns/#list-project-columns
      # @example
      #   @client.project_columns(123942)
      def project_columns(id, options = {})
        paginate "projects/#{id}/columns", options
      end

      # Create a project column
      #
      # Requires authenticated client
      #
      # @param id [Integer] Project column id
      # @param name [String] New column name
      # @return [Sawyer::Resource] Newly created column
      # @see https://developer.github.com/v3/projects/columns/#create-a-project-column
      # @example
      #   @client.create_project_column(123942, "To Dones")
      def create_project_column(id, name, options = {})
        options[:name] = name
        post "projects/#{id}/columns", options
      end

      # Get a project column by ID
      #
      # @param id [Integer] Project column id
      # @return [Sawyer::Resource] Project column
      # @see https://developer.github.com/v3/projects/columns/#get-a-project-column
      # @example
      #   Octokit.project_column(30294)
      def project_column(id, options = {})
        get "projects/columns/#{id}", options
      end

      # Update a project column
      #
      # Requires authenticated client
      #
      # @param id [Integer] Project column id
      # @param name [String] New column name
      # @return [Sawyer::Resource] Updated column
      # @see https://developer.github.com/v3/projects/columns/#update-a-project-column
      # @example
      #   @client.update_project_column(30294, "new column name")
      def update_project_column(id, name, options = {})
        options[:name] = name
        patch "projects/columns/#{id}", options
      end

      # Delete a project column
      #
      # Requires authenticated client
      #
      # @param id [Integer] Project column id
      # @return [Boolean] Result of deletion request, true when deleted
      # @see https://developer.github.com/v3/projects/columns/#delete-a-project-column
      # @example
      #   @client.delete_project_column(30294)
      def delete_project_column(id, options = {})
        boolean_from_response :delete, "projects/columns/#{id}", options
      end

      # Move a project column
      #
      # Requires authenticated client
      #
      # @param id [Integer] Project column id
      # @param position [String] New position for the column. Can be one of
      #   <tt>first</tt>, <tt>last</tt>, or <tt>after:<column-id></tt>, where
      #   <tt><column-id></tt> is the id value of a column in the same project.
      # @return [Sawyer::Resource] Result
      # @see https://developer.github.com/v3/projects/columns/#move-a-project-column
      # @example
      #   @client.move_project_column(30294, "last")
      def move_project_column(id, position, options = {})
        options[:position] = position
        post "projects/columns/#{id}/moves", options
      end

      # List columns cards
      #
      # Requires authenticated client
      #
      # @param id [Integer] Project column id
      # @return [Array<Sawyer::Resource>] Cards in the column
      # @see https://developer.github.com/v3/projects/cards/#list-project-cards
      # @example
      #   @client.column_cards(30294)
      def column_cards(id, options = {})
        paginate "projects/columns/#{id}/cards", options
      end

      # Create project card
      #
      # Requires authenticated client
      #
      # @param id [Integer] Project column id
      # @option options [String] :note Card contents for a note type
      # @option options [Integer] :content_id Issue ID for the card contents
      # @option options [String] :content_type Type of content to associate
      #   with the card. <tt>Issue</tt> is presently the only avaiable value
      # @note If :note is supplied, :content_id and :content_type must be
      #   excluded. Similarly, if :content_id is supplied, :content_type must
      #   be set and :note must not be included.
      # @return [Sawyer::Resource] Newly created card
      # @see https://developer.github.com/v3/projects/cards/#create-a-project-card
      # @example Create a project card with a note
      #   @client.create_project_card(123495, note: 'New note card')
      # @example Create a project card for an repository issue
      #   @client.create_project_card(123495, content_id: 1, content_type: 'Issue')
      def create_project_card(id, options = {})
        post "projects/columns/#{id}/cards", options
      end

      # Get a project card
      #
      # Requires authenticated client
      #
      # @param id [Integer] Project card id
      # @return [Sawyer::Resource] Project card
      # @see https://developer.github.com/v3/projects/cards/#get-a-project-card
      # @example
      #   @client.project_card(123495)
      def project_card(id, options = {})
        get "projects/columns/cards/#{id}", options
      end

      # Update a project card
      #
      # Requires authenticated client
      #
      # @param id [Integer] Project card id
      # @option options [String] :note The card's note content. Only valid for
      #   cards without another type of content, so this cannot be specified if
      #   the card already has a content_id and content_type.
      # @return [Sawyer::Resource] Updated project card
      # @see https://developer.github.com/v3/projects/cards/#update-a-project-card
      # @example
      #   @client.update_project_card(12345, note: 'new note')
      def update_project_card(id, options = {})
        patch "projects/columns/cards/#{id}", options
      end

      # Move a project card
      #
      # Requires authenticated client
      #
      # @param id [Integer] Project card id
      # @param position [String] Can be one of <tt>top</tt>, <tt>bottom</tt>,
      #   or <tt>after:<card-id></tt>, where <card-id> is the id value of a
      #   card in the same column, or in the new column specified by column_id.
      # @option options [Integer] :column_id The column id to move the card to,
      #   must be column in same project
      # @return [Sawyer::Resource] Empty sawyer resource
      # @see https://developer.github.com/v3/projects/cards/#move-a-project-card
      # @example Move a card to the bottom of the same column
      #   @client.move_project_card(123495, 'bottom')
      # @example Move a card to the top of another column
      #   @client.move_project_card(123495, 'top', column_id: 59402)
      def move_project_card(id, position, options = {})
        options[:position] = position
        post "projects/columns/cards/#{id}/moves", options
      end

      # Delete a project card
      #
      # Requires authenticated client
      #
      # @param id [Integer] Project card id
      # @return [Boolean] True of deleted, false otherwise
      # @see https://developer.github.com/v3/projects/cards/#delete-a-project-card
      # @example
      #   @client.delete_project_card(123495)
      def delete_project_card(id, options = {})
        boolean_from_response :delete, "projects/columns/cards/#{id}", options
      end
    end # Projects
  end
end