<commit_before>#!/usr/bin/env python

import argparse
import errno
import glob
import os
import requests
import subprocess
import sys
import tempfile

from lib.util import *
from lib.github import GitHub


TARGET_PLATFORM = {
  'cygwin': 'win32',
  'darwin': 'darwin',
  'linux2': 'linux',
  'win32': 'win32',
}[sys.platform]

ATOM_SHELL_REPO = 'atom/atom-shell'
ATOM_SHELL_VRESION = get_atom_shell_version()
NODE_VERSION = 'v0.10.18'

SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
OUT_DIR = os.path.join(SOURCE_ROOT, 'out', 'Release')
DIST_DIR = os.path.join(SOURCE_ROOT, 'dist')
DIST_NAME = 'atom-shell-{0}-{1}.zip'.format(ATOM_SHELL_VRESION, TARGET_PLATFORM)


def main():
  args = parse_args()

  if not dist_newer_than_head():
    create_dist = os.path.join(SOURCE_ROOT, 'script', 'create-dist.py')
    subprocess.check_call([sys.executable, create_dist])

  github = GitHub(auth_token())
  print create_or_get_release_draft(github, args.version)
  # upload(auth_token)
  # if not args.no_update_version:
  #   update_version(auth_token)


def parse_args():
  parser = argparse.ArgumentParser(description='upload distribution file')
  parser.add_argument('-v', '--version', help='Specify the version',
                      default=ATOM_SHELL_VRESION)
  parser.add_argument('-n', '--no-update-version',
                      help='Do not update the latest version file',
                      action='store_true')
  return parser.parse_args()


def dist_newer_than_head():
  with scoped_cwd(SOURCE_ROOT):
    try:
      head_time = subprocess.check_output(['git', 'log', '--pretty=format:%at',
                                           '-n', '1']).strip()
      dist_time = os.path.getmtime(os.path.join(DIST_DIR, DIST_NAME))
    except OSError as e:
      if e.errno != errno.ENOENT:
        raise
      return False

  return dist_time > int(head_time)


def create_or_get_release_draft(github, tag):
  releases = github.repos(ATOM_SHELL_REPO).releases.get()
  for release in releases:
    if release['tag_name'] == tag:
      return release['id']

  return create_release_draft(github, tag)


def create_release_draft(github, tag):
  name = 'atom-shell %s' % tag<commit_msg>:lipstick: Find the release even when commit isn't tagged.<commit_after>#!/usr/bin/env python

import argparse
import errno
import glob
import os
import requests
import subprocess
import sys
import tempfile

from lib.util import *
from lib.github import GitHub


TARGET_PLATFORM = {
  'cygwin': 'win32',
  'darwin': 'darwin',
  'linux2': 'linux',
  'win32': 'win32',
}[sys.platform]

ATOM_SHELL_REPO = 'atom/atom-shell'
ATOM_SHELL_VRESION = get_atom_shell_version()
NODE_VERSION = 'v0.10.18'

SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
OUT_DIR = os.path.join(SOURCE_ROOT, 'out', 'Release')
DIST_DIR = os.path.join(SOURCE_ROOT, 'dist')
DIST_NAME = 'atom-shell-{0}-{1}.zip'.format(ATOM_SHELL_VRESION, TARGET_PLATFORM)


def main():
  args = parse_args()

  if not dist_newer_than_head():
    create_dist = os.path.join(SOURCE_ROOT, 'script', 'create-dist.py')
    subprocess.check_call([sys.executable, create_dist])

  github = GitHub(auth_token())
  print create_or_get_release_draft(github, args.version)
  # upload(auth_token)
  # if not args.no_update_version:
  #   update_version(auth_token)


def parse_args():
  parser = argparse.ArgumentParser(description='upload distribution file')
  parser.add_argument('-v', '--version', help='Specify the version',
                      default=ATOM_SHELL_VRESION)
  parser.add_argument('-n', '--no-update-version',
                      help='Do not update the latest version file',
                      action='store_true')
  return parser.parse_args()


def dist_newer_than_head():
  with scoped_cwd(SOURCE_ROOT):
    try:
      head_time = subprocess.check_output(['git', 'log', '--pretty=format:%at',
                                           '-n', '1']).strip()
      dist_time = os.path.getmtime(os.path.join(DIST_DIR, DIST_NAME))
    except OSError as e:
      if e.errno != errno.ENOENT:
        raise
      return False

  return dist_time > int(head_time)


def create_or_get_release_draft(github, tag):
  name = 'atom-shell %s' % tag
  releases = github.repos(ATOM_SHELL_REPO).releases.get()
  for release in releases:
    # The untagged commit doesn't have a matching tag_name, so also check name.
    if release['tag_name'] == tag or release['name'] == name:
      return release['id']

  return create_release_draft(github, tag)


def create_release_draft(github, tag):
  name = 'atom-shell %s' % tag
{'fraction_non_alphanumeric': 0.13072747014115094, 'fraction_numerical': 0.006514657980456026, 'mean_word_length': 3.7338129496402876, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1826027', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1552, 'n_words': 328}