def update(filepath, github_account, discovery_documents): """Updates the google-api-php-client-services repository. Args: filepath (str): the directory to work in. github_account (GitHubAccount): the GitHub account to commit with. discovery_documents (dict(str, str)): a map of API IDs to Discovery document filenames to generate from. """ repo = _git.clone_from_github( _REPO_PATH, join(filepath, _REPO_NAME), github_account=github_account) venv_filepath = join(repo.filepath, 'venv') check_output(['virtualenv', venv_filepath, '-p', 'python2.7']) # The PHP client library generator is published in the # "google-apis-client-generator" package. check_output([join(venv_filepath, 'bin/pip'), 'install', 'google-apis-client-generator==1.6.1']) added, updated = _generate_and_commit_all_clients( repo, venv_filepath, discovery_documents) commit_count = len(added) + len(updated) if commit_count == 0: return _run_tests(repo) repo.soft_reset('HEAD~{}'.format(commit_count)) commitmsg = _commit_message.build(added, None, updated) repo.commit(commitmsg, github_account.name, github_account.email) repo.push()
def update(filepath, github_account): """Updates the discovery-artifact-manager repository. Args: filepath (str): the directory to work in. github_account (GitHubAccount): the GitHub account to commit and push with. """ repo = _git.clone_from_github(_REPO_PATH, join(filepath, _REPO_NAME), github_account=github_account) with TemporaryDirectory() as gopath: os.makedirs(join(gopath, 'src')) check_output([ 'ln', '-s', join(repo.filepath, 'src'), join(gopath, 'src/discovery-artifact-manager') ]) env = os.environ.copy() env['GOPATH'] = gopath check_output(['go', 'run', 'src/main/updatedisco/main.go'], cwd=repo.filepath, env=env) repo.add(['discoveries']) if not repo.diff_name_status(): return repo.commit('Autogenerated Discovery document update', github_account.name, github_account.email) repo.push()
def update(filepath, github_account): """Updates the discovery-artifact-manager repository. Args: filepath (str): the directory to work in. github_account (GitHubAccount): the GitHub account to commit and push with. """ repo = _git.clone_from_github(_repo_path(), join(filepath, _repo_name()), github_account=github_account) if _update_disco(repo, github_account) > 0: repo.push()
def release(filepath, github_account, npm_account, force=False): """Releases a new version in the google-api-nodejs-client repository. A release consists of: 1. A Git tag of a new version. 2. An update to "package.json" and "CHANGELOG.md". 3. A package pushed to npm. 4. Generated docs updated on the branch "gh-pages". Args: filepath (str): the directory to work in. github_account (GitHubAccount): the GitHub account to commit with. force (bool, optional): if true, the check that all authors since the last tag were `github_account` is ignored. """ repo = _git.clone_from_github(_REPO_PATH, join(filepath, _REPO_NAME), github_account=github_account) latest_tag = repo.latest_tag() version = _Version(latest_tag) if not _common.check_prerelease(repo, latest_tag, github_account, force): return _check_latest_version(latest_tag) added, deleted, updated = set(), set(), set() status_to_ids = { _git.Status.ADDED: added, _git.Status.DELETED: deleted, _git.Status.UPDATED: updated } diff_ns = repo.diff_name_status(rev=latest_tag) for filename, status in diff_ns: match = _SERVICE_FILENAME_RE.match(filename) if not match: continue status_to_ids.get(status, set()).add(match.group(1)) if deleted: version.bump_major() else: version.bump_minor() new_version = str(version) _update_package_json(repo, new_version) _update_changelog_md(repo, new_version, added, deleted, updated) _install_dependencies(repo) _build(repo) _run_tests(repo) repo.commit(new_version, github_account.name, github_account.email) repo.tag(new_version) repo.push() repo.push(tags=True) _publish_package(repo, npm_account) _update_and_publish_gh_pages(repo, new_version, github_account)
def update(filepath, github_account): """Updates the google-api-nodejs-client repository. Args: filepath (str): the directory to work in. github_account (GitHubAccount): the GitHub account to commit with. """ repo = _git.clone_from_github( _REPO_PATH, join(filepath, _REPO_NAME), github_account=github_account) _install_dependencies(repo) added, deleted, updated = _generate_all_clients(repo) if not any([added, deleted, updated]): return _build(repo) _run_tests(repo) commitmsg = _commit_message.build(added, deleted, updated) repo.add(['apis']) repo.commit(commitmsg, github_account.name, github_account.email) repo.push()
def discovery_documents(filepath, preferred=False, skip=None): """Returns a map of API IDs to Discovery document filenames. Args: filepath (str): the directory to work in. Discovery documents are downloaded to this directory. preferred (bool, optional): if true, only APIs marked as preferred are returned. skip (list, optional): a list of API IDs to skip. Returns: dict(string, string): a map of API IDs to Discovery document filenames. """ repo = _git.clone_from_github(_repo_path(), join(filepath, _repo_name())) filenames = glob.glob(join(repo.filepath, 'discoveries/*.json')) # Skip index.json. filenames = [x for x in filenames if os.path.basename(x) != 'index.json'] ddocs = {} for filename in filenames: id_ = None with open(filename) as file_: id_ = json.load(file_)['id'] # If an ID has already been visited, skip it. if id_ in ddocs: continue ddocs[id_] = filename if skip: _ = [ddocs.pop(id_, None) for id_ in skip] if not preferred: return ddocs index = {} with open(join(repo.filepath, 'discoveries/index.json')) as file_: index = json.load(file_) for api in index['items']: id_ = api['id'] if id_ in _ACTUALLY_PREFERRED: continue if api['preferred']: continue ddocs.pop(id_, None) return ddocs
def update(filepath, github_account): """Updates the google-api-ruby-client repository. Args: filepath (str): the directory to work in. discovery_documents (dict(str, str)): a map of API IDs to Discovery document filenames to generate from. github_account (GitHubAccount): the GitHub account to commit with. """ repo = _git.clone_from_github(_REPO_PATH, join(filepath, _REPO_NAME), github_account=github_account) _install_dependencies(repo) added, deleted, updated = _generate_all_clients(repo) if not any([added, deleted, updated]): return _run_tests(repo) commitmsg = _commit_message.build(added, deleted, updated) repo.add(['api_names_out.yaml', 'generated']) repo.commit(commitmsg, github_account.name, github_account.email) repo.push()
def create_pull_request(filepath, github_account): """Creates a pull request on the discovery-artifact-manager repository. Args: filepath (str): the directory to work in. github_account (GitHubAccount): the GitHub account to commit with. """ repo = _git.clone_from_github(_repo_path(), join(filepath, _repo_name()), github_account=github_account) branch = ('update-discovery-artifacts-' + datetime.datetime.now().strftime('%Y%m%d-%H%M%S')) repo.checkout_new(branch) if _update_disco(repo, github_account) > 0: repo.push(branch=branch) gh = Github(github_account.personal_access_token) gh_repo = gh.get_repo(_repo_path()) pr = gh_repo.create_pull( title='chore: autogenerated discovery document update', body='', base='master', head=branch)
def release(filepath, github_account, force=False): """Releases a new version in the google-api-php-client-services repository. A release consists of: 1. A Git tag of a new version. Args: filepath (str): the directory to work in. github_account (GitHubAccount): the GitHub account to commit with. force (bool, optional): if true, the check that all authors since the last tag were `github_account` is ignored. """ repo = _git.clone_from_github( _REPO_PATH, join(filepath, _REPO_NAME), github_account=github_account) latest_tag = repo.latest_tag() version = _Version(latest_tag) if not _common.check_prerelease(repo, latest_tag, github_account, force): return _run_tests(repo) version.bump_minor() new_version = str(version) repo.tag(new_version) repo.push(tags=True)