{"size": 786, "ext": "js", "max_stars_repo_path": "lib/signature.js", "max_stars_repo_name": "andrewstech/update-server", "max_stars_repo_stars_event_min_datetime": "2022-02-19T13:10:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-19T13:10:50.000Z", "max_issues_repo_path": "lib/signature.js", "max_issues_repo_name": "andrewstech/update-server", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/signature.js", "max_forks_repo_name": "andrewstech/update-server", "max_forks_repo_forks_event_min_datetime": "2021-09-06T04:27:23.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-27T20:50:29.000Z"}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": 2, "avg_line_length": 23.8181818182, "max_line_length": 79, "alphanum_fraction": 0.6195928753}
const fetch = require('node-fetch')
const retry = require('async-retry')
const convertStream = require('stream-to-string')

module.exports = async (fileName, assets) => {
  // Look if we can find a signature...
  const foundSignature = assets.find(asset => asset.name === `${fileName}.sig`)

  if (!foundSignature) {
    return null
  }

  const { body } = await retry(
    async () => {
      const response = await fetch(foundSignature.browser_download_url)

      if (response.status !== 200) {
        throw new Error(
          `GitHub API responded with ${response.status} for url ${
            foundSignature.browser_download_url
          }`
        )
      }

      return response
    },
    { retries: 3 }
  )

  const content = await convertStream(body)
  return content
}
