Пример #1
0
def check_args():
    transifex_info = (get_env_var('TRANSIFEX_USERNAME') and
                      get_env_var('TRANSIFEX_PASSWORD') or
                      get_env_var('TRANSIFEX_API_KEY'))
    message = 'TRANSIFEX_USERNAME and TRANSIFEX_PASSWORD or '
    'TRANSIFEX_API_KEY must be set'
    assert transifex_info, message
Пример #2
0
def check_args():
    transifex_info = (get_env_var('TRANSIFEX_USERNAME')
                      and get_env_var('TRANSIFEX_PASSWORD')
                      or get_env_var('TRANSIFEX_API_KEY'))
    message = 'BRAVE_TRANSIFEX_USERNAME and BRAVETRANSIFEX_PASSWORD or '
    'BRAVE_TRANSIFEX_API_KEY must be set in npm config'
    assert transifex_info, message
Пример #3
0
def check_args():
    transifex_info = (get_env_var('TRANSIFEX_USERNAME')
                      and get_env_var('TRANSIFEX_PASSWORD')
                      or get_env_var('TRANSIFEX_API_KEY'))
    message = 'TRANSIFEX_USERNAME and TRANSIFEX_PASSWORD or '
    'TRANSIFEX_API_KEY must be set'
    assert transifex_info, message
Пример #4
0
 def get_auth(self):
     """Creates an HTTPBasicAuth object given the Transifex information"""
     username = get_env_var('TRANSIFEX_USERNAME')
     password = get_env_var('TRANSIFEX_PASSWORD')
     transifex_api_key = get_env_var('TRANSIFEX_API_KEY')
     auth = None
     if transifex_api_key:
         auth = requests.auth.HTTPBasicAuth("api", transifex_api_key)
     else:
         auth = requests.auth.HTTPBasicAuth(username, password)
     return auth
Пример #5
0
 def __init__(self, project_name):
     self._project_name = project_name
     assert self._project_name, \
         'TransifexAPIV2Wrapper: project_name is not set.'
     # Checks that we can get authentication info from the environment
     transifex_info = (get_env_var('TRANSIFEX_USERNAME')
                       if get_env_var('TRANSIFEX_PASSWORD') else
                       get_env_var('TRANSIFEX_API_KEY'))
     message = 'TRANSIFEX_USERNAME and TRANSIFEX_PASSWORD or '\
               'TRANSIFEX_API_KEY must be set'
     assert transifex_info, message
Пример #6
0
 def initialize(self, args):
     try:
         self.is_verbose = args.verbose
         self.is_dryrun = args.dry_run
         self.title = args.title
         # validate channel names
         validate_channel(args.uplift_to)
         validate_channel(args.start_from)
         # read github token FIRST from CLI, then from .npmrc
         self.github_token = get_env_var('GITHUB_TOKEN')
         if len(self.github_token) == 0:
             try:
                 result = execute(['npm', 'config', 'get', 'BRAVE_GITHUB_TOKEN']).strip()
                 if result == 'undefined':
                     raise Exception('`BRAVE_GITHUB_TOKEN` value not found!')
                 self.github_token = result
             except Exception as e:
                 print('[ERROR] no valid GitHub token was found either in npmrc or ' +
                       'via environment variables (BRAVE_GITHUB_TOKEN)')
                 return 1
         # if `--owners` is not provided, fall back to user owning token
         self.parsed_owners = parse_user_logins(self.github_token, args.owners, verbose=self.is_verbose)
         if len(self.parsed_owners) == 0:
             self.parsed_owners = [get_authenticated_user_login(self.github_token)]
         self.labels = parse_labels(self.github_token, BRAVE_CORE_REPO, args.labels, verbose=self.is_verbose)
         if self.is_verbose:
             print('[INFO] config: ' + str(vars(self)))
         return 0
     except Exception as e:
         print('[ERROR] error returned from GitHub API while initializing config: ' + str(e))
         return 1
Пример #7
0
 def initialize(self, args):
     try:
         self.is_verbose = args.verbose
         self.is_dryrun = args.dry_run
         self.title = args.title
         # validate channel names
         validate_channel(args.uplift_to)
         validate_channel(args.start_from)
         # read github token FIRST from CLI, then from .npmrc
         self.github_token = get_env_var('GITHUB_TOKEN')
         if len(self.github_token) == 0:
             try:
                 result = execute(['npm', 'config', 'get', 'BRAVE_GITHUB_TOKEN']).strip()
                 if result == 'undefined':
                     raise Exception('`BRAVE_GITHUB_TOKEN` value not found!')
                 self.github_token = result
             except Exception as e:
                 print('[ERROR] no valid GitHub token was found either in npmrc or ' +
                       'via environment variables (BRAVE_GITHUB_TOKEN)')
                 return 1
         # if `--owners` is not provided, fall back to user owning token
         self.parsed_owners = parse_user_logins(self.github_token, args.owners, verbose=self.is_verbose)
         if len(self.parsed_owners) == 0:
             self.parsed_owners = [get_authenticated_user_login(self.github_token)]
         self.labels = parse_labels(self.github_token, BRAVE_CORE_REPO, args.labels, verbose=self.is_verbose)
         if self.is_verbose:
             print('[INFO] config: ' + str(vars(self)))
         return 0
     except Exception as e:
         print('[ERROR] error returned from GitHub API while initializing config: ' + str(e))
         return 1
Пример #8
0
def main():

    args = parse_args()

    if args.debug:
        logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
        logging.debug('prerelease: {}'.format(args.prerelease))

    if not os.environ.get('npm_config_brave_version'):
        message = ('Error: Please set the $npm_config_brave_version'
                   'environment variable')
        exit(message)

    BRAVE_VERSION = os.environ.get('npm_config_brave_version')

    repo = GitHub(get_env_var('GITHUB_TOKEN')).repos(BRAVE_REPO)

    tag = BRAVE_VERSION
    logging.debug("Tag: {}".format(tag))

    # If we are publishing a prerelease, the release can only be in draft mode. If we
    # are publishing a full release, it is allowed to already be a published release.
    if args.prerelease:
        release = get_draft(repo, tag)
    else:
        release = get_release(repo, tag, allow_published_release_updates=True)

    tag_name = release['tag_name']
    logging.debug("release[id]: {}".format(release['id']))

    logging.info("Releasing {}".format(tag_name))
    publish_release(repo, release['id'], tag_name, args.prerelease, logging)
Пример #9
0
def get_github_token():
    github_token = get_env_var('GITHUB_TOKEN')
    if len(github_token) == 0:
        result = execute(['npm', 'config', 'get', 'BRAVE_GITHUB_TOKEN']).strip()
        if result == 'undefined':
            raise Exception('`BRAVE_GITHUB_TOKEN` value not found!')
        return result
def main():
    """
    Download the brave-browser/CHANGELOG.md file, parse it and
    convert to markdown, then update the release notes for the
    release specified.

    """

    args = parse_args()

    if args.debug:
        logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)

    changelog_url = args.url

    tag = args.tag

    if not re.match(r'^refs/tags/', tag) and not re.match(r'^v', tag):
        logging.error(" Tag prefix must contain {} or {}".format(
            "\"refs/tags/\"", "\"v\""))
        exit(1)

    match = re.match(r'^refs/tags/(.*)$', tag)
    if match:
        tag = match.group(1)

    match = re.match(r'^v(.*)$', tag)
    if match:
        version = match.group(1)

    logging.debug("CHANGELOG_URL: {}".format(changelog_url))
    logging.debug("TAG: {}".format(tag))
    logging.debug("VERSION: {}".format(version))

    changelog_txt = download_from_url(args, logging, changelog_url)

    tag_changelog_txt = render_markdown(changelog_txt, version, logging)

    # BRAVE_REPO is defined in lib/helpers.py
    repo = GitHub(get_env_var('GITHUB_TOKEN')).repos(BRAVE_REPO)
    release = get_release(repo, tag, allow_published_release_updates=True)

    logging.debug("Release body before update: \n\'{}\'".format(
        release['body']))

    logging.info("Merging original release body with changelog")
    new_body = release['body'] + '\n\n### Release Notes' + '\n\n' + \
        tag_changelog_txt
    logging.debug("release body is now: \n\'{}\'".format(new_body))

    data = dict(tag_name=tag, name=release['name'], body=new_body)
    id = release['id']
    logging.debug("Updating release with id: {}".format(id))
    release = retry_func(
        lambda run: repo.releases.__call__(f'{id}').patch(data=data),
        catch=requests.exceptions.ConnectionError,
        retries=3)
    logging.debug("Release body after update: \n\'{}\'".format(
        release['body']))
Пример #11
0
def main():
    repo = GitHub(get_env_var('GITHUB_TOKEN')).repos(BRAVE_REPO)

    release = get_draft(repo, get_brave_version())
    commit_tag = get_commit_tag(get_raw_version())

    print("[INFO] Releasing {}".format(release['tag_name']))
    publish_release(repo, release['id'], get_tag(), commit_tag)
Пример #12
0
def main():

    """
    Download the brave-browser/CHANGELOG.md file, parse it and
    convert to markdown, then update the release notes for the
    release specified.

    """

    args = parse_args()

    if args.debug:
        logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)

    changelog_url = args.url

    tag = args.tag

    if not re.match(r'^refs/tags/', tag) and not re.match(r'^v', tag):
        logging.error(" Tag prefix must contain {} or {}".format("\"refs/tags/\"", "\"v\""))
        exit(1)

    match = re.match(r'^refs/tags/(.*)$', tag)
    if match:
        tag = match.group(1)

    match = re.match(r'^v(.*)$', tag)
    if match:
        version = match.group(1)

    logging.debug("CHANGELOG_URL: {}".format(changelog_url))
    logging.debug("TAG: {}".format(tag))
    logging.debug("VERSION: {}".format(version))

    changelog_txt = download_from_url(args, logging, changelog_url)

    tag_changelog_txt = render_markdown(changelog_txt, version, logging)

    # BRAVE_REPO is defined in lib/helpers.py
    repo = GitHub(get_env_var('GITHUB_TOKEN')).repos(BRAVE_REPO)
    release = get_release(repo, tag, allow_published_release_updates=True)

    logging.debug("Release body before update: \n\'{}\'".format(release['body']))

    logging.info("Merging original release body with changelog")
    new_body = release['body'] + '\n\n### Release Notes' + '\n\n' + \
        tag_changelog_txt
    logging.debug("release body is now: \n\'{}\'".format(new_body))

    data = dict(tag_name=tag, name=release['name'], body=new_body)
    id = release['id']
    logging.debug("Updating release with id: {}".format(id))
    release = retry_func(
        lambda run: repo.releases.__call__(f'{id}').patch(data=data),
        catch=requests.exceptions.ConnectionError, retries=3
    )
    logging.debug("Release body after update: \n\'{}\'".format(release['body']))
Пример #13
0
 def __init__(self,
              project_name,
              organization_name=brave_organization_name):
     self._organization_name = organization_name
     self._project_name = project_name
     self._transifex_api_key = get_env_var('TRANSIFEX_API_KEY')
     assert self._organization_name, \
         'TransifexAPIV3Wrapper: organization_name is not set.'
     assert self._project_name, \
         'TransifexAPIV3Wrapper: project_name is not set.'
     assert self._transifex_api_key, \
         'TRANSIFEX_API_KEY environmental var is not set.'
     self.__auth()
Пример #14
0
def main():

    args = parse_args()

    if args.debug:
        logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
        logging.debug('prerelease: {}'.format(args.prerelease))

    if not os.environ.get('npm_config_onevn_version'):
        message = ('Error: Please set the $npm_config_onevn_version'
                   'environment variable')
        exit(message)

    ONEVN_VERSION = os.environ.get('npm_config_onevn_version')

    repo = GitHub(get_env_var('GITHUB_TOKEN')).repos(ONEVN_REPO)

    release = get_draft(repo, ONEVN_VERSION)

    tag_name = release['tag_name']

    logging.info("Releasing {}".format(tag_name))
    publish_release(repo, release['id'], tag_name, args.prerelease, logging)
Пример #15
0
def main():

    args = parse_args()

    if args.debug:
        logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
        logging.debug('prerelease: {}'.format(args.prerelease))

    if not os.environ.get('npm_config_brave_version'):
        message = ('Error: Please set the $npm_config_brave_version'
                   'environment variable')
        exit(message)

    BRAVE_VERSION = os.environ.get('npm_config_brave_version')

    repo = GitHub(get_env_var('GITHUB_TOKEN')).repos(BRAVE_REPO)

    release = get_draft(repo, BRAVE_VERSION)

    tag_name = release['tag_name']

    logging.info("Releasing {}".format(tag_name))
    publish_release(repo, release['id'], tag_name, args.prerelease, logging)
Пример #16
0
def main():
    args = parse_args()
    print('[INFO] Running upload...')

    # Repo is defined in lib/helpers.py for now
    repo = GitHub(get_env_var('GITHUB_TOKEN')).repos(BRAVE_REPO)

    tag = get_brave_version()
    release = get_draft(repo, tag)

    if not release:
        print(
            "[INFO] No existing release found, creating new release for this upload"
        )
        release = create_release_draft(repo, tag)

    print('[INFO] Uploading release {}'.format(release['tag_name']))
    # Upload Brave with GitHub Releases API.
    upload_brave(repo,
                 release,
                 os.path.join(dist_dir(), DIST_NAME),
                 force=args.force)
    upload_brave(repo,
                 release,
                 os.path.join(dist_dir(), SYMBOLS_NAME),
                 force=args.force)
    # if PLATFORM == 'darwin':
    #   upload_brave(repo, release, os.path.join(dist_dir(), DSYM_NAME))
    # elif PLATFORM == 'win32':
    #   upload_brave(repo, release, os.path.join(dist_dir(), PDB_NAME))

    # Upload chromedriver and mksnapshot.
    chromedriver = get_zip_name('chromedriver', get_chromedriver_version())
    upload_brave(repo,
                 release,
                 os.path.join(dist_dir(), chromedriver),
                 force=args.force)

    pkgs = yield_brave_packages(output_dir(), release_channel(),
                                get_raw_version())

    if PLATFORM == 'darwin':
        for pkg in pkgs:
            upload_brave(repo,
                         release,
                         os.path.join(output_dir(), pkg),
                         force=args.force)
    elif PLATFORM == 'win32':
        if get_target_arch() == 'x64':
            upload_brave(repo,
                         release,
                         os.path.join(output_dir(), 'brave_installer.exe'),
                         'brave_installer-x64.exe',
                         force=args.force)
        else:
            upload_brave(repo,
                         release,
                         os.path.join(output_dir(), 'brave_installer.exe'),
                         'brave_installer-ia32.exe',
                         force=args.force)
    else:
        if get_target_arch() == 'x64':
            for pkg in pkgs:
                upload_brave(repo,
                             release,
                             os.path.join(output_dir(), pkg),
                             force=args.force)
        else:
            upload_brave(repo,
                         release,
                         os.path.join(output_dir(), 'brave-i386.rpm'),
                         force=args.force)
            upload_brave(repo,
                         release,
                         os.path.join(output_dir(), 'brave-i386.deb'),
                         force=args.force)

    # mksnapshot = get_zip_name('mksnapshot', get_brave_version())
    # upload_brave(repo, release, os.path.join(dist_dir(), mksnapshot))

    # if PLATFORM == 'win32' and not tag_exists:
    #   # Upload PDBs to Windows symbol server.
    #   run_python_script('upload-windows-pdb.py')

    versions = parse_version(args.version)
    version = '.'.join(versions[:3])
    print('[INFO] Finished upload')
Пример #17
0
def main():
    args = parse_args()
    print('[INFO] Running upload...')

    # Enable urllib3 debugging output
    if os.environ.get('DEBUG_HTTP_HEADERS') == 'true':
        logging.basicConfig(level=logging.DEBUG)
        logging.getLogger("urllib3").setLevel(logging.DEBUG)
        logging.debug(
            "DEBUG_HTTP_HEADERS env var is enabled, logging HTTP headers")
        debug_requests_on()

    # BRAVE_REPO is defined in lib/helpers.py for now
    repo = GitHub(get_env_var('GITHUB_TOKEN')).repos(BRAVE_REPO)

    tag = get_brave_version()
    release = get_release(repo, tag, allow_published_release_updates=False)

    if not release:
        print("[INFO] No existing release found, creating new "
              "release for this upload")
        release = create_release_draft(repo, tag)

    print('[INFO] Uploading release {}'.format(release['tag_name']))
    # Upload Brave with GitHub Releases API.
    upload_brave(repo,
                 release,
                 os.path.join(dist_dir(), DIST_NAME),
                 force=args.force)
    upload_brave(repo,
                 release,
                 os.path.join(dist_dir(), SYMBOLS_NAME),
                 force=args.force)
    # if PLATFORM == 'darwin':
    #     upload_brave(repo, release, os.path.join(dist_dir(), DSYM_NAME))
    # elif PLATFORM == 'win32':
    #     upload_brave(repo, release, os.path.join(dist_dir(), PDB_NAME))

    pkgs = get_brave_packages(output_dir(), release_channel(),
                              get_raw_version())

    if PLATFORM == 'darwin':
        for pkg in pkgs:
            upload_brave(repo,
                         release,
                         os.path.join(output_dir(), pkg),
                         force=args.force)
    elif PLATFORM == 'win32':
        if get_target_arch() == 'x64':
            upload_brave(repo,
                         release,
                         os.path.join(output_dir(), 'brave_installer.exe'),
                         'brave_installer-x64.exe',
                         force=args.force)
            for pkg in pkgs:
                upload_brave(repo,
                             release,
                             os.path.join(output_dir(), pkg),
                             force=args.force)
        else:
            upload_brave(repo,
                         release,
                         os.path.join(output_dir(), 'brave_installer.exe'),
                         'brave_installer-ia32.exe',
                         force=args.force)
            for pkg in pkgs:
                upload_brave(repo,
                             release,
                             os.path.join(output_dir(), pkg),
                             force=args.force)
    else:
        if get_target_arch() == 'x64':
            for pkg in pkgs:
                upload_brave(repo,
                             release,
                             os.path.join(output_dir(), pkg),
                             force=args.force)
        else:
            upload_brave(repo,
                         release,
                         os.path.join(output_dir(), 'brave-i386.rpm'),
                         force=args.force)
            upload_brave(repo,
                         release,
                         os.path.join(output_dir(), 'brave-i386.deb'),
                         force=args.force)

    # mksnapshot = get_zip_name('mksnapshot', get_brave_version())
    # upload_brave(repo, release, os.path.join(dist_dir(), mksnapshot))

    # if PLATFORM == 'win32' and not tag_exists:
    #     # Upload PDBs to Windows symbol server.
    #     run_python_script('upload-windows-pdb.py')

    if os.environ.get('DEBUG_HTTP_HEADERS') == 'true':
        debug_requests_off()
    print('[INFO] Finished upload')
Пример #18
0
def download_from_github(args, logging):
    file_list = []

    # BRAVE_REPO defined in helpers.py
    repo = GitHub(get_env_var('GITHUB_TOKEN')).repos(BRAVE_REPO)

    if args.tag:
        tag_name = args.tag
    else:
        tag_name = get_brave_version()

    release = None
    releases = get_releases_by_tag(repo, tag_name, include_drafts=True)
    if releases:
        if len(releases) > 1:
            exit("Error: More than 1 release exists with the tag: \'{}\'".
                 format(tag_name))
        release = releases[0]
    else:
        exit("Error: Did not get the release \'{}\' from Github.".format(
            tag_name))

    found_assets_in_github_release = {}

    for asset in release['assets']:
        if re.match(r'.*\.dmg$', asset['name']):
            if args.uploaded:
                if not args.platform:
                    args.platform = []
                args.platform.append('darwin')
            found_assets_in_github_release['darwin'] = {}
            found_assets_in_github_release['darwin']['name'] = asset['name']
            found_assets_in_github_release['darwin']['url'] = asset['url']
        elif re.match(r'brave_installer-ia32\.exe$', asset['name']):
            if args.uploaded:
                if not args.platform:
                    args.platform = []
                args.platform.append('win32')
            found_assets_in_github_release['win32'] = {}
            found_assets_in_github_release['win32']['name'] = asset['name']
            found_assets_in_github_release['win32']['url'] = asset['url']
        elif re.match(r'brave_installer-x64\.exe$', asset['name']):
            if args.uploaded:
                if not args.platform:
                    args.platform = []
                args.platform.append('win64')
            found_assets_in_github_release['win64'] = {}
            found_assets_in_github_release['win64']['name'] = asset['name']
            found_assets_in_github_release['win64']['url'] = asset['url']

    logging.debug("Found assets in github release: {}".format(
        found_assets_in_github_release))

    for requested_platform in args.platform:
        logging.debug(
            "Verifying platform \'{}\' exists in GitHub release".format(
                requested_platform))
        if requested_platform not in found_assets_in_github_release.keys():
            logging.error(
                "Platform \'{}\' does not exist in GitHub release".format(
                    requested_platform))
            exit(1)

    for platform in args.platform:
        if args.debug:
            logging.debug("GitHub asset_url: {}".format(
                found_assets_in_github_release[platform]['url'] + '/' +
                found_assets_in_github_release[platform]['name']))

        # Instantiate new requests session, versus reusing the repo session above.
        # Headers was likely being reused in that session, and not allowing us
        # to set the Accept header to the below.
        headers = {
            'Accept': 'application/octet-stream',
            'Authorization': 'token ' + get_env_var('GITHUB_TOKEN')
        }

        asset_url = found_assets_in_github_release[platform]['url']

        if args.debug:
            # disable urllib3 logging for this session to avoid showing
            # access_token in logs
            logging.getLogger("urllib3").setLevel(logging.WARNING)

        r = requests.get(asset_url, headers=headers, stream=True)

        if args.debug:
            logging.getLogger("urllib3").setLevel(logging.DEBUG)

        logging.debug("Writing GitHub download to file: {}".format(
            found_assets_in_github_release[platform]['name']))

        with open(found_assets_in_github_release[platform]['name'], 'wb') as f:
            for chunk in r.iter_content(chunk_size=1024):
                if chunk:
                    f.write(chunk)

        logging.debug("Requests Response status_code: {}".format(
            r.status_code))
        if r.status_code == 200:
            file_list.append('./' +
                             found_assets_in_github_release[platform]['name'])
        else:
            logging.debug("Requests Response status_code != 200: {}".format(
                r.status_code))

    if len(file_list) < len(args.platform):
        for item in args.platform:
            logging.error("Cannot get requested file from Github! {}".format(
                found_assets_in_github_release[item]['name']))
        remove_github_downloaded_files(file_list, logging)
        exit(1)

    return file_list
Пример #19
0
def auth_token():
  token = get_env_var('GITHUB_TOKEN')
  message = ('Error: Please set the $ELECTRON_GITHUB_TOKEN '
             'environment variable, which is your personal token')
  assert token, message
  return token
Пример #20
0
def download_from_github(args, logging):
    file_list = []

    # BRAVE_REPO defined in helpers.py
    repo = GitHub(get_env_var('GITHUB_TOKEN')).repos(BRAVE_REPO)

    if args.tag:
        tag_name = args.tag
    else:
        tag_name = get_brave_version()

    release = None
    releases = get_releases_by_tag(repo, tag_name, include_drafts=True)
    if releases:
        if len(releases) > 1:
            exit("Error: More than 1 release exists with the tag: \'{}\'".format(tag_name))
        release = releases[0]

    for asset in release['assets']:
        if re.match(r'.*\.dmg$', asset['name']) \
                or re.match(r'brave_installer.*\.exe$', asset['name']):
            filename = asset['name']
            asset_url = asset['url']
            if args.debug:
                logging.debug("GitHub asset_url: {}".format(
                    asset_url + '/' + filename))

            # Instantiate new requests session, versus reusing the repo session above.
            # Headers was likely being reused in that session, and not allowing us
            # to set the Accept header to the below.
            headers = {'Accept': 'application/octet-stream'}

            asset_auth_url = asset_url + '?access_token=' + \
                os.environ.get('BRAVE_GITHUB_TOKEN')

            if args.debug:
                # disable urllib3 logging for this session to avoid showing
                # access_token in logs
                logging.getLogger("urllib3").setLevel(logging.WARNING)

            r = requests.get(asset_auth_url, headers=headers, stream=True)

            if args.debug:
                logging.getLogger("urllib3").setLevel(logging.DEBUG)

            with open(filename, 'wb') as f:
                for chunk in r.iter_content(chunk_size=1024):
                    if chunk:
                        f.write(chunk)

            logging.debug(
                "Requests Response status_code: {}".format(r.status_code))
            if r.status_code == 200:
                file_list.append('./' + filename)
            else:
                logging.debug(
                    "Requests Response status_code != 200: {}".format(r.status_code))

    if len(file_list) < 3:
        logging.error(
            "Cannot get all 3 install files from Github! (\'*.dmg\', \'brave_installer-x64.exe\',"
            " \'brave-installer-ia32.exe\')")
        remove_github_downloaded_files(file_list, logging)
        exit(1)

    return file_list
Пример #21
0
def auth_token():
    token = get_env_var('GITHUB_TOKEN')
    message = ('Error: Please set the $ELECTRON_GITHUB_TOKEN '
               'environment variable, which is your personal token')
    assert token, message
    return token
Пример #22
0
def download_from_github(args, logging):
    file_list = []

    # BRAVE_REPO defined in helpers.py
    repo = GitHub(get_env_var('GITHUB_TOKEN')).repos(BRAVE_REPO)

    if args.tag:
        tag_name = args.tag
    else:
        tag_name = get_brave_version()

    release = None
    releases = get_releases_by_tag(repo, tag_name, include_drafts=True)
    if releases:
        if len(releases) > 1:
            exit("Error: More than 1 release exists with the tag: \'{}\'".format(tag_name))
        release = releases[0]
    else:
        exit("Error: Did not get the release \'{}\' from Github.".format(tag_name))

    found_assets_in_github_release = {}

    for asset in release['assets']:
        if re.match(r'.*\.dmg$', asset['name']):
            if args.uploaded:
                if not args.platform:
                    args.platform = []
                args.platform.append('darwin')
            found_assets_in_github_release['darwin'] = {}
            found_assets_in_github_release['darwin']['name'] = asset['name']
            found_assets_in_github_release['darwin']['url'] = asset['url']
        elif re.match(r'brave_installer-ia32\.exe$', asset['name']):
            if args.uploaded:
                if not args.platform:
                    args.platform = []
                args.platform.append('win32')
            found_assets_in_github_release['win32'] = {}
            found_assets_in_github_release['win32']['name'] = asset['name']
            found_assets_in_github_release['win32']['url'] = asset['url']
        elif re.match(r'brave_installer-x64\.exe$', asset['name']):
            if args.uploaded:
                if not args.platform:
                    args.platform = []
                args.platform.append('win64')
            found_assets_in_github_release['win64'] = {}
            found_assets_in_github_release['win64']['name'] = asset['name']
            found_assets_in_github_release['win64']['url'] = asset['url']

    logging.debug("Found assets in github release: {}".format(
                  found_assets_in_github_release))

    for requested_platform in args.platform:
        logging.debug("Verifying platform \'{}\' exists in GitHub release".
                      format(requested_platform))
        if requested_platform not in found_assets_in_github_release.keys():
            logging.error("Platform \'{}\' does not exist in GitHub release".
                          format(requested_platform))
            exit(1)

    for platform in args.platform:
        if args.debug:
            logging.debug("GitHub asset_url: {}".format(
                          found_assets_in_github_release[platform]['url'] + '/'
                          + found_assets_in_github_release[platform]['name']))

        # Instantiate new requests session, versus reusing the repo session above.
        # Headers was likely being reused in that session, and not allowing us
        # to set the Accept header to the below.
        headers = {'Accept': 'application/octet-stream'}

        asset_auth_url = found_assets_in_github_release[platform]['url'] + \
            '?access_token=' + os.environ.get('BRAVE_GITHUB_TOKEN')

        if args.debug:
            # disable urllib3 logging for this session to avoid showing
            # access_token in logs
            logging.getLogger("urllib3").setLevel(logging.WARNING)

        r = requests.get(asset_auth_url, headers=headers, stream=True)

        if args.debug:
            logging.getLogger("urllib3").setLevel(logging.DEBUG)

        logging.debug("Writing GitHub download to file: {}".format(
                      found_assets_in_github_release[platform]['name']))

        with open(found_assets_in_github_release[platform]['name'], 'wb') as f:
            for chunk in r.iter_content(chunk_size=1024):
                if chunk:
                    f.write(chunk)

        logging.debug(
            "Requests Response status_code: {}".format(r.status_code))
        if r.status_code == 200:
            file_list.append('./' + found_assets_in_github_release[platform]['name'])
        else:
            logging.debug(
                "Requests Response status_code != 200: {}".format(r.status_code))

    if len(file_list) < len(args.platform):
        for item in args.platform:
            logging.error(
                "Cannot get requested file from Github! {}".format(found_assets_in_github_release[item]['name']))
        remove_github_downloaded_files(file_list, logging)
        exit(1)

    return file_list