This post is the continuation of:

Here another groovy script example to get the Worklogs of the Tempo Teams using the Tempo Timesheets REST API and Adaptavist Scriptrunner.

....
def JIRA_REST_URL = "http://localhost:2000"
def JIRA_API_URL = JIRA_REST_URL + "/rest/tempo-teams/1/team"
def JIRA_API_URL_2 = JIRA_REST_URL + "/rest/tempo-teams/2/team/"
def JIRA_API_URL_3 = JIRA_REST_URL + "/rest/tempo-timesheets/3/worklogs/"
def user_pass = "user:password"

...
//We get the list of Tempo Teams
def jira = new HTTPBuilder(JIRA_API_URL);
jira.client.addRequestInterceptor(new HttpRequestInterceptor() {
void process(HttpRequest httpRequest, HttpContext httpContext) {
httpRequest.addHeader('Authorization', 'Basic ' + user_pass.bytes.encodeBase64().toString())
}
})
def teams = jira.get(path: JIRA_API_URL );
...
while ( i < teams.size() ) {
	...
        //We get the list of members of the team
	members = jira.get(path: JIRA_API_URL_2 + teams[i].id +"/member" );
	while ( j < members.size() ) {
		...
		try {
                //We get the worklogs in a range of dates
		worklogs = jira.get(path: JIRA_API_URL_3 , query:['dateFrom':(date - 7).format('yyyy-MM-dd'),'dateTo':(date - 0).format('yyyy-MM-dd'),'username':members[j].member.name ]);
		while ( y < worklogs.size()) {
			time = time + worklogs[y].timeSpentSeconds
			y++;
		}
		} catch ( Exception e ) {
			error = error + "||" + e.message + " Member:"+members[j].member.name;
		}
		time_in_hours = time_in_hours + (time / 3600)
		x = x + (Double.parseDouble(members[j].membership.availability)/100);
		...
	}
	...
}
Posted by:.

One thought on “Jira Groovy example script to get Tempo Teams Worklogs using REST API

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s