/**
  * @param string $type
  * @param string $user
  * @param string $repo
  *
  * @return bool|int false or the id of the hook
  */
 protected function getHookId($type, $user, $repo)
 {
     $hooks = $this->repoApi->hooks()->all($user, $repo);
     foreach ($hooks as $hook) {
         if ($hook['name'] === $type) {
             return $hook['id'];
         }
     }
     return false;
 }
 public function actionUnRegister(array $limitRepos = [])
 {
     /** @var $client \Github\Client */
     $client = Yii::$app->github->client();
     $repositories = Yii::$app->params['repositories'];
     if (!empty($limitRepos)) {
         $repositories = array_intersect($limitRepos, $repositories);
     }
     // remove hooks:
     foreach ($repositories as $urepo) {
         foreach ($this->hooks() as $hookName => $hookUrl) {
             $this->stdout("un-registering ");
             $this->stdout("{$hookName}", Console::BOLD);
             $this->stdout(" hook on ");
             $this->stdout($urepo, Console::BOLD);
             $this->stdout('...');
             list($user, $repo) = explode('/', $urepo);
             // https://developer.github.com/v3/repos/hooks/#create-a-hook
             $api = new Repo($client);
             // check if hook exists
             foreach ($api->hooks()->all($user, $repo) as $hook) {
                 if ($hook['name'] == 'web' && isset($hook['config']['url']) && $hook['config']['url'] === $hookUrl) {
                     $api->hooks()->remove($user, $repo, $hook['id']);
                 }
                 break;
             }
             $this->stdout("done.\n", Console::FG_GREEN, Console::BOLD);
         }
     }
 }