docs: def check_repo_exists(deploy_repo, service='github', *, auth=None,
      headers=None, ask=False):
      """
      Checks that the repository exists on GitHub.
  
      This should be done before attempting generate a key to deploy to that
      repo.
  
      Raises ``RuntimeError`` if the repo is not valid.
  
      Returns a dictionary with the following keys:
  
      - 'private': Indicates whether or not the repo requires authorization to
        access. Private repos require authorization.
      - 'service': For service='travis', is 'travis-ci.com' or 'travis-ci.org',
        depending on which should be used. Otherwise it is just equal to ``service``.
  
      For service='travis', if ask=True, it will ask at the command line if both
      travis-ci.org and travis-ci.com exist. If ask=False, service='travis' will
      check travis-ci.com first and only check travis-ci.org if it doesn't
      exist. ask=True does nothing for service='github',
      service='travis-ci.com', service='travis-ci.org'.
  
      """
      headers = headers or {}
      if deploy_repo.count("/") != 1:
          raise RuntimeError('"{deploy_repo}" should be in the form username/repo'.format(deploy_repo=deploy_repo))
  
      user, repo = deploy_repo.split('/')
      if service == 'github':
          REPO_URL = 'https://api.github.com/repos/{user}/{repo}'
      elif service == 'travis' or service == 'travis-ci.com':
          REPO_URL = 'https://api.travis-ci.com/repo/{user}%2F{repo}'
          headers = {**headers, **Travis_APIv3}
      elif service == 'travis-ci.org':
          REPO_URL = 'https://api.travis-ci.org/repo/{user}%2F{repo}'
          headers = {**headers, **Travis_APIv3}
      else:
          raise RuntimeError('Invalid service specified for repo check (should be one of {"github", "travis", "travis-ci.com", "travis-ci.org"}')
  
      wiki = False
      if repo.endswith('.wiki') and service == 'github':
          wiki = True
          repo = repo[:-5]
  
      def _try(url):
          r = requests.get(url, auth=auth, headers=headers)
  
          if r.status_code in [requests.codes.not_found, requests.codes.forbidden]:
              return False
          if service == 'github':
              GitHub_raise_for_status(r)
          else:
              r.raise_for_status()
          return r
  
      r = _try(REPO_URL.format(user=urllib.parse.quote(user),
          repo=urllib.parse.quote(repo)))
      r_active = r and (service == 'github' or r.json().get('active', False))
  
      if service == 'travis':
          REPO_URL = 'https://api.travis-ci.org/repo/{user}%2F{repo}'
          r_org = _try(REPO_URL.format(user=urllib.parse.quote(user),
              repo=urllib.parse.quote(repo)))
          r_org_active = r_org and r_org.json().get('active', False)
          if not r_active:
              if not r_org_active:
                  raise RuntimeError('"{user}/{repo}" not found on travis-ci.org or travis-ci.com'.format(user=user, repo=repo))
              r = r_org
              r_active = r_org_active
              service = 'travis-ci.org'
          else:
              if r_active and r_org_active:
                  if ask:
                      while True:
                          print(green("{user}/{repo} appears to exist on both travis-ci.org and travis-ci.com.".format(user=user, repo=repo)))
                          preferred = input("Which do you want to use? [{default}/travis-ci.org] ".format(default=blue("travis-ci.com")))
                          preferred = preferred.lower().strip()
                          if preferred in ['o', 'org', '.org', 'travis-ci.org']:
                              r = r_org
                              service = 'travis-ci.org'
                              break
                          elif preferred in ['c', 'com', '.com', 'travis-ci.com', '']:
                              service = 'travis-ci.com'
                              break
                          else:
                              print(red("Please type 'travis-ci.com' or 'travis-ci.org'."))
                  else:
                      service = 'travis-ci.com'
              else:
                  # .com but not .org.
                  service = 'travis-ci.com'
  
      if not r_active:
          msg = '' if auth else '. If the repo is private, then you need to authenticate.'
          raise RuntimeError('"{user}/{repo}" not found on {service}{msg}'.format(user=user,
                                                                                  repo=repo,
                                                                                  service=service,
                                                                                  msg=msg))
  
      private = r.json().get('private', False)
  
      if wiki and not private:
          # private wiki needs authentication, so skip check for existence
          p = subprocess.run(['git', 'ls-remote', '-h', 'https://github.com/{user}/{repo}.wiki'.format(
              user=user, repo=repo)], stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False)
          if p.stderr or p.returncode:
              raise RuntimeError('Wiki not found. Please create a wiki')
  
      return {
          'private': private,
          'service': service,
          }