{"size": 903, "ext": "js", "max_stars_repo_path": "lib/steps/check-restricted-address.js", "max_stars_repo_name": "telemark/avtale-generator", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lib/steps/check-restricted-address.js", "max_issues_repo_name": "telemark/avtale-generator", "max_issues_repo_issues_event_min_datetime": "2018-04-20T21:04:19.000Z", "max_issues_repo_issues_event_max_datetime": "2019-08-19T16:15:53.000Z", "max_forks_repo_path": "lib/steps/check-restricted-address.js", "max_forks_repo_name": "telemark/avtale-generator", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 74, "max_forks_count": null, "avg_line_length": 33.4444444444, "max_line_length": 106, "alphanum_fraction": 0.6965669989}
const isHemmelig = require('tfk-is-hemmelig-adresse')
const logger = require('../logger')

module.exports = async data => {
  logger('info', ['check-restricted-address', data._id])

  if (data.sendToDistribution === true) {
    if (data.dsfError) {
      logger('info', ['check-restricted-address', data._id, 'skipped due to dsfError'])
    } else {
      const restrictedDsf = isHemmelig(data.dsfContact)
      const restricted360 = data.p360Contact ? isHemmelig(data.p360Contact) : false

      const gotRestrictedAddress = restricted360 || restrictedDsf

      logger('info', ['check-restricted-address', data._id, 'gotRestrictedAddress', gotRestrictedAddress])

      data.restrictedAddress = gotRestrictedAddress

      data.sendToDistribution = !gotRestrictedAddress
    }
  } else {
    logger('info', ['check-restricted-address', data._id, 'skipped due to no distribution'])
  }
  return data
}
