import fetch from 'node-fetch'
import {execSync} from 'child_process'
import {format as formatDate} from '../src/format'

const zapierHookURL =
  `https://zapier.com/hooks/catch/${process.env.ZAPIER_TWEET_RELEASE_HOOK_ID}/`
const tag = process.env.TRAVIS_TAG ||
  execSync('git describe --abbrev=0 --tags').toString().trim()
const formattedDate = formatDate(new Date(), 'YYYY-MM-DD')
const changelogUrl =
  `https://github.com/toptal/tracker-front/blob/master/CHANGELOG.md#${tag.replace(/\./g, '')}---${formattedDate}`

console.log('~ Posting release tweet')

fetch(zapierHookURL, {
  method: 'POST',
  body: JSON.stringify({
    tweet: `date-fns ${tag} is published! See changelog: ${changelogUrl}.`
  }),
  headers: {'Content-Type': 'application/json'}
})
  .then(() => console.log('+ Done!'))
  .catch((err) => {
    console.error(err)
    process.exit(1)
  })

@@ -74,19 +74,8 @@
 ort 
-%7Bformat as 
 form
@@ -80,17 +80,16 @@
 rmatDate
-%7D
  from '.
@@ -401,64 +401,36 @@
 s://
-github.com/toptal/tracker-front/blob/master/CHANGELOG.md
+date-fns.org/docs/Change-Log
 #$%7Bt
@@ -445,21 +445,18 @@
 ce(/
-%5C./g
+%5Ev/
 , '')%7D-
---
 $%7Bfo

Fix release tweet script