<commit_before>child_process = require 'child_process'
path = require 'path'

_ = require 'underscore-plus'
async = require 'async'
fs = require 'fs-plus'
GitHub = require 'github-releases'
request = require 'request'
AWS = require 'aws-sdk'

grunt = null

token = process.env.ATOM_ACCESS_TOKEN
repo = process.env.ATOM_PUBLISH_REPO ? 'atom/atom'
defaultHeaders =
  Authorization: "token #{token}"
  'User-Agent': 'Atom'

module.exports = (gruntObject) ->
  grunt = gruntObject
  {cp} = require('./task-helpers')(grunt)

  grunt.registerTask 'publish-build', 'Publish the built app', ->
    tasks = []
    tasks.push('build-docs', 'prepare-docs') if process.platform is 'darwin'
    tasks.push('upload-assets')
    grunt.task.run(tasks)

  grunt.registerTask 'prepare-docs', 'Move api.json to atom-api.json', ->
    docsOutputDir = grunt.config.get('docsOutputDir')
    buildDir = grunt.config.get('atom.buildDir')
    cp path.join(docsOutputDir, 'api.json'), path.join(buildDir, 'atom-api.json')

  grunt.registerTask 'upload-assets', 'Upload the assets to a GitHub release', ->
    releaseBranch = grunt.config.get('atom.releaseBranch')
    isPrerelease = grunt.config.get('atom.channel') is 'beta'
    return unless releaseBranch?

    doneCallback = @async()
    startTime = Date.now()
    done = (args...) ->
      elapsedTime = Math.round((Date.now() - startTime) / 100) / 10
      grunt.log.ok("Upload time: #{elapsedTime}s")
      doneCallback(args...)

    unless token
      return done(new Error('ATOM_ACCESS_TOKEN environment variable not set'))

    buildDir = grunt.config.get('atom.buildDir')
    assets = getAssets()

    zipAssets buildDir, assets, (error) ->
      return done(error) if error?
      getAtomDraftRelease isPrerelease, releaseBranch, (error, release) ->
        return done(error) if error?
        assetNames = (asset.assetName for asset in assets)
        deleteExistingAssets release, assetNames, (error) ->
          return done(error) if error?
          uploadAssets(release, buildDir, assets, done)

getAssets = ->
  {cp} = require('./task-helpers')(grunt)

  {version} = grunt.file.readJSON('package.json')
  buildDir = grunt.config.get('atom.buildDir')<commit_msg>Add repo logging to publish task<commit_after>child_process = require 'child_process'
path = require 'path'

_ = require 'underscore-plus'
async = require 'async'
fs = require 'fs-plus'
GitHub = require 'github-releases'
request = require 'request'
AWS = require 'aws-sdk'

grunt = null

token = process.env.ATOM_ACCESS_TOKEN
repo = process.env.ATOM_PUBLISH_REPO ? 'atom/atom'
defaultHeaders =
  Authorization: "token #{token}"
  'User-Agent': 'Atom'

module.exports = (gruntObject) ->
  grunt = gruntObject
  {cp} = require('./task-helpers')(grunt)

  grunt.registerTask 'publish-build', 'Publish the built app', ->
    tasks = []
    tasks.push('build-docs', 'prepare-docs') if process.platform is 'darwin'
    tasks.push('upload-assets')
    grunt.task.run(tasks)

  grunt.registerTask 'prepare-docs', 'Move api.json to atom-api.json', ->
    docsOutputDir = grunt.config.get('docsOutputDir')
    buildDir = grunt.config.get('atom.buildDir')
    cp path.join(docsOutputDir, 'api.json'), path.join(buildDir, 'atom-api.json')

  grunt.registerTask 'upload-assets', 'Upload the assets to a GitHub release', ->
    grunt.log.ok("Starting upload-assets to #{repo} repo")
    releaseBranch = grunt.config.get('atom.releaseBranch')
    isPrerelease = grunt.config.get('atom.channel') is 'beta'
    return unless releaseBranch?

    doneCallback = @async()
    startTime = Date.now()
    done = (args...) ->
      elapsedTime = Math.round((Date.now() - startTime) / 100) / 10
      grunt.log.ok("Upload time: #{elapsedTime}s")
      doneCallback(args...)

    unless token
      return done(new Error('ATOM_ACCESS_TOKEN environment variable not set'))

    buildDir = grunt.config.get('atom.buildDir')
    assets = getAssets()

    zipAssets buildDir, assets, (error) ->
      return done(error) if error?
      getAtomDraftRelease isPrerelease, releaseBranch, (error, release) ->
        return done(error) if error?
        assetNames = (asset.assetName for asset in assets)
        deleteExistingAssets release, assetNames, (error) ->
          return done(error) if error?
          uploadAssets(release, buildDir, assets, done)

getAssets = ->
  {cp} = require('./task-helpers')(grunt)

  {version} = grunt.file.readJSON('package.json')
  buildDir = grunt.config.get('atom.buildDir')
{'fraction_non_alphanumeric': 0.14171122994652408, 'fraction_numerical': 0.0022281639928698753, 'mean_word_length': 3.6956066945606696, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4807317', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1436, 'n_words': 329}