Пример #1
0
 /**
  * Use basic auth with a key comprised of our consumer key/consumer token
  * to request a bearer token.
  */
 public function getToken()
 {
     if (!is_null($this->token)) {
         return $this->token;
     }
     $auth_key = $this->getAuthKey();
     $browser = new \Buzz\Browser(new \Buzz\Client\Curl());
     $headers = array();
     $headers['Authorization'] = 'Basic ' . $auth_key;
     $headers['User-Agent'] = phpversion();
     $response = $browser->post('https://api.twitter.com/oauth2/token', $headers, 'grant_type=client_credentials');
     if (!$response->isOk()) {
         throw new \Exception($response->getReasonPhrase());
     } else {
         return json_decode($response->getContent())->access_token;
     }
 }
 /**
  * Send request to refresh article cache on Facebook
  *
  * @param int $number
  * @param int $languageId
  *
  * @return mixed response from Facebook about url, or array with error message
  */
 private function clearpageCache($number, $languageId)
 {
     $article = new \Article($languageId, $number);
     if (!$article->isPublished()) {
         return array('message' => $this->get('translator')->trans('fb.label.errornot'));
     }
     $url = \ShortURL::GetURL($article->getPublicationId(), $article->getLanguageId(), $article->getIssueNumber(), $article->getSectionNumber(), $article->getArticleNumber());
     try {
         $curlClient = new \Buzz\Client\Curl();
         $curlClient->setTimeout(10000);
         $browser = new \Buzz\Browser($curlClient);
         $result = $browser->post('https://graph.facebook.com/?id=' . $url . '&scrape=true');
         $urlInfo = json_decode($result->getContent(), true);
     } catch (\Buzz\Exception\ClientException $e) {
         return array('message' => $this->get('translator')->trans('fb.label.error'));
     }
     return $urlInfo;
 }
                $ticketStatus[$issueKey] = json_decode($response->getContent(), true);
                file_put_contents("data/" . $project . ".status.json", json_encode($ticketStatus, JSON_PRETTY_PRINT));
                printf("updated status... ");
            }
        }
        if ($ticketStatus[$issueKey]['status'] === 'pending') {
            printf("pending, skipped\n");
            continue;
        }
        if ($ticketStatus[$issueKey]['status'] === 'imported') {
            printf("imported, skipped\n");
            continue;
        }
        if ($ticketStatus[$issueKey]['status'] === 'failed') {
            printf("Error importing, retry... ", $issueKey);
        }
    }
    //printf("debug skip\n"); continue;
    $response = $client->post('https://api.github.com/repos/doctrine/' . $githubRepository . '/import/issues', $githubHeaders, json_encode($issue));
    if ($response->getStatusCode() >= 400) {
        printf("Error: " . $response->getContent());
        exit;
    }
    $ticketStatus[$issueKey] = json_decode($response->getContent(), true);
    file_put_contents("data/" . $project . ".status.json", json_encode($ticketStatus, JSON_PRETTY_PRINT));
    printf("imported %s\n", $issueKey);
    $count++;
    if ($count % 10 === 0) {
        //exit;
    }
}
Пример #4
0
$projects = (require 'projects.php');
$client = new \Buzz\Browser();
if (!isset($projects[$project])) {
    printf("Unknown project: {$project}\n");
    exit(2);
}
$githubRepository = $projects[$project];
$githubHeaders = ['User-Agent: Doctrine Jira Migration', 'Authorization: token ' . $_SERVER['GITHUB_TOKEN'], 'Accept: application/vnd.github.golden-comet-preview+json'];
if (!file_exists('data/' . $project . '.issues.json')) {
    printf("Requires issue numbers file.\n");
    exit(3);
}
$issueNumbers = json_decode(file_get_contents('data/' . $project . '.issues.json'), true);
$files = scandir('data/' . $project);
if (isset($argv[2])) {
    $files = [$argv[2] . ".json"];
}
$count = 0;
foreach ($files as $file) {
    if ($file === "." || $file === "..") {
        continue;
    }
    $issueKey = str_replace('.json', '', $file);
    $issue = json_decode(file_get_contents('data/' . $project . '/' . $file), true);
    // POST /repos/:owner/:repo/issues/:number/labels
    if (isset($issueNumbers[$issueKey]) && isset($issue['issue']['labels'])) {
        $githubId = $issueNumbers[$issueKey];
        $client->post('https://api.github.com/repos/doctrine/' . $githubRepository . '/issues/' . $githubId . '/labels', $githubHeaders, json_encode($issue['issue']['labels']));
        printf("https://github.com/doctrine/%s/issues/%d\n", $githubRepository, $githubId);
    }
}
Пример #5
0
        continue;
    }
    $attachments = scandir('data/attachments/' . $project . '/' . $issue);
    $gist = ['description' => 'Attachments to Doctrine Jira Issue ' . $issue . ' - https://github.com/doctrine/' . $githubRepository . '/issues/' . $issueMap[$issue], 'public' => false, 'files' => []];
    foreach ($attachments as $attachment) {
        if (in_array($attachment, ['.', '..'])) {
            continue;
        }
        $ext = pathinfo($attachment, PATHINFO_EXTENSION);
        if (!in_array($ext, ['php', 'patch', 'diff', 'xml', 'yml', 'txt', 'sql', 'log', 'xsd'])) {
            continue;
        }
        $gist['files'][$attachment]['content'] = file_get_contents('data/attachments/' . $project . '/' . $issue . '/' . $attachment);
    }
    if (count($gist['files']) === 0) {
        continue;
    }
    $response = $client->post('https://api.github.com/gists', $githubHeaders, json_encode($gist));
    if ($response->getStatusCode() >= 400) {
        throw new \Exception($issue . " attachment import failed: " . $response->getContent());
    }
    $gistData = json_decode($response->getContent(), true);
    $url = $gistData['html_url'];
    $comment = "Imported " . count($gist["files"]) . " attachments from Jira into " . $url . "\n\n";
    foreach ($gist['files'] as $file => $_) {
        $anchor = "#file-" . str_replace(".", "-", $file);
        $comment .= "- [" . $file . "](" . $url . $anchor . ")\n";
    }
    $response = $client->post('https://api.github.com/repos/doctrine/' . $githubRepository . '/issues/' . $issueMap[$issue] . '/comments', $githubHeaders, json_encode(['body' => $comment]));
    printf("%04d - Imported %s into %s\n", $count, $issue, $url);
}
Пример #6
0
 public function fetchHttp($url)
 {
     $hosts = $this->di->get('config')->phantomjs->hosts->toArray();
     shuffle($hosts);
     $host = reset($hosts);
     $post = 'url=' . $url;
     $browser = new \Buzz\Browser();
     try {
         $response = $browser->post($host, array(), $post);
     } catch (\Buzz\Exception\ClientException $e) {
         $this->flashJson(500, array(), $e->getMessage());
         return false;
     }
     return $response->getContent();
 }
    }
    $milestones[] = $milestone;
}
usort($milestones, function ($a, $b) {
    return version_compare($a['title'], $b['title']) * -1;
});
$response = $client->get('https://api.github.com/repos/doctrine/' . $githubRepository . '/milestones?state=all&per_page=100', $githubHeaders);
if ($response->getStatusCode() !== 200) {
    printf("Could not fetch existing Github Milestones\n");
    var_dump($response->getContent());
    exit(3);
}
$existingMilestones = [];
foreach (json_decode($response->getContent(), true) as $existingMilestone) {
    $existingMilestones[$existingMilestone['title']] = true;
}
$createdMilestones = [];
foreach ($milestones as $milestone) {
    if (isset($existingMilestones[$milestone['title']])) {
        continue;
    }
    $response = $client->post('https://api.github.com/repos/doctrine/' . $githubRepository . '/milestones', $githubHeaders, json_encode($milestone));
    if ($response->getStatusCode() < 400) {
        $data = json_decode($response->getContent(), true);
        $createdMilestones[$milestone['title']] = $data['id'];
    } else {
        printf('Error creating milestone "%s": %s', $milestone['title'], $response->getContent()) . "\n";
    }
}
printf('Created %d milestones from Jira to Github.', count($createdMilestones));
var_dump($createdMilestones);
Пример #8
0
        // @see http://brunorocha.org/python/dealing-with-linked-containers-dependency-in-docker-compose.html
        // for a better solution
        sleep(1);
    }
}
$channel = $connection->channel();
$channel->queue_declare('bookmark', false, false, false, false);
echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";
$fetcher = new Fetcher();
$callback = function ($msg) use($fetcher) {
    echo " [x] Received ", $msg->body, "\n";
    $message = json_decode($msg->body);
    $url = $message->url;
    $resource = $fetcher->fetch(new Url($url));
    echo sprintf('%s: %s%s', 'URL', $resource->getUrl(), PHP_EOL);
    echo sprintf('%s: %s%s', 'Type', $resource->getType(), PHP_EOL);
    echo sprintf('%s: %s%s', 'Title', $resource->getTitle(), PHP_EOL);
    echo sprintf('%s: %s%s', 'Description', $resource->getDescription(), PHP_EOL);
    echo sprintf('%s: %s%s', 'Image URL', $resource->getImageUrl(), PHP_EOL);
    echo sprintf('%s: %s%s', 'Video URL', $resource->getVideoUrl(), PHP_EOL);
    // call API
    $url = sprintf('http://api:8080/%s', $message->uuid);
    $headers = array('Content-Type' => 'application/json');
    $payload = json_encode((object) array('type' => $resource->getType(), 'title' => $resource->getTitle(), 'description' => $resource->getDescription(), 'imageUrl' => null !== $resource->getImageUrl() ? (string) $resource->getImageUrl() : null, 'videoUrl' => null !== $resource->getVideoUrl() ? (string) $resource->getVideoUrl() : null));
    $browser = new \Buzz\Browser(new \Buzz\Client\Curl());
    $browser->post($url, $headers, $payload);
};
$channel->basic_consume('bookmark', '', false, true, false, false, $callback);
while (true) {
    $channel->wait();
}