javascript Jira Tempo整合

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Jira Tempo整合相关的知识,希望对你有一定的参考价值。

//runIntegration();
runIntegrationTest();

function runIntegration() {
	var dateFrom = '2017-11-01';
	var dateTo = '2017-11-30';
	
	new JiraIntegration().execute(dateFrom, dateTo);
}

function runIntegrationTest() {
	var dateFrom = '2017-11-01';
	var dateTo = '2017-11-30';
	var jiraKey = 'ASP';
	
	new JiraIntegration().executeTest(dateFrom, dateTo, jiraKey);
}
var JiraIntegration = Class.create();
JiraIntegration.prototype = {
	initialize: function() {
	},
	
	execute: function(dateFrom, dateTo) {
		var responseBody, number;
		var jiraKeyArray = this.getJiraKey();
		
		for (var i = 0; i < jiraKeyArray.length; i++) {
			
			responseBody = this.tempoRESTCall(dateFrom, dateTo, jiraKeyArray[i]);
			
			if (responseBody != undefined) {
				number = this.getProjectNumber(jiraKeyArray[i]);
				this.insertTimeCard(responseBody, jiraKeyArray[i], number);
			} else {
				gs.log("No response from " + jiraKeyArray[i], "Script Include - JiraIntegration");
			}
		}
	},
	
	executeTest: function(dateFrom, dateTo, jiraKey) {
		var responseBody, number;
		responseBody = this.tempoRESTCall(dateFrom, dateTo, jiraKey);
		if (responseBody != undefined) {
			number = this.getProjectNumber(jiraKey);
			this.insertTimeCard(responseBody, jiraKey, number);
		} else {
			gs.log("No response from " + jiraKey + " dateFrom: " + dateFrom + " dateTo: " + dateTo, "Script Include - JiraIntegration");
		}
	},
	
	//Return unique JiraKey in an array
	getJiraKey: function() {
		
		var jiraKey = [];
		var arrayUtil = new ArrayUtil();
		
		var gr = new GlideRecord('pm_project');
		gr.addNotNullQuery('u_ekb');
		//gr.setLimit(5);
		//gr.addQuery('u_ekb', 'ASP');
		gr.query();
		
		while (gr.next()) {
			jiraKey.push(gr.u_ekb + '');
		}
		
		return arrayUtil.unique(jiraKey);
	},
	
	//Return project number
	getProjectNumber : function(jiraKey) {
		var gr = new GlideRecord('pm_project');
		gr.addQuery('u_ekb', jiraKey);
		gr.query();
		
		if (gr.next()) {
			return gr.number;
		} else {
			gs.log("Project number not found", "Script Include - JiraIntegration");
		}
	},
	
	//Make REST API call
	tempoRESTCall: function(dateFrom, dateTo, projectKey) {
		var responseBody, httpStatus, response;
		
		try {
			var r = new sn_ws.RESTMessageV2('Jira Integration (Tempo)', 'get');
			r.setStringParameterNoEscape('dateFrom', dateFrom);
			r.setStringParameterNoEscape('dateTo', dateTo);
			r.setStringParameterNoEscape('projectKey', projectKey);
			
			response = r.execute();
			responseBody = response.getBody();
			httpStatus = response.getStatusCode();
		}
		catch(ex) {
			var message = ex.getMessage();
		}
		
		if (response.haveError()) {
			gs.log("Jira API Response: " + response.getErrorMessage() + " HTTP Status: " + httpStatus, "Script Include - JiraIntegration");
			gs.log(message);
		} else {
			return responseBody;
		}
	},
	
	//Insert a timecard record to the import table
	insertTimeCard: function(responseBody, jiraKey, number) {
		responseBody = JSON.parse(responseBody);
		var gr = new GlideRecord('u_jira_integration_time_card_import');
		
		responseBody.forEach(function(object) {
			gr.initialize();
			gr.u_timespentseconds = object.timeSpentSeconds;
			gr.u_datestarted = object.dateStarted;
			gr.u_comment = object.comment;
			gr.u_jiraworklogid = object.jiraWorklogId;
			gr.u_author = object.author.displayName;
			gr.u_issuetype = object.worklogAttributes[0].value;
			gr.u_task = number;
			gr.u_jirakey = jiraKey;
			gr.insert();
		});
	},
	
	type: 'JiraIntegration'
};

以上是关于javascript Jira Tempo整合的主要内容,如果未能解决你的问题,请参考以下文章

JIRA统计工时,我们用Tempo

testlink里面没有jira.cfg.php 怎么整合

markdown 整合:松弛到OpsGenie和Jira

IDEA 整合 jira

Confluence 6 与其他应用整合

javascript 复制jira sprint报告门票内容