/**
  * Create a github client wrapper with automated token-based authentication.
  *
  * @param string $token The API token to authenticate with.
  * @param string $owner The owner name of the github repository.
  * @param string $repo The name of the github repository.
  * @param string $apiUrl The base url to the github API if different from the main github site (i.e., GitHub Enterprise).
  * @return self The github client wrapper, authenticated against the API.
  * @throws \Exception if the token is invalid
  */
 public static function createWithToken($token, $owner, $repo, $apiUrl = null)
 {
     $client = new Client();
     if ($apiUrl !== null) {
         $client->setApiUrl($apiUrl);
     }
     $client->setToken($token);
     // Verify that the token works
     $users = $client->getReceiver(\FlexyProject\GitHub\Client::USERS);
     $authenticatedUser = $users->getUser();
     if (empty($authenticatedUser)) {
         throw new \Exception('Bad credentials');
     }
     return new static($client, $owner, $repo);
 }