-
Notifications
You must be signed in to change notification settings - Fork 800
Expand file tree
/
Copy pathProject.js
More file actions
236 lines (217 loc) · 8.62 KB
/
Project.js
File metadata and controls
236 lines (217 loc) · 8.62 KB
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
/**
* @file
* @copyright 2013 Michael Aufreiter (Development Seed) and 2016 Yahoo Inc.
* @license Licensed under {@link https://spdx.org/licenses/BSD-3-Clause-Clear.html BSD-3-Clause-Clear}.
* Github.js is freely distributable.
*/
import Requestable from './Requestable';
/**
* Project encapsulates the functionality to create, query, and modify cards and columns.
*/
class Project extends Requestable {
/**
* Create a Project.
* @param {string} id - the id of the project
* @param {Requestable.auth} [auth] - information required to authenticate to Github
* @param {string} [apiBase=https://api.github.com] - the base Github API URL
*/
constructor(id, auth, apiBase) {
super(auth, apiBase, 'inertia-preview');
this.__id = id;
}
/**
* Get information about a project
* @see https://developer.github.com/v3/projects/#get-a-project
* @param {Requestable.callback} cb - will receive the project information
* @return {Promise} - the promise for the http request
*/
getProject(cb) {
return this._request('GET', `/projects/${this.__id}`, null, cb);
}
/**
* Edit a project
* @see https://developer.github.com/v3/projects/#update-a-project
* @param {Object} options - the description of the project
* @param {Requestable.callback} cb - will receive the modified project
* @return {Promise} - the promise for the http request
*/
updateProject(options, cb) {
return this._request('PATCH', `/projects/${this.__id}`, options, cb);
}
/**
* Delete a project
* @see https://developer.github.com/v3/projects/#delete-a-project
* @param {Requestable.callback} cb - will receive true if the operation is successful
* @return {Promise} - the promise for the http request
*/
deleteProject(cb) {
return this._request('DELETE', `/projects/${this.__id}`, null, cb);
}
/**
* Get information about all columns of a project
* @see https://developer.github.com/v3/projects/columns/#list-project-columns
* @param {Requestable.callback} [cb] - will receive the list of columns
* @return {Promise} - the promise for the http request
*/
listProjectColumns(cb) {
return this._requestAllPages(`/projects/${this.__id}/columns`, null, cb);
}
/**
* Get information about a column
* @see https://developer.github.com/v3/projects/columns/#get-a-project-column
* @param {string} colId - the id of the column
* @param {Requestable.callback} cb - will receive the column information
* @return {Promise} - the promise for the http request
*/
getProjectColumn(colId, cb) {
return this._request('GET', `/projects/columns/${colId}`, null, cb);
}
/**
* Create a new column
* @see https://developer.github.com/v3/projects/columns/#create-a-project-column
* @param {Object} options - the description of the column
* @param {Requestable.callback} cb - will receive the newly created column
* @return {Promise} - the promise for the http request
*/
createProjectColumn(options, cb) {
return this._request('POST', `/projects/${this.__id}/columns`, options, cb);
}
/**
* Edit a column
* @see https://developer.github.com/v3/projects/columns/#update-a-project-column
* @param {string} colId - the column id
* @param {Object} options - the description of the column
* @param {Requestable.callback} cb - will receive the modified column
* @return {Promise} - the promise for the http request
*/
updateProjectColumn(colId, options, cb) {
return this._request('PATCH', `/projects/columns/${colId}`, options, cb);
}
/**
* Delete a column
* @see https://developer.github.com/v3/projects/columns/#delete-a-project-column
* @param {string} colId - the column to be deleted
* @param {Requestable.callback} cb - will receive true if the operation is successful
* @return {Promise} - the promise for the http request
*/
deleteProjectColumn(colId, cb) {
return this._request('DELETE', `/projects/columns/${colId}`, null, cb);
}
/**
* Move a column
* @see https://developer.github.com/v3/projects/columns/#move-a-project-column
* @param {string} colId - the column to be moved
* @param {string} position - can be one of first, last, or after:<column-id>,
* where <column-id> is the id value of a column in the same project.
* @param {Requestable.callback} cb - will receive true if the operation is successful
* @return {Promise} - the promise for the http request
*/
moveProjectColumn(colId, position, cb) {
return this._request(
'POST',
`/projects/columns/${colId}/moves`,
{position: position},
cb
);
}
/**
* Get information about all cards of a project
* @see https://developer.github.com/v3/projects/cards/#list-project-cards
* @param {Requestable.callback} [cb] - will receive the list of cards
* @return {Promise} - the promise for the http request
*/
listProjectCards(cb) {
return this.listProjectColumns()
.then(({data}) => {
return Promise.all(data.map((column) => {
return this._requestAllPages(`/projects/columns/${column.id}/cards`, null);
}));
}).then((cardsInColumns) => {
const cards = cardsInColumns.reduce((prev, {data}) => {
prev.push(...data);
return prev;
}, []);
if (cb) {
cb(null, cards);
}
return cards;
}).catch((err) => {
if (cb) {
cb(err);
return;
}
throw err;
});
}
/**
* Get information about all cards of a column
* @see https://developer.github.com/v3/projects/cards/#list-project-cards
* @param {string} colId - the id of the column
* @param {Requestable.callback} [cb] - will receive the list of cards
* @return {Promise} - the promise for the http request
*/
listColumnCards(colId, cb) {
return this._requestAllPages(`/projects/columns/${colId}/cards`, null, cb);
}
/**
* Get information about a card
* @see https://developer.github.com/v3/projects/cards/#get-a-project-card
* @param {string} cardId - the id of the card
* @param {Requestable.callback} cb - will receive the card information
* @return {Promise} - the promise for the http request
*/
getProjectCard(cardId, cb) {
return this._request('GET', `/projects/columns/cards/${cardId}`, null, cb);
}
/**
* Create a new card
* @see https://developer.github.com/v3/projects/cards/#create-a-project-card
* @param {string} colId - the column id
* @param {Object} options - the description of the card
* @param {Requestable.callback} cb - will receive the newly created card
* @return {Promise} - the promise for the http request
*/
createProjectCard(colId, options, cb) {
return this._request('POST', `/projects/columns/${colId}/cards`, options, cb);
}
/**
* Edit a card
* @see https://developer.github.com/v3/projects/cards/#update-a-project-card
* @param {string} cardId - the card id
* @param {Object} options - the description of the card
* @param {Requestable.callback} cb - will receive the modified card
* @return {Promise} - the promise for the http request
*/
updateProjectCard(cardId, options, cb) {
return this._request('PATCH', `/projects/columns/cards/${cardId}`, options, cb);
}
/**
* Delete a card
* @see https://developer.github.com/v3/projects/cards/#delete-a-project-card
* @param {string} cardId - the card to be deleted
* @param {Requestable.callback} cb - will receive true if the operation is successful
* @return {Promise} - the promise for the http request
*/
deleteProjectCard(cardId, cb) {
return this._request('DELETE', `/projects/columns/cards/${cardId}`, null, cb);
}
/**
* Move a card
* @see https://developer.github.com/v3/projects/cards/#move-a-project-card
* @param {string} cardId - the card to be moved
* @param {string} position - can be one of top, bottom, or after:<card-id>,
* where <card-id> is the id value of a card in the same project.
* @param {string} colId - the id value of a column in the same project.
* @param {Requestable.callback} cb - will receive true if the operation is successful
* @return {Promise} - the promise for the http request
*/
moveProjectCard(cardId, position, colId, cb) {
return this._request(
'POST',
`/projects/columns/cards/${cardId}/moves`,
{position: position, column_id: colId}, // eslint-disable-line camelcase
cb
);
}
}
module.exports = Project;