UNPKG

synergia-jira-connector

Version:

Easy to use NodeJS wrapper for the Jira REST API.

292 lines (264 loc) 11.4 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: api/project.js</title> <script src="scripts/prettify/prettify.js"></script> <script src="scripts/prettify/lang-css.js"></script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Source: api/project.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>"use strict"; module.exports = ProjectClient; /** * Used to access Jira REST endpoints in '/rest/api/2/project' * @param {JiraClient} jiraClient * @constructor ProjectClient */ function ProjectClient(jiraClient) { this.jiraClient = jiraClient; /** * Returns all projects which are visible for the currently logged in user. If no user is logged in, it returns the * list of projects that are visible when using anonymous access. * * @method getAllProjects * @memberOf ProjectClient# * @param opts Ignored * @param callback Called when the projects have been retrieved. */ this.getAllProjects = function (opts, callback) { var options = { uri: this.jiraClient.buildURL('/project'), method: 'GET', json: true, followAllRedirects: true }; this.jiraClient.makeRequest(options, callback); }; /** * Contains a full representation of a project in JSON format. * * All project keys associated with the project will only be returned if expand=projectKeys. * * @method getProject * @memberOf ProjectClient# * @param opts The request options sent to the Jira API. * @param opts.projectIdOrKey The project id or project key * @param callback Called when the project is retrieved. */ this.getProject = function (opts, callback) { var options = this.buildRequestOptions(opts, '', 'GET'); this.jiraClient.makeRequest(options, callback); }; /** * Contains a full representation of a the specified project's components. * * @method getComponents * @memberOf ProjectClient# * @param opts The request options sent to the Jira API. * @param opts.projectIdOrKey The project id or project key * @param callback Called when the components are retrieved. */ this.getComponents = function (opts, callback) { var options = this.buildRequestOptions(opts, '/components', 'GET'); this.jiraClient.makeRequest(options, callback); }; /** * Get all issue types with valid status values for a project * * @method getStatuses * @memberOf ProjectClient# * @param opts The request options sent to the Jira API. * @param opts.projectIdOrKey The project id or project key * @param callback Called when the statuses have been retrieved. */ this.getStatuses = function (opts, callback) { var options = this.buildRequestOptions(opts, '/statuses', 'GET'); this.jiraClient.makeRequest(options, callback); }; /** * Contains a full representation of a the specified project's versions. * * @method getVersions * @memberOf ProjectClient# * @param opts The request options sent to the Jira API. * @param opts.projectIdOrKey The project id or project key * @param callback Called when the versions have been retrieved. */ this.getVersions = function (opts, callback) { var options = this.buildRequestOptions(opts, '/versions', 'GET'); this.jiraClient.makeRequest(options, callback); }; /** * Contains a list of roles in this project with links to full details. * * @method getRoles * @memberOf ProjectClient# * @param opts The request options sent to the Jira API. * @param opts.projectIdOrKey The project id or project key * @param callback Called when the roles have been retrieved. */ this.getRoles = function (opts, callback) { var options = this.buildRequestOptions(opts, '/role', 'GET'); this.jiraClient.makeRequest(options, callback); }; /** * Details on a given project role. * * @method getRole * @memberOf ProjectClient# * @param opts The request options sent to the Jira API. * @param opts.projectIdOrKey The project id or project key * @param opts.roleId The id of the role to retrieve. * @param callback Called when the roles have been retrieved. */ this.getRole = function (opts, callback) { var options = this.buildRequestOptions(opts, '/role/' + opts.roleId, 'GET'); this.jiraClient.makeRequest(options, callback); }; /** * Updates a project role to contain the sent actors. * * @method updateRole * @memberOf ProjectClient# * @param opts The request options sent to the Jira API. * @param opts.projectIdOrKey The project id or project key * @param opts.roleId The id of the role to retrieve. * @param opts.newRole See {@link https://docs.atlassian.com/jira/REST/latest/#d2e108} * @param callback Called when the roles have been retrieved. */ this.updateRole = function (opts, callback) { var options = this.buildRequestOptions(opts, '/role/' + opts.roleId, 'PUT', opts.newRole); this.jiraClient.makeRequest(options, callback); }; /** * Add an actor to a project role. * * @method addToRole * @memberOf ProjectClient# * @param opts The request options sent to the Jira API. * @param opts.projectIdOrKey The project id or project key * @param opts.roleId The id of the role to retrieve. * @param opts.newRole See {@link https://docs.atlassian.com/jira/REST/latest/#d2e134} * @param callback Called when the roles have been retrieved. */ this.addToRole = function (opts, callback) { var options = this.buildRequestOptions(opts, '/role/' + opts.roleId, 'POST', opts.newRole); this.jiraClient.makeRequest(options, callback); }; /** * Build out the request options necessary to make a particular API call. * * @private * @method buildRequestOptions * @memberOf ProjectClient# * @param {Object} opts The arguments passed to the method. * @param {number} opts.projectIdOrKey The id of the project to use in the path. * @param {Array} [opts.fields] The fields to include * @param {Array} [opts.expand] The fields to expand * @param {string} path The path of the endpoint following /project/{id} * @param {string} method The request method. * @param {Object} [body] The request body, if any. * @param {Object} [qs] The querystring, if any. opts.expand and opts.fields arrays will be automagically added. * @returns {{uri: string, method: string, body: Object, qs: Object, followAllRedirects: boolean, json: boolean}} */ this.buildRequestOptions = function (opts, path, method, body, qs) { var basePath = '/project/' + opts.projectIdOrKey; if (!qs) qs = {}; if (!body) body = {}; if (opts.fields) { qs.fields = ''; opts.fields.forEach(function (field) { qs.fields += field + ',' }); qs.fields = qs.fields.slice(0, -1); } if (opts.expand) { qs.expand = ''; opts.expand.forEach(function (ex) { qs.expand += ex + ',' }); qs.expand = qs.expand.slice(0, -1); } return { uri: this.jiraClient.buildURL(basePath + path), method: method, body: body, qs: qs, followAllRedirects: true, json: true }; }; }</code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2> <h3>Classes</h3> <ul> <li><a href="ApplicationPropertiesClient.html">ApplicationPropertiesClient</a></li> <li><a href="AttachmentClient.html">AttachmentClient</a></li> <li><a href="AuditingClient.html">AuditingClient</a></li> <li><a href="AvatarClient.html">AvatarClient</a></li> <li><a href="CommentClient.html">CommentClient</a></li> <li><a href="ComponentClient.html">ComponentClient</a></li> <li><a href="CustomFieldOptionClient.html">CustomFieldOptionClient</a></li> <li><a href="DashboardClient.html">DashboardClient</a></li> <li><a href="FieldClient.html">FieldClient</a></li> <li><a href="FilterClient.html">FilterClient</a></li> <li><a href="GroupClient.html">GroupClient</a></li> <li><a href="GroupsClient.html">GroupsClient</a></li> <li><a href="GroupUserPickerClient.html">GroupUserPickerClient</a></li> <li><a href="IssueClient.html">IssueClient</a></li> <li><a href="IssueLinkClient.html">IssueLinkClient</a></li> <li><a href="IssueLinkTypeClient.html">IssueLinkTypeClient</a></li> <li><a href="IssueTypeClient.html">IssueTypeClient</a></li> <li><a href="JiraClient.html">JiraClient</a></li> <li><a href="JqlClient.html">JqlClient</a></li> <li><a href="LicenseRoleClient.html">LicenseRoleClient</a></li> <li><a href="LicenseValidatorClient.html">LicenseValidatorClient</a></li> <li><a href="MyPermissionsClient.html">MyPermissionsClient</a></li> <li><a href="MyPreferencesClient.html">MyPreferencesClient</a></li> <li><a href="MyselfClient.html">MyselfClient</a></li> <li><a href="PasswordClient.html">PasswordClient</a></li> <li><a href="PriorityClient.html">PriorityClient</a></li> <li><a href="ProjectCategoryClient.html">ProjectCategoryClient</a></li> <li><a href="ProjectClient.html">ProjectClient</a></li> <li><a href="ProjectValidateClient.html">ProjectValidateClient</a></li> <li><a href="ReindexClient.html">ReindexClient</a></li> <li><a href="ResolutionClient.html">ResolutionClient</a></li> <li><a href="ScreensClient.html">ScreensClient</a></li> <li><a href="SearchClient.html">SearchClient</a></li> <li><a href="SecurityLevelClient.html">SecurityLevelClient</a></li> <li><a href="ServerInfoClient.html">ServerInfoClient</a></li> <li><a href="SettingsClient.html">SettingsClient</a></li> <li><a href="StatusCategoryClient.html">StatusCategoryClient</a></li> <li><a href="StatusClient.html">StatusClient</a></li> <li><a href="UserClient.html">UserClient</a></li> <li><a href="VersionClient.html">VersionClient</a></li> <li><a href="WorkflowClient.html">WorkflowClient</a></li> <li><a href="WorkflowSchemeClient.html">WorkflowSchemeClient</a></li> </ul> <h3>Namespaces</h3> <ul> <li><a href="OauthUtil.html">OauthUtil</a></li> </ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha13</a> on Tue Nov 10 2015 11:10:10 GMT-0600 (CST) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"></script> </body> </html>