const { requireValue } = require('./services/utils')

const request = require('request-promise-native')

const getVersion = require ('./services/version')

module.exports = async (options, logger) => {

  const versionInfo = getVersion(options, logger)

  let {
    project = process.env.PROJECT_ID || requireValue('project'),
    version = process.env.VERSION || versionInfo.version || requireValue('version')
  } = options

  await request({
    method: 'POST',
    uri: 'https://automation.codebarrel.io/pro/hooks/babff4335c2ecb135235f32bbc34d1dc56e228c9',
    body: {
      data: {
        releaseVersion: version,
        projectId: project
      }
    },
    json: true
  })

  logger(`Released version "${version}" sent to Jira project ${project.toUpperCase()}`.green)
  return 0
}
