Created
September 15, 2016 18:10
-
-
Save IranthaJ/58b02ada29be2bf811eff4ff6ce5f85a to your computer and use it in GitHub Desktop.
google apps script to JIRA connector
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function testJiraConnection() | |
| { | |
| var baseURL = "https://yourserver/rest/api/2/search"; | |
| var username = "username"; | |
| var password = "pass"; | |
| var encCred = Utilities.base64Encode(username+":"+password); | |
| var fetchArgs = { | |
| contentType: "application/json", | |
| headers: {"Authorization":"Basic "+encCred}, | |
| muteHttpExceptions : true | |
| }; | |
| //JQL; you can use your own JQL ;) | |
| var jql = "?jql=assignee = currentUser() AND resolution = Unresolved order by updated DESC"; | |
| var httpResponse = UrlFetchApp.fetch(baseURL + jql, fetchArgs); | |
| if (httpResponse) { | |
| var rspns = httpResponse.getResponseCode(); | |
| switch(rspns){ | |
| case 200: | |
| var data = JSON.parse(httpResponse.getContentText()); | |
| var issuessss = []; | |
| for(var id in data["issues"]) | |
| { | |
| // Check the data is valid and the Jira fields exist | |
| if(data["issues"][id] && data["issues"][id].fields) { | |
| var type = data["issues"][id].fields.issuetype.name; | |
| var reporter = data["issues"][id].fields.reporter.displayName; | |
| var summary = data["issues"][id].fields.summary; | |
| issuessss.push([type,reporter,summary]);// adding each issue data to 2D array | |
| } | |
| } | |
| var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); //select active spreadsheet | |
| sheet.getRange(2, 1, issuessss.length, 3).setValues(issuessss); // write from cell A2 | |
| break; | |
| case 404: | |
| Browser.msgBox("Response error, No item found", Browser.Buttons.OK); | |
| break; | |
| default: | |
| var data = JSON.parse(httpResponse.getContentText()); | |
| Browser.msgBox("Error: " + data.errorMessages.join(",")); // returns all errors that occured | |
| break; | |
| } | |
| } | |
| else { | |
| Browser.msgBox("Jira Error","Unable to make requests to Jira!", Browser.Buttons.OK); | |
| } | |
| } | |
nice, but far from complete, this only fetches 50, how would you expand to fetch more records?
You can use the "maxResults=-1" to get all the issues matched by your JQL
Como consigo buscar mais registros?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi.
I started with a similar simple snippet, and then i extended it to an actual GAS Add-on.
Maybe peoples out there start contributing to improve the add-on even more.
Check it out, feedback welcome: https://github.com/ljay79/jira-tools/