<commit_before>fs = require 'fs'
path = require 'path'

request = require 'request'

module.exports = (grunt) ->
  {spawn, mkdir, rm, cp} = require('./task-helpers')(grunt)

  accessToken = null
  getTokenFromKeychain = ->
    accessToken ?= process.env['ATOM_ACCESS_TOKEN']

  callAtomShellReposApi = (path, callback) ->
    options =
      url: "https://api.github.com/repos/atom/atom-shell#{path}"
      proxy: process.env.http_proxy || process.env.https_proxy
      headers:
        authorization: "token #{getTokenFromKeychain()}"
        accept: 'application/vnd.github.manifold-preview'
    request options, (error, response, body) ->
      if not error?
        body = JSON.parse(body)
        error = new Error(body.message) if response.statusCode != 200
      callback(error, response, body)

  findReleaseIdFromAtomShellVersion = (version, callback) ->
    callAtomShellReposApi '/releases', (error, response, data) ->
      if error?
        grunt.log.error('Cannot get releases of atom-shell')
        callback(error)
      else
        for release in data when release.tag_name is version
          callback(null, release.id)
          return
        grunt.log.error("There is no #{version} release of atom-shell")
        callback(false)

  getAtomShellDownloadUrl = (version, releaseId, callback) ->
    callAtomShellReposApi "/releases/#{releaseId}/assets", (error, response, data) ->
      if error?
        grunt.log.error("Cannot get assets of atom-shell's #{version} release")
        callback(error)
      else
        filename = "atom-shell-#{version}-#{process.platform}.zip"
        for asset in data when asset.name is filename and asset.state is 'uploaded'
          callback(null, asset.url)
          return<commit_msg>Give error more descriptive title<commit_after>fs = require 'fs'
path = require 'path'

request = require 'request'

module.exports = (grunt) ->
  {spawn, mkdir, rm, cp} = require('./task-helpers')(grunt)

  accessToken = null
  getTokenFromKeychain = ->
    accessToken ?= process.env['ATOM_ACCESS_TOKEN']

  callAtomShellReposApi = (path, callback) ->
    options =
      url: "https://api.github.com/repos/atom/atom-shell#{path}"
      proxy: process.env.http_proxy || process.env.https_proxy
      headers:
        authorization: "token #{getTokenFromKeychain()}"
        accept: 'application/vnd.github.manifold-preview'
    request options, (error, response, body) ->
      if not error?
        body = JSON.parse(body)
        error = new Error(body.message) if response.statusCode != 200
      callback(error, response, body)

  findReleaseIdFromAtomShellVersion = (version, callback) ->
    callAtomShellReposApi '/releases', (error, response, data) ->
      if error?
        grunt.log.error('GitHub API failed to access atom-shell releases')
        callback(error)
      else
        for release in data when release.tag_name is version
          callback(null, release.id)
          return
        grunt.log.error("There is no #{version} release of atom-shell")
        callback(false)

  getAtomShellDownloadUrl = (version, releaseId, callback) ->
    callAtomShellReposApi "/releases/#{releaseId}/assets", (error, response, data) ->
      if error?
        grunt.log.error("Cannot get assets of atom-shell's #{version} release")
        callback(error)
      else
        filename = "atom-shell-#{version}-#{process.platform}.zip"
        for asset in data when asset.name is filename and asset.state is 'uploaded'
          callback(null, asset.url)
          return
{'fraction_non_alphanumeric': 0.1206798866855524, 'fraction_numerical': 0.0016997167138810198, 'mean_word_length': 2.954087346024636, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4105931', 'n_tokens_mistral': 1052, 'n_tokens_neox': 1025, 'n_words': 261}