Alexei Trebounskikh
Context
Jira is Atlassian's flagship software development tool that has many uses across the enterprise. This code snippet abstracts several functions for interacting with the JIRA REST API (https://docs.atlassian.com/jira/REST/latest/). This code is generalized to be used against any type of object within the Jira platform.
Note: This uses the _XMIO function available here, but could easily be rewritten to not need it.
Usage
var text = "I'm taking this issue.";
var key = 'JRA-3333';
var type = 'issue';
// Assign the issue to chef
var resp = JIRA.assign( type, key, 'chef' );
// Make a comment to the issue
resp = JIRA.comment( type, key, text, 'chef' );
Code
// JIRA REST API
var JIRA = {};
(function(){
// private functions and variables
var prefix = "/rest/api/latest/";
var xmio = new _XMIO( 'Jira' );
// public functions
JIRA.comment = function( type, key, text, author ) {
console.log( "JIRA: comment on " + type + " " + key + ": '" + text
+ ( author !== null ? "' by " + author : "" ) );
var url = prefix + type + "/" + key + "/comment";
var json = {
"body": text
};
if ( author !== null ) {
json.author = { "name": author };
}
return xmio.post( JSON.stringify( json ), url );
};
JIRA.assign = function( type, key, user ) {
console.log( "JIRA: assign " + type + " " + key + " to " + user );
var url = prefix + type + "/" + key;
var json = {
"fields": {
"assignee": { "name": user }
}
};
var response = xmio.put( JSON.stringify( json ), url );
return response;
};
})();
0
Comments
Please sign in to leave a comment.