Advertisement
stormihoebe

Shoutbase/Jira Zap Custom Code

Sep 24th, 2019
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // get values from input
  2. const { recordDuration, description } = input
  3.  
  4. // duration seconds => hours, mins, seconds
  5. function secondsToHMS(d) {
  6.     d = Number(d);
  7.     var h = Math.floor(d / 3600);
  8.     var m = Math.floor(d % 3600 / 60);
  9.     var s = Math.floor(d % 3600 % 60);
  10.  
  11.     var hDisplay = h > 0 ? h + (h == 1 ? " hour " : " hours ") : "";
  12.     var mDisplay = m > 0 ? m + (m == 1 ? " minute " : " minutes ") : "";
  13.     var sDisplay = s > 0 ? s + (s == 1 ? " second" : " seconds") : "";
  14.     return hDisplay + mDisplay + sDisplay;
  15. }
  16.  
  17. const duration = secondsToHMS(recordDuration)
  18.  
  19. if (description && description.includes(".atlassian.net/browse/")) {
  20.   // parse Jira key from description
  21.   const descriptionSplit = description.split(".atlassian.net/browse/")
  22.   const jiraKey = descriptionSplit.length > 1 ? descriptionSplit[1].split()[0] : ""
  23.   const key = jiraKey.split(/(\s)/)
  24.  
  25.   output = [{duration, jiraKey: key[0]}];
  26. } else {
  27.   output = [{duration, jiraKey: null}];
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement