blob: eb26a13023685af2e5add47ab85e409f55bbda7a [file] [log] [blame]
#!/usr/bin/env python
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Exports local changes to web-platform-tests in Chromium to upstream repo.
This script checks LayoutTests/external/wpt for changes that can be exported,
then creates a patch, and creates and lands a pull request for the upstream
repository.
For this script to be effective it needs to be run on a regular
interval (e.g. every 10 mins).
"""
import argparse
import json
import logging
from webkitpy.common.host import Host
from webkitpy.w3c.test_exporter import TestExporter
_log = logging.getLogger(__name__)
def main():
logging.basicConfig(level=logging.INFO, format='%(message)s')
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
'--dry-run', action='store_true',
help='See what would be done without actually creating or merging '
'any pull requests.')
parser.add_argument(
'--gh-user',
help='GitHub user name. Can also be provided using the GH_USER '
'environment variable.')
parser.add_argument(
'--gh-token',
help='GitHub token or password. Can also be provided using the GH_TOKEN '
'environment variable.')
parser.add_argument('--gerrit-user', default=None,
help='Gerrit username (found on settings page or in .gitcookies).')
parser.add_argument('--gerrit-token', default=None,
help='Gerrit API key (found on settings page or in .gitcookies).')
parser.add_argument(
'--github-credentials-json',
help='A JSON file with schema {"GH_USER": "", "GH_TOKEN": ""}. '
'This will override credentials that were passed via command line or env var.')
args = parser.parse_args()
host = Host()
gh_user = args.gh_user
gh_token = args.gh_token
if not gh_user:
gh_user = host.environ.get('GH_USER')
if not gh_token:
gh_token = host.environ.get('GH_TOKEN')
if args.github_credentials_json:
with open(args.github_credentials_json, 'r') as f:
contents = json.load(f)
gh_user = contents['GH_USER']
gh_token = contents['GH_TOKEN']
if not (gh_user and gh_token):
parser.error('Must provide both gh_user and gh_token for GitHub.')
TestExporter(
host,
gh_user,
gh_token,
args.gerrit_user,
args.gerrit_token,
dry_run=args.dry_run
).run()
if __name__ == '__main__':
main()