Skip to content

Commit

Permalink
README update, code clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
owenconti committed May 18, 2020
1 parent 01a0146 commit 873cb5c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Oh See Gists

[![Current Release](https://img.shields.io/github/release/ohseesoftware/.svg?style=flat-square)](https://github.com/ohseesoftware/oh-see-gists/releases)
![Build Status Badge](https://github.com/ohseesoftware/oh-see-gists/workflows/Build/badge.svg)
[![Maintainability Score](https://img.shields.io/codeclimate/maintainability/ohseesoftware/oh-see-gists.svg?style=flat-square)](https://codeclimate.com/github/ohseesoftware/oh-see-gists)
[![Downloads](https://img.shields.io/packagist/dt/ohseesoftware/oh-see-gists.svg?style=flat-square)](https://packagist.org/packages/ohseesoftware/oh-see-gists)
[![MIT License](https://img.shields.io/github/license/ohseesoftware/oh-see-gists.svg?style=flat-square)](https://github.com/ohseesoftware/oh-see-gists/blob/master/LICENSE)

## Installation

Install the add-on:
Expand Down
37 changes: 19 additions & 18 deletions src/Listeners/HandleContentSaving.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,23 @@ private function saveGist(array $gistData, array &$gistBlocks): void
}
}

if (!empty($gistData['files'])) {
if (empty($gistId)) {
// Create a new Gist
$response = $this->github->gists()->create($gistData);

foreach ($gistBlocks as &$gistBlock) {
$gistBlock['gist_id'] = $response['id'];
}
} else {
// Update existing Gist
$this->github->gists()->update($gistId, $gistData);
if (empty($gistData['files'])) {
return;
}

if (empty($gistId)) {
// Create a new Gist
$response = $this->github->gists()->create($gistData);

foreach ($gistBlocks as &$gistBlock) {
$gistBlock['gist_id'] = $response['id'];
}

return;
}

// Update existing Gist
$this->github->gists()->update($gistId, $gistData);
}

private function getGistBlocks(array &$content): array
Expand All @@ -93,16 +97,13 @@ private function getGistBlocks(array &$content): array

foreach ($content as &$block) {
$type = $block['type'] ?? null;
if ($type !== 'set') {
$setType = $block['attrs']['values']['type'] ?? null;

if ($type !== 'set' || $setType !== 'gist_content') {
continue;
}

$type = $block['attrs']['values']['type'] ?? null;
$code = $block['attrs']['values']['code'] ?? null;

if ($type === 'gist_content' || !empty($code)) {
$gistBlocks[] = &$block['attrs']['values'];
}
$gistBlocks[] = &$block['attrs']['values'];
}

return $gistBlocks;
Expand Down

0 comments on commit 873cb5c

Please sign in to comment.