UNPKG

9.17 kBSource Map (JSON)View Raw
1{"version":3,"names":[],"mappings":"","sources":["Project.js"],"sourcesContent":["/**\n * @file\n * @copyright 2013 Michael Aufreiter (Development Seed) and 2016 Yahoo Inc.\n * @license Licensed under {@link https://spdx.org/licenses/BSD-3-Clause-Clear.html BSD-3-Clause-Clear}.\n * Github.js is freely distributable.\n */\n\nimport Requestable from './Requestable';\n\n/**\n * Project encapsulates the functionality to create, query, and modify cards and columns.\n */\nclass Project extends Requestable {\n /**\n * Create a Project.\n * @param {string} id - the id of the project\n * @param {Requestable.auth} [auth] - information required to authenticate to Github\n * @param {string} [apiBase=https://api.github.com] - the base Github API URL\n */\n constructor(id, auth, apiBase) {\n super(auth, apiBase, 'inertia-preview');\n this.__id = id;\n }\n\n /**\n * Get information about a project\n * @see https://developer.github.com/v3/projects/#get-a-project\n * @param {Requestable.callback} cb - will receive the project information\n * @return {Promise} - the promise for the http request\n */\n getProject(cb) {\n return this._request('GET', `/projects/${this.__id}`, null, cb);\n }\n\n /**\n * Edit a project\n * @see https://developer.github.com/v3/projects/#update-a-project\n * @param {Object} options - the description of the project\n * @param {Requestable.callback} cb - will receive the modified project\n * @return {Promise} - the promise for the http request\n */\n updateProject(options, cb) {\n return this._request('PATCH', `/projects/${this.__id}`, options, cb);\n }\n\n /**\n * Delete a project\n * @see https://developer.github.com/v3/projects/#delete-a-project\n * @param {Requestable.callback} cb - will receive true if the operation is successful\n * @return {Promise} - the promise for the http request\n */\n deleteProject(cb) {\n return this._request('DELETE', `/projects/${this.__id}`, null, cb);\n }\n\n /**\n * Get information about all columns of a project\n * @see https://developer.github.com/v3/projects/columns/#list-project-columns\n * @param {Requestable.callback} [cb] - will receive the list of columns\n * @return {Promise} - the promise for the http request\n */\n listProjectColumns(cb) {\n return this._requestAllPages(`/projects/${this.__id}/columns`, null, cb);\n }\n\n /**\n * Get information about a column\n * @see https://developer.github.com/v3/projects/columns/#get-a-project-column\n * @param {string} colId - the id of the column\n * @param {Requestable.callback} cb - will receive the column information\n * @return {Promise} - the promise for the http request\n */\n getProjectColumn(colId, cb) {\n return this._request('GET', `/projects/columns/${colId}`, null, cb);\n }\n\n /**\n * Create a new column\n * @see https://developer.github.com/v3/projects/columns/#create-a-project-column\n * @param {Object} options - the description of the column\n * @param {Requestable.callback} cb - will receive the newly created column\n * @return {Promise} - the promise for the http request\n */\n createProjectColumn(options, cb) {\n return this._request('POST', `/projects/${this.__id}/columns`, options, cb);\n }\n\n /**\n * Edit a column\n * @see https://developer.github.com/v3/projects/columns/#update-a-project-column\n * @param {string} colId - the column id\n * @param {Object} options - the description of the column\n * @param {Requestable.callback} cb - will receive the modified column\n * @return {Promise} - the promise for the http request\n */\n updateProjectColumn(colId, options, cb) {\n return this._request('PATCH', `/projects/columns/${colId}`, options, cb);\n }\n\n /**\n * Delete a column\n * @see https://developer.github.com/v3/projects/columns/#delete-a-project-column\n * @param {string} colId - the column to be deleted\n * @param {Requestable.callback} cb - will receive true if the operation is successful\n * @return {Promise} - the promise for the http request\n */\n deleteProjectColumn(colId, cb) {\n return this._request('DELETE', `/projects/columns/${colId}`, null, cb);\n }\n\n /**\n * Move a column\n * @see https://developer.github.com/v3/projects/columns/#move-a-project-column\n * @param {string} colId - the column to be moved\n * @param {string} position - can be one of first, last, or after:<column-id>,\n * where <column-id> is the id value of a column in the same project.\n * @param {Requestable.callback} cb - will receive true if the operation is successful\n * @return {Promise} - the promise for the http request\n */\n moveProjectColumn(colId, position, cb) {\n return this._request(\n 'POST',\n `/projects/columns/${colId}/moves`,\n {position: position},\n cb\n );\n }\n\n /**\n * Get information about all cards of a project\n * @see https://developer.github.com/v3/projects/cards/#list-project-cards\n * @param {Requestable.callback} [cb] - will receive the list of cards\n * @return {Promise} - the promise for the http request\n */\n listProjectCards(cb) {\n return this.listProjectColumns()\n .then(({data}) => {\n return Promise.all(data.map((column) => {\n return this._requestAllPages(`/projects/columns/${column.id}/cards`, null);\n }));\n }).then((cardsInColumns) => {\n const cards = cardsInColumns.reduce((prev, {data}) => {\n prev.push(...data);\n return prev;\n }, []);\n if (cb) {\n cb(null, cards);\n }\n return cards;\n }).catch((err) => {\n if (cb) {\n cb(err);\n return;\n }\n throw err;\n });\n }\n\n /**\n * Get information about all cards of a column\n * @see https://developer.github.com/v3/projects/cards/#list-project-cards\n * @param {string} colId - the id of the column\n * @param {Requestable.callback} [cb] - will receive the list of cards\n * @return {Promise} - the promise for the http request\n */\n listColumnCards(colId, cb) {\n return this._requestAllPages(`/projects/columns/${colId}/cards`, null, cb);\n }\n\n /**\n * Get information about a card\n * @see https://developer.github.com/v3/projects/cards/#get-a-project-card\n * @param {string} cardId - the id of the card\n * @param {Requestable.callback} cb - will receive the card information\n * @return {Promise} - the promise for the http request\n */\n getProjectCard(cardId, cb) {\n return this._request('GET', `/projects/columns/cards/${cardId}`, null, cb);\n }\n\n /**\n * Create a new card\n * @see https://developer.github.com/v3/projects/cards/#create-a-project-card\n * @param {string} colId - the column id\n * @param {Object} options - the description of the card\n * @param {Requestable.callback} cb - will receive the newly created card\n * @return {Promise} - the promise for the http request\n */\n createProjectCard(colId, options, cb) {\n return this._request('POST', `/projects/columns/${colId}/cards`, options, cb);\n }\n\n /**\n * Edit a card\n * @see https://developer.github.com/v3/projects/cards/#update-a-project-card\n * @param {string} cardId - the card id\n * @param {Object} options - the description of the card\n * @param {Requestable.callback} cb - will receive the modified card\n * @return {Promise} - the promise for the http request\n */\n updateProjectCard(cardId, options, cb) {\n return this._request('PATCH', `/projects/columns/cards/${cardId}`, options, cb);\n }\n\n /**\n * Delete a card\n * @see https://developer.github.com/v3/projects/cards/#delete-a-project-card\n * @param {string} cardId - the card to be deleted\n * @param {Requestable.callback} cb - will receive true if the operation is successful\n * @return {Promise} - the promise for the http request\n */\n deleteProjectCard(cardId, cb) {\n return this._request('DELETE', `/projects/columns/cards/${cardId}`, null, cb);\n }\n\n /**\n * Move a card\n * @see https://developer.github.com/v3/projects/cards/#move-a-project-card\n * @param {string} cardId - the card to be moved\n * @param {string} position - can be one of top, bottom, or after:<card-id>,\n * where <card-id> is the id value of a card in the same project.\n * @param {string} colId - the id value of a column in the same project.\n * @param {Requestable.callback} cb - will receive true if the operation is successful\n * @return {Promise} - the promise for the http request\n */\n moveProjectCard(cardId, position, colId, cb) {\n return this._request(\n 'POST',\n `/projects/columns/cards/${cardId}/moves`,\n {position: position, column_id: colId}, // eslint-disable-line camelcase\n cb\n );\n }\n}\n\nmodule.exports = Project;\n"],"file":"Project.js"}
\No newline at end of file