VICE / Server / JIRA.js
JIRA.js
Raw
// var authStr = 'Basic am9wMjJAbmF1LmVkdTpoRWdyVnFHd2ljcUs2N2IzZ2t1cjg1REI=';

class JIRA {
  constructor(){
    this.authStr = 'Basic am9wMjJAbmF1LmVkdTpoRWdyVnFHd2ljcUs2N2IzZ2t1cjg1REI=';
  }

  *get_issues(domain_name, board_id, callback)
  {
      var url_string= `https://${domain_name}.atlassian.net/rest/agile/1.0/board/${board_id}/epic/none/issue`;
      var issues = [];
  
      console.log("Getting new issues\n\n");
  
      fetch(url_string, {
        method: 'GET',
        authorization: authStr,
        headers: {
          'Authorization': authStr,
          'Accept': 'application/json',
          'Content-Type': 'application/json'
        }
      })
        .then(response => {
          console.log(
            `Response: ${response.status}`
          );
          return response.text();
        })
        .then(text => {
            //console.log(text)
            const obj = JSON.parse(text);
            const issues_length = obj.issues.length;
            for(let i = 0; i < issues_length; i++)
            {
                console.log(obj.issues[i].key);
                console.log(obj.issues[i].fields.description);
                issues.push({"id":obj.issues[i].key,
                             "description":obj.issues[i].fields.description});
            }
            // possibly remove?
            callback(issues);
        })
        .catch(err => console.error(err));
  };
}
//var IssueRequestHandler = function(request, response) {
//    get_issues('wdcapstonetest', 1, async (issues) => {
//    });
//};