synergia-jira-connector
Version:
Easy to use NodeJS wrapper for the Jira REST API.
358 lines (325 loc) • 14.5 kB
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: api/version.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/version.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>"use strict";
module.exports = VersionClient;
/**
* Used to access Jira REST endpoints in '/rest/api/2/version'
* @param {JiraClient} jiraClient
* @constructor VersionClient
*/
function VersionClient(jiraClient) {
this.jiraClient = jiraClient;
/**
* Creates a version
*
* @method createVersion
* @memberOf VersionClient#
* @param {Object} opts The request options sent to Jira.
* @param {Object} opts.version See {@link https://docs.atlassian.com/jira/REST/latest/#d2e3549}
* @param callback Called when the version has been created.
*/
this.createVersion = function (opts, callback) {
var options = {
uri: this.jiraClient.buildURL('/version'),
method: 'POST',
json: true,
followAllRedirects: true,
body: opts.version
};
this.jiraClient.makeRequest(options, callback);
};
/**
* Modify a version's sequence within a project. The move version bean has 2 alternative field value pairs
* (opts.position or opts.after). One and only one of these two must be provided.
*
* @method moveVersion
* @memberOf VersionClient#
* @param {Object} opts The request options sent to the Jira API.
* @param {string} opts.versionId The id of the version to move.
* @param {string} [opts.position] An absolute position, which may have a value of 'First', 'Last', 'Earlier' or
* 'Later'. Must be provided if opts.after is missing.
* @param {string} [opts.after] A version to place this version after. The value should be the self link of another
* version. Must be provided if opts.position is missing
* @param callback Called when the version has been moved.
*/
this.moveVersion = function (opts, callback) {
var options = this.buildRequestOptions(opts, '/move', 'POST', {position: opts.position, after: opts.after});
this.jiraClient.makeRequest(options, callback);
};
/**
* Get a project version.
*
* @method getVersion
* @memberOf VersionClient#
* @param {Object} opts The request options sent to the Jira API.
* @param {string|number} opts.versionId The id of the version to retrieve.
* @param callback Called when the version is retrieved.
*/
this.getVersion = function (opts, callback) {
var options = this.buildRequestOptions(opts, '', 'GET');
this.jiraClient.makeRequest(options, callback);
};
/**
* Modify an existing version; any omitted fields will be ignored.
*
* @method createVersion
* @memberOf VersionClient#
* @param {Object} opts The request options sent to Jira.
* @param {string} opts.versionId The id of the version to edit.
* @param {Object} opts.version See {@link https://docs.atlassian.com/jira/REST/latest/#d2e3619}
* @param callback Called when the version has been modified.
*/
this.editVersion = function (opts, callback) {
var options = this.buildRequestOptions(opts, '', 'PUT', opts.version);
this.jiraClient.makeRequest(options, callback);
};
/**
* Get a bean containing the number of fixed in and affected issues for the given version.
*
* @method getRelatedIssueCounts
* @memberOf VersionClient#
* @param opts The request options sent to the Jira API.
* @param opts.versionId The version for which to retrieve related issues.
* @param callback Called when the count has been retrieved.
*/
this.getRelatedIssueCounts = function (opts, callback) {
var options = this.buildRequestOptions(opts, '/relatedIssueCounts', 'GET');
this.jiraClient.makeRequest(options, callback);
};
/**
* Get the number of unresolved issues for the given version
*
* @method getUnresolvedIssueCount
* @memberOf VersionClient#
* @param opts The request options sent to the Jira API.
* @param opts.versionId The version for which to retrieve unresolved issues.
* @param callback Called when the count has been retrieved.
*/
this.getUnresolvedIssueCount = function (opts, callback) {
var options = this.buildRequestOptions(opts, '/unresolvedIssueCount', 'GET');
this.jiraClient.makeRequest(options, callback);
};
/**
* Get the remote version links associated with the given version id.
*
* @method getRemoteLinks
* @memberOf VersionClient#
* @param opts The request options sent to the Jira API.
* @param opts.versionId The version for which to retrieve remote links.
* @param callback Called when the links have been retrieved.
*/
this.getRemoteLinks = function (opts, callback) {
var options = this.buildRequestOptions(opts, '/remotelink', 'GET');
this.jiraClient.makeRequest(options, callback);
};
/**
* Create a remote version link via POST. The link's global id will be taken from the JSON payload if provided;
* otherwise, it will be generated.
*
* @method createRemoteLink
* @memberOf VersionClient#
* @param opts The request options sent to the Jira API.
* @param opts.versionId The version for which to retrieve unresolved issues.
* @param opts.remoteLink See {@link https://docs.atlassian.com/jira/REST/latest/#d2e3753}
* @param callback Called when the remote link has been created.
*/
this.createRemoteLink = function (opts, callback) {
var options = this.buildRequestOptions(opts, '/remotelink', 'POST', opts.remoteLink);
this.jiraClient.makeRequest(options, callback, 'Remotelink Created');
};
/**
* Get a REST sub-resource representing a remote version link.
*
* @method getRemoteLinks
* @memberOf VersionClient#
* @param opts The request options sent to the Jira API.
* @param opts.versionId The version for which to retrieve the remote link
* @param opts.remoteLinkId The global id of the remote link
* @param callback Called when the link has been retrieved.
*/
this.getRemoteLink = function (opts, callback) {
var options = this.buildRequestOptions(opts, '/remotelink/' + opts.remoteLinkId, 'GET');
this.jiraClient.makeRequest(options, callback);
};
/**
* Delete a remote version link.
*
* @method deleteRemoteLink
* @memberOf VersionClient#
* @param opts The request options sent to the Jira API.
* @param opts.versionId The version id
* @param opts.remoteLinkId The global id of the remote link
* @param callback Called when the link has been deleted.
*/
this.deleteRemoteLink = function (opts, callback) {
var options = this.buildRequestOptions(opts, '/remotelink/' + opts.remoteLinkId, 'DELETE');
this.jiraClient.makeRequest(options, callback, 'Remote Link Deleted');
};
/**
* Delete a project version.
*
* @method deleteVersion
* @memberOf VersionClient#
* @param {Object} opts The request options sent to the Jira API.
* @param {string|number} opts.versionId The id of the version to delete.
* @param callback Called when the version is deleted.
*/
this.deleteVersion = function (opts, callback) {
var options = this.buildRequestOptions(opts, '', 'DELETE');
this.jiraClient.makeRequest(options, callback, 'Version Deleted');
};
/**
* Delete all remote version links for a given version id.
*
* @method deleteAllRemoteLinks
* @memberOf VersionClient#
* @param {Object} opts The request options sent to the Jira API.
* @param {string|number} opts.versionId The id of the version to delete.
* @param callback Called when the version is deleted.
*/
this.deleteAllRemoteLinks = function (opts, callback) {
var options = this.buildRequestOptions(opts, '/remotelink', 'DELETE');
this.jiraClient.makeRequest(options, callback, 'Remote Links Deleted');
};
/**
* Returns the remote version links for a given global id.
*
* @method getGlobalRemoteLink
* @memberOf VersionClient#
* @param opts The request options sent to the Jira API.
* @param opts.globalId The global id of the remote resource that is linked to the versions
* @param callback Called when the remote link is returned.
*/
this.getGlobalRemoteLink = function (opts, callback) {
var options = {
uri: this.jiraClient.buildURL('/version/remotelink'),
method: 'GET',
json: true,
followAllRedirects: true,
qs: {globalId: opts.globalId}
};
this.jiraClient.makeRequest(options, callback);
};
/**
* Build out the request options necessary to make a particular API call.
*
* @private
* @method buildRequestOptions
* @memberOf FilterClient#
* @param {Object} opts The arguments passed to the method.
* @param {number} opts.versionId The id of the screen 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 /version/{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 = '/version/' + opts.versionId;
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="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 Oct 27 2015
13:43:13 GMT-0500 (CDT)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"></script>
</body>
</html>