Skip to content

Instantly share code, notes, and snippets.

@beshkenadze
Created June 19, 2015 12:53
Show Gist options
  • Save beshkenadze/05d9d2fb72031e8c8383 to your computer and use it in GitHub Desktop.
Save beshkenadze/05d9d2fb72031e8c8383 to your computer and use it in GitHub Desktop.
Use issue_key (epic_key) to obtain epic progress.

#To use a custom function:

  • Create or open a spreadsheet in Google Sheets.
  • Select the menu item Tools > Script editor. If you are presented with a welcome screen, click Blank Project on the left to start a new project.
  • Delete any code in the script editor. For the PROGRESS_EPIC function below, simply copy and paste the code into the script editor.
  • Select the menu item File > Save. Give the script project a name and click OK.
  • All done! Now you can use the custom function.
var epicProgressURL = "https://{host_name}.atlassian.net/rest/greenhopper/1.0/xboard/plan/backlog/epics?&rapidViewId={PROJECT_ID}";
var fetchArgs = {
contentType: "application/json",
headers: {"Authorization":"Basic [base64 of username:password"},
muteHttpExceptions : true
};
function getPercentageCompleted(data, epicKey){
for(var i = 0; i < data.epics.length; i++) {
var epic = data.epics[i];
if(epic.key.indexOf(epicKey) >= 0) {
return epic.epicStats.percentageCompleted;
}
}
}
function PROGRESS_EPIC(input) {
var httpResponse = UrlFetchApp.fetch(epicProgressURL, fetchArgs);
if (httpResponse) {
switch(httpResponse.getResponseCode()){
case 200:
var data = JSON.parse(httpResponse.getContentText());
// Check the data is valid and the Jira fields exist
if(data && data.epics) {
// Set some basic ticket data in your spreadsheet
return Math.round(getPercentageCompleted(data, input));
}
else {
// Something funky is up with the JSON response.
return "Failed to retrive ticket data!";
}
case 404:
return "This ticket does not exist";
default:
// Jira returns all errors that occured in an array (if using the application/json mime type)
// var data = JSON.parse(httpResponse.getContentText());
return "Error: ";
}
} else {
return "Jira Error","Unable to make requests to Jira!";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment