Connecting Google spreadsheet to Atlassian JIRA

ぐ巨炮叔叔 提交于 2019-12-08 08:45:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!