/** * process a zendesk attachment, get it back to local (to avoid authorization problems) * * @param $attachmentUrl * @return string */ private function processZendeskAttachment($attachmentUrl) { $username = sprintf('%s/token', $this->config['zendesk_username']); $token = $this->config['zendesk_token']; $attachmentPath = '/images/'; if (!is_dir($attachmentPath)) { mkdir($attachmentPath); } parse_str(parse_url($attachmentUrl, PHP_URL_QUERY), $file); $uniqName = uniqid() . '_' . $file['name']; $filepath = $attachmentPath . $uniqName; $context = stream_context_create(['http' => ['header' => "Authorization: Basic " . base64_encode("{$username}:{$token}")]]); $data = file_get_contents($attachmentUrl, false, $context); file_put_contents($this->config['web_path'] . $filepath, $data); return [$uniqName, UrlHelper::getHost() . $filepath]; }
/** * Update webhooks for repo * * @param $repo * @param $secret */ private function updateRemoteStatus($repo, $secret) { foreach (['issues', 'issue_comment'] as $event) { $action = $repo->isUsed() ? 'subscribe' : 'unsubscribe'; $topic = 'https://github.com/' . $repo->getFullname() . '/events/' . $event; $this->client->getHttpClient()->post('/hub', ['hub.mode' => $action, 'hub.topic' => $topic, 'hub.callback' => UrlHelper::getHost() . '/github/fromissue', 'hub.secret' => $secret]); } }