LANG SELRCT

Apps Script Reference  (Create: Create new Spreadsheet | Create new Apps Script

Tuesday, February 11, 2020

JIRA APIで指定した課題にコメントを追加したい


公式リファレンスを参考に、以下のコード.gsでいけました。



事前準備
  • 「BASE_URL」と「issueKey」は各自の値を設定します
  • スクリプトのプロパティに「token」という名でbase64Encodeしたトークンを入れておきます



tokenについては別途こちらにも書きました



コード.gs
var BASE_URL = "https://SITENAME.atlassian.net";
var issueKey = "KT-8";

function addComment() {
  var data = {
    "body": {
      "type": "doc",
      "version": 1,
      "content": [
        {
          "type": "paragraph",
          "content": [
            {
              "text": "added comment",
              "type": "text"
            }
          ]
        }
      ]
    }
  }

  var options = {
    method: 'post',
    contentType: 'application/json',
    headers: {'Authorization': ' Basic ' + getToken()},
    payload: JSON.stringify(data)
  }
  var url = BASE_URL + '/rest/api/3/issue/' + issueKey + "/comment";
  UrlFetchApp.fetch(url, options);
}

function getToken() {
  return PropertiesService.getScriptProperties().getProperty('token');
}





補足

上記は REST API v3 の場合で
v2 の場合は以下のコード2.gsでいけました。


コード2.gs
var BASE_URL = "https://SITENAME.atlassian.net";
var issueKey = "KT-8";

function addComment() {
  var data = {
        "body": "added comment v2"
      }

  var options = {
    method: 'post',
    contentType: 'application/json',
    headers: {'Authorization': ' Basic ' + getToken()},
    payload: JSON.stringify(data)
  }
  var url = BASE_URL + '/rest/api/2/issue/' + issueKey + "/comment";
  UrlFetchApp.fetch(url, options);
}

function getToken() {
  return PropertiesService.getScriptProperties().getProperty('token');
}



参考

Add comment v3
https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-rest-api-3-issue-issueIdOrKey-comment-post

Add comment v2
https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issue-issueIdOrKey-comment-post

Latest post

スプレッドシートA列にある複数のテキストをスライドに追加したい(Google Apps Script)

今回Google Apps Scriptでやりたいこと GoogleスプレッドシートA列にある複数の値を取得して Googleスライドに渡して 図形オブジェクトのテキストとして追加したい ① スプレッドシートのA列に値を入れておく ② Code.gsのinsertNewShape...