コード例 #1
0
ファイル: PublishRelease.php プロジェクト: silverstripe/cow
 /**
  * Update github release notes via github API
  *
  * @param OutputInterface $output
  * @param LibraryRelease $release
  */
 protected function updateGithubChangelog(OutputInterface $output, LibraryRelease $release)
 {
     $library = $release->getLibrary();
     if (!$library->hasGithubChangelog()) {
         return;
     }
     // Check github slug is available
     $slug = $release->getLibrary()->getGithubSlug();
     if (empty($slug)) {
         throw new InvalidArgumentException("Could not find github slug for " . $library->getName());
     }
     list($org, $repo) = explode('/', $slug);
     // Log release
     $version = $release->getVersion();
     $tag = $version->getValue();
     $this->log($output, "Creating github release <info>{$org}/{$repo} v{$tag}</info>");
     /** @var Repo $reposAPI */
     $client = $this->getGithubClient($output);
     $reposAPI = $client->api('repo');
     $releasesAPI = $reposAPI->releases();
     // Build release payload
     // Note target_commitish is omitted since the tag already exists
     $releaseData = ['tag_name' => $tag, 'name' => $tag, 'prerelease' => !$version->isStable(), 'draft' => false];
     $changelog = $release->getChangelog();
     if ($changelog) {
         $releaseData['body'] = $changelog;
     }
     // Determine if editing or creating a release
     $existing = null;
     try {
         sleep(1);
         // Ensure non-zero period between tagging and searching for this tag
         $existing = $releasesAPI->tag($org, $repo, $tag);
     } catch (RuntimeException $ex) {
         if ($ex->getCode() !== 404) {
             throw $ex;
         }
     }
     // Create or update
     if ($existing && !empty($existing['id'])) {
         $result = $releasesAPI->edit($org, $repo, $existing['id'], $releaseData);
         if (isset($result['created_at'])) {
             $this->log($output, "Successfully updated github release");
             return;
         }
     } else {
         $result = $releasesAPI->create($org, $repo, $releaseData);
         if (isset($result['created_at'])) {
             $this->log($output, "Successfully created at <info>" . $result['created_at'] . "</info>");
             return;
         }
     }
     $this->log($output, "Github API update failed for <info>" . $library->getName() . "</info>", "error");
 }
コード例 #2
0
ファイル: Library.php プロジェクト: silverstripe/cow
 /**
  * Serialise a plan to json
  *
  * @param LibraryRelease $plan
  * @return array Encoded json data
  */
 public function serialisePlan(LibraryRelease $plan)
 {
     $content = [];
     $name = $plan->getLibrary()->getName();
     $content[$name] = ['Version' => $plan->getVersion()->getValue(), 'Changelog' => $plan->getChangelog(), 'Items' => []];
     foreach ($plan->getItems() as $item) {
         $content[$name]['Items'] = array_merge($content[$name]['Items'], $item->getLibrary()->serialisePlan($item));
     }
     return $content;
 }