Skip to content

Commit

Permalink
updated to add missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenMarkToms committed Jul 7, 2022
1 parent b46a324 commit c701846
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![Well](documentation/logo.jpg)
![Siteplot](documentation/logo.jpg)

## Project Setup

Expand Down
113 changes: 113 additions & 0 deletions app/Observers/RepositoryObserver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php

namespace App\Observers;

use App\Models\Repository;
use Illuminate\Support\Facades\Http;

class RepositoryObserver
{
public function CreateRepository(array $data, String $token)
{
$response = Http::withHeaders([
"Authorization" => $token,
])->withBody(
json_encode($data),
'application/json'
)->post('https://api.github.com/user/repos');
return $response;
}

public function CreateFile(array $data, String $url, String $token)
{
$response = Http::withHeaders([
"Authorization" => $token,
])->withBody(
json_encode($data),
'application/json'
)->put($url);
return $response;
}
/**
* Handle the Repository "created" event.
*
* @param \App\Models\Repository $repository
* @return void
*/
public function created(Repository $repository)
{
$data = [
"name" => $repository->name,
"auto_init" => false,
"private" => true
];

$token = $repository->personal_access_token;

// Create repositry via GitHub
$response = json_decode($this->CreateRepository($data, $token)->body());

// Confirm pathing
$targetRepository = Repository::find($repository->id);
$targetRepository->path = $response->full_name;
$targetRepository->saveQuietly();

// Initialize ReadME.md
$data = [
"message" => "Creating Repository",
"committer" => [
"name" => "Siteplot Bot",
"email" => "[email protected]"
],
"content" => "IyBTZWNvbmRhcnkgQ29tcG9uZW50cwoKQ29tcG9uZW50IGxpYnJhcnkgZ2VuZXJhdGVkIGJ5IFNpdGVwbG90CgpSZXBvIENyZWF0ZWQgd2l0aCB0aGUgZm9sbG93aW5nIHNldHRpbmdzOgpgYGAKbmFtZTogU2Vjb25kYXJ5IENvbXBvbmVudHMKcGF0aDogc2l0ZXBsb3QvU2Vjb25kYXJ5Q29tcG9uZW50cwpwZXJzb25hbF9hY2Nlc3NfdG9rZW46ICoqKioqKioqKioqKioqKmRrZHNrcwpgYGAKCkFsbCBzdXBwb3J0aW5nIGNvbXBvbmVudHMgY2FuIGJlIGZvdW5kIGluIHRoZSBgYGAvY29tcG9uZW50c2BgYCBmb2xkZXIKVGhpcyBjb21wb25lbnQgbGlicmFyeSBjYW4gYmUgbW91bnRlZCBpbiBhbnkgY3VzdG9tIHByb2plY3QgdmlhIGEgW3N1Ym1vZHVsZV0oaHR0cHM6Ly9naXQtc2NtLmNvbS9ib29rL2VuL3YyL0dpdC1Ub29scy1TdWJtb2R1bGVzKQ=="
];

$url = 'https://api.github.com/repos/' . $targetRepository->path . '/contents/README.md';

$this->CreateFile($data, $url, $token);
}

/**
* Handle the Repository "updated" event.
*
* @param \App\Models\Repository $repository
* @return void
*/
public function updated(Repository $repository)
{
//
}

/**
* Handle the Repository "deleted" event.
*
* @param \App\Models\Repository $repository
* @return void
*/
public function deleted(Repository $repository)
{
//
}

/**
* Handle the Repository "restored" event.
*
* @param \App\Models\Repository $repository
* @return void
*/
public function restored(Repository $repository)
{
//
}

/**
* Handle the Repository "force deleted" event.
*
* @param \App\Models\Repository $repository
* @return void
*/
public function forceDeleted(Repository $repository)
{
//
}
}
3 changes: 3 additions & 0 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;
use App\Observers\BlockTypeObserver;
use App\Observers\RepositoryObserver;
use App\Models\BlockType;
use App\Models\Repository;

class EventServiceProvider extends ServiceProvider
{
Expand All @@ -30,5 +32,6 @@ class EventServiceProvider extends ServiceProvider
public function boot()
{
BlockType::observe(BlockTypeObserver::class);
Repository::observe(RepositoryObserver::class);
}
}
4 changes: 2 additions & 2 deletions graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ directive @whereConditions(

type AssetEntry {
id: ID!
path: String!
path: String
website: Website! @belongsTo
created_at: DateTime!
updated_at: DateTime!
Expand Down Expand Up @@ -192,7 +192,7 @@ type Mutation {
createBlockType(input: CreateBlockTypeInput! @spread): BlockType @create @guard
updateBlockType(input: UpdateBlockTypeInput! @spread): BlockType @update @guard

createRepository(name: String!, path: String!, personal_access_token: String): Repository! @create @guard
createRepository(name: String!, personal_access_token: String): Repository! @create @guard
updateRepository(id: ID!, name: String!, path: String!, personal_access_token: String): Repository! @update @guard

}
Expand Down
Loading

0 comments on commit c701846

Please sign in to comment.