问题
I want to display my JIRA issues in a Google spreadsheet using Google Apps script but first i need to establish a connection with JIRA, so i went through these tutorials only to find out that the opposit is possible (JIRA connects to other applications), therefore i want to ask if there's a way to connect Google Sheets to JIRA and in that case how to get the Authentication Token ?
回答1:
Request token from JIRA:
Code.gs
function requestJIRA_Token() {
var baseUrl = 'Put Base URL to JIRA here';
var theUrl = baseUrl + "/plugins/servlet/oauth/request-token";
var response = UrlFetchApp.fetch(theUrl);
Logger.log('response: ' + response);
};
JIRA OAUTH
回答2:
Please find sample code to connect to JIRA and get the response as an Json Load
function seachIssuesR(j_query, maxresult) {
if (!j_query) {
Browser.msgBox("Null Query :: " + j_query);
}
var url = "https://<jiraServerName>.jira.com/rest/api/2/search?jql=" + j_query + "&startAt=0&maxResults=" + maxresult;
Logger.log(url);
if (!PropertiesService.getScriptProperties().getProperty("digest")) {
var userAndPassword = Browser.inputBox("Enter your Jira On Demand User id and Password in the form User:Password. e.g. javarohit@gmail.com:mypassword@123 (Note: This will be base64 Encoded and saved as a property on the spreadsheet)", "Userid:Password", Browser.Buttons.OK_CANCEL);
var x = Utilities.base64Encode(userAndPassword);
PropertiesService.getScriptProperties().setProperty("digest", "Basic " + x);
}
var digestfull = PropertiesService.getScriptProperties().getProperty("digest");
var headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"method": "GET",
"headers": {
"Authorization": digestfull
},
"muteHttpExceptions": true
};
var resp = UrlFetchApp.fetch(url, headers);
if (resp.getResponseCode() != 200) {
Browser.msgBox("Error retrieving data for url" + url + ":" + resp.getContentText());
return "";
} else {
json = resp.getContentText();
}
pri_list = JSON.parse(json);
return pri_list;
}
来源:https://stackoverflow.com/questions/30268924/connecting-google-spreadsheet-to-atlassian-jira