SHARE
TWEET

Shoutbase/GitHub Zap Custom Code

stormihoebe Sep 24th, 2019 (edited) 121 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. const duration = secondsToHMS(recordDuration)
  17.  
  18. if (description && description.includes("https://github.com/")) {
  19.   // parse PR ID from description
  20.   const descriptionSplit = description.split("/pull/")
  21.   const afterPull = descriptionSplit.length > 1 ? descriptionSplit[1].split()[0] : ""
  22.   const prID = afterPull.split(/(\s)/)[0]
  23.  
  24.   // get Repo from description
  25.   const repoDescriptionSplit = description.split("https://github.com/")
  26.   const repo = repoDescriptionSplit.length > 1
  27.     ? repoDescriptionSplit[1].split("/pull/")[0]
  28.     : ""
  29.   output = [{duration, prID, repo}]
  30. } else {
  31.   output = [{duration, prID: null, repo: null}]
  32. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top