All files app.js

73.8% Statements 31/42
100% Branches 4/4
61.53% Functions 8/13
73.8% Lines 31/42

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 1792x                                             1x   1x 1x 1x   1x     1x   1x 4x 4x 4x 4x     4x 1x                             1x   1x 1x 1x     1x     1x 1x 1x 3x 3x                       3x         3x   3x         3x               3x   3x                   3x                                                                                                                              
const { error } = require("console");
 
var client;
 
init();
 
async function init() {
  client = await app.initialized();
  client.events.on('app.activated', renderText);
 
}
async function renderText() {
  const textElement = document.getElementById('apptext');
  const contactData = await client.data.get('contact');
  const {
    contact: { name }
  } = contactData;
 
  textElement.innerHTML = `Ticket is created by ${name}`;
}
 
async function push(){
 
  client = await app.initialized();
 
  var headers = {"Authorization": "Basic <%= encode(iparam.api_key) %>"};
  var options = { headers: headers };
  var url= "https://<%= iparam.domain %>.freshdesk.com/api/v2/tickets";
 
  client.request.get(url, options)
  .then (
  function(data) {
    let content= JSON.parse(data.response);
   
    content.map((values)=>{
      let status =values.status;
      let type =values.type;
      let ID =values.id;
      let SUB =values.subject;
      
     
      if(status!==5&&type=="Refund"){
       getConversation(ID,SUB);
      }
    })   
   
 
  },
  function(error) {
    console.log(error);
  });
 
 
 
}
 
async function getConversation (ID,SUB){
  client = await app.initialized();
 
  var headers = {"Authorization": "Basic <%= encode(iparam.api_key) %>"};
  var options = { headers: headers };
  var url= `https://<%= iparam.domain %>.freshdesk.com/api/v2/tickets/${ID}/conversations`;
  
 
  client.request.get(url, options)
  .then (
  function(data) {
    let content= JSON.parse(data.response);
   console.log(content)
    content.map((values)=>{
      let body =values.body;
     pushToGit(SUB,body)
    })   
   
 
  },
  function(error) {
    console.log(error);
  });
}
 
async function pushToGit(sub,body){
 
   const  issue = {
    title: sub,
    body: body
};
 
   let raw=JSON.stringify(issue);
 
  let headers = {"Authorization": "Token <%= iparam.git_api_key %> ",
  
  'User-Agent': 'Freshdesk Sample User Agent',
 
};
  let options = {
    method:"POST",
    headers: headers,
    body:raw,
    
 
    }
   
  const url = `https://api.github.com/repos/<%= iparam.GitUserName %>/<%= iparam.GitRepoName %>/issues`;
  
  client.request.get(url, options)
  .then (
  function(data) {
    let content= JSON.parse(data);
    
   console.log(content)   
   
 
  },
  function(error) {
    console.log(error);
  })
  
 
 
 
 //console.log(url)
 
//  client.iparams.get('GitRepoName','GitUserName').then(function (iparam) {
//   client.request.get(`https://api.github.com/repos/Arokiya-Kithiyon/gitissue/issues`,options)
//     .then(function (res) {
//       try {
//         data = JSON.parse(res.response);
       
//       } catch (error) {
//         console.error("Error while attempting to show issue", error);
//       }
//     })
//     .catch(function (error) {
//       console.error("error", error);
//     });
// });
 
 
 
 // json: {
    //   name: 'web',
    //   active: true,
    //   events: [
    //     'issues'
    //   ],
    //   config: {
        
    //     content_type: 'json'
    //   }
 
 
 /// isOAuth: true
   // let user = jQuery("input[name=username]").val().trim();
  // let repo = jQuery("input[name=reponame]").val().trim();
  // const token = "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";
//  let options ={
//   method:"POST",
//   headers : {
//     "Authorization": `Token ${token} `,
//     "Accept": "application/vnd.github+json"
// },
// body:raw
// }
 
//   await fetch(url,options)
//   .then(Response=>Response.json())
//   .then(result=>{
//     console.log(result)
//   })
//    .catch(er=>{
//     console.log(er)
//    });
 
}