将Google电子表格连接到Atlassian JIRA

时间:2015-05-15 21:21:06

标签: google-apps-script google-sheets jira-rest-api

我想使用Google Apps脚本在Google电子表格中显示我的JIRA问题,但首先我需要与JIRA建立连接,所以我经历了这些tutorials只是为了找出可能的对立面(JIRA)连接到其他应用程序),因此我想询问是否有方法将Google表格连接到JIRA,在这种情况下如何获取身份验证令牌?

2 个答案:

答案 0 :(得分:1)

从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

答案 1 :(得分:0)

请找到连接到JIRA的示例代码,并以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;

}