Skip to content

Commit

Permalink
GithubReleases: drop parsedown and loads release description in html …
Browse files Browse the repository at this point in the history
…mode (mediatype)
  • Loading branch information
f3l1x committed Oct 18, 2016
1 parent 309c5ba commit 5155924
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 178 deletions.
5 changes: 0 additions & 5 deletions app/config/app/latte.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,3 @@ services:

# Composer
- addFilter('isPhpDependency', ['App\Core\Latte\Filters\ComposerHelper', 'isPhpDependency'])

# Parsedown / Markdown
- addFilter('parsedown', [@latte.parsedown, 'process'])

latte.parsedown: Minetro\Parsedown\ParsedownExtraAdapter
4 changes: 2 additions & 2 deletions app/model/commands/addons/content/GenerateContentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$counter = 0;
foreach ($addons as $addon) {
// Raw
$response = $this->github->readme($addon->owner, $addon->name, 'raw');
$response = $this->github->readme($addon->owner, $addon->name, GithubService::MEDIATYPE_HTML);
if ($response->isOk()) {
// Content
$addon->github->contentRaw = $response->getBody();
Expand All @@ -82,7 +82,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

// HTML
$response = $this->github->readme($addon->owner, $addon->name, 'html');
$response = $this->github->readme($addon->owner, $addon->name, GithubService::MEDIATYPE_HTML);
if ($response->isOk()) {
// Content
$addon->github->contentHtml = $response->getBody();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$storedReleases = $addon->github->releases->get()->fetchPairs('gid');

// Get all releases
$responses = $this->github->allReleases($addon->owner, $addon->name);
$responses = $this->github->allReleases($addon->owner, $addon->name, GithubService::MEDIATYPE_HTML);
if ($responses) {

foreach ((array) $responses as $response) {
Expand Down Expand Up @@ -103,8 +103,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
$githubRelease->draft = (bool) $release['draft'];
$githubRelease->prerelease = (bool) $release['prerelease'];
$githubRelease->createdAt = new DateTime($release['created_at']);
$githubRelease->crawledAt = new DateTime();
$githubRelease->publishedAt = new DateTime($release['published_at']);
$githubRelease->body = $release['body'];
$githubRelease->body = $release['body_html'];

// If its new one
if (!$githubRelease->isPersisted()) {
Expand Down
80 changes: 44 additions & 36 deletions app/model/webservices/github/GithubService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
final class GithubService
{

const MEDIATYPE_HTML = 'html';
const MEDIATYPE_HTML_JSON = 'html+json';
const MEDIATYPE_RAW = 'raw';

/** @var GithubClient */
private $client;

Expand Down Expand Up @@ -103,6 +107,31 @@ protected function parsePages($link)
return $pages;
}


/**
* @param string $mediatype
* @return array
*/
protected function mediatype($mediatype)
{
switch ($mediatype) {
case self::MEDIATYPE_HTML:
return ['Accept' => 'application/vnd.github.' . GithubClient::VERSION . '.html'];
break;

case self::MEDIATYPE_HTML_JSON:
return ['Accept' => 'application/vnd.github.' . GithubClient::VERSION . '.html+json'];
break;

case self::MEDIATYPE_RAW:
return ['Accept' => 'application/vnd.github.' . GithubClient::VERSION . '.raw'];
break;

default:
return [];
}
}

/**
* API *********************************************************************
*/
Expand All @@ -120,26 +149,12 @@ public function repo($owner, $repo)
/**
* @param string $owner
* @param string $repo
* @param string $mediatype
* @return Response
*/
public function readme($owner, $repo, $type = NULL)
public function readme($owner, $repo, $mediatype = NULL)
{
switch ($type) {
case 'html':
$headers = ['Accept' => 'application/vnd.github.' . GithubClient::VERSION . '.html'];
break;

case 'html+json':
$headers = ['Accept' => 'application/vnd.github.' . GithubClient::VERSION . '.html+json'];
break;

case 'raw':
$headers = ['Accept' => 'application/vnd.github.' . GithubClient::VERSION . '.raw'];
break;

default:
$headers = [];
}
$headers = $this->mediatype($mediatype);

return $this->call("/repos/$owner/$repo/readme", $headers);
}
Expand All @@ -148,26 +163,12 @@ public function readme($owner, $repo, $type = NULL)
* @param string $owner
* @param string $repo
* @param string $path
* @param string $mediatype
* @return Response
*/
public function content($owner, $repo, $path, $type = NULL)
public function content($owner, $repo, $path, $mediatype = NULL)
{
switch ($type) {
case 'html':
$headers = ['Accept' => 'application/vnd.github.' . GithubClient::VERSION . '.html'];
break;

case 'html+json':
$headers = ['Accept' => 'application/vnd.github.' . GithubClient::VERSION . '.html+json'];
break;

case 'raw':
$headers = ['Accept' => 'application/vnd.github.' . GithubClient::VERSION . '.raw'];
break;

default:
$headers = [];
}
$headers = $this->mediatype($mediatype);

return $this->call("/repos/$owner/$repo/contents/$path", $headers);
}
Expand Down Expand Up @@ -195,6 +196,7 @@ public function bower($owner, $repo)
/**
* @param string $owner
* @param string $repo
* @param int $page
* @return Response
*/
public function releases($owner, $repo, $page = NULL)
Expand All @@ -209,11 +211,17 @@ public function releases($owner, $repo, $page = NULL)
/**
* @param string $owner
* @param string $repo
* @param string $mediatype
* @return Response[]
*/
public function allReleases($owner, $repo)
public function allReleases($owner, $repo, $mediatype = NULL)
{
return $this->aggregate($this->client->getApiUrl("/repos/$owner/$repo/releases"));
$headers = $this->mediatype($mediatype);

return $this->aggregate(
$this->client->getApiUrl("/repos/$owner/$repo/releases"),
$headers
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
</h3>

<section>
{$release->body|escape|parsedown|noescape}
{$release->body|noescape}
</section>
</li>
</ul>
<p class="alert alert-warning">No release at this moment. <a href="{$addon->github->linker->getNewReleaseUrl()}">Try to create first one</a>.</p>
<p class="alert alert-warning" n:if="$addon->github->releases->count() <= 0">No release at this moment. <a href="{$addon->github->linker->getNewReleaseUrl()}">Try to create first one</a>.</p>
</div>
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
"nextras/orm": "dev-master",
"nextras/dbal": "^2.0.0",
"nextras/migrations": "~3.0.4",
"symfony/console": "~3.1.3",
"minetro/latte-parsedown-extra": "~1.1.0"
"symfony/console": "~3.1.3"
},
"require-dev": {
"nette/tester": "~1.7.0",
Expand Down
131 changes: 2 additions & 129 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5155924

Please sign in to comment.