Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 72 additions & 4 deletions app/Api/GitHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@ public function __construct()
{
$this->api = new Client([
'base_uri' => 'https://api.github.com/'
// ,
// 'headers' => [
// 'Accept' => 'application/json',
// 'Authorization' => 'token 933e7e16c558537f62961ef6c67612b8244a0d41'
// ]
]);

$this->oauth = new Client([
'base_uri' => 'https://github.com/login/oauth/',
'headers' => [
'Accept' => 'application/json'
]
// 'headers' => [
// 'Accept' => 'application/json',
// 'token' => '933e7e16c558537f62961ef6c67612b8244a0d41'
// ]
]);
}

Expand All @@ -45,6 +51,68 @@ public function getBranches($username, $repo_name)
);
}

/**
* Returns array with all repo's webhooks
*
* https://developer.github.com/v3/repos/hooks/#list-hooks
*/
public function getHooks($username, $repo_name) {
// GET /repos/:owner/:repo/hooks
//TODO: set the header correctly

return json_decode(
$this->api->request("get", "repos/{$username}/{$repo_name}/hooks", [
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'token 933e7e16c558537f62961ef6c67612b8244a0d41'
]
])->getBody()->getContents()
);
}

/**
* Returns array with all repo's branches
*
* https://developer.github.com/v3/repos/hooks/#list-hooks
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function createHooks($username, $repo_name) {
// POST /repos/:owner/:repo/hooks
//TODO: set the header correctly
//TODO: fix the payload
//TODO: set the get back to post on the web.php routes
//TODO: send the payload as a form_params
$data = [
'json' => [
'name' => 'web',
// 'active' => true,
'events' => ['push'],
'config' => [
'url' => 'http://ab47d7ec.ngrok.io/access/callback'//,
// 'content_type' => 'json'
]
]
];

try {
$this->api->request("post", "repos/{$username}/{$repo_name}/hooks", [
'headers' => [
'Authorization' => 'token 933e7e16c558537f62961ef6c67612b8244a0d41'
],
'json' => [
'name' => 'web',
'events' => ['push'],
'config' => [
'url' => 'https://ab47d7ec.ngrok.io/github/getPayload'
]
]
]);
} catch (\GuzzleHttp\Exception\ClientException $e) {
dd($e->getResponse()->getBody()->getContents());
}

}

/**
* Creates a user access token
*
Expand All @@ -58,4 +126,4 @@ public function getAccessToken($code)
'&code=' . $code
)->getBody()->getContents())->access_token;
}
}
}
70 changes: 65 additions & 5 deletions app/Http/Controllers/Api/GitHubController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Api\GitHub;
use App\Http\Controllers\Controller;
use App\Models\Repository;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Redirect;
Expand All @@ -20,14 +21,46 @@ public function __construct()

/**
* AJAX : Gets all branches for a repository
* @param Request $request
* @return mixed
*/
public function getBranches()
public function getBranches(Request $request)
{
$repository = Repository::find(request('repository_id'));

$repository = Repository::find(1);
return $this->github->getBranches($repository->owner, $repository->name);
}

/**
* AJAX : Gets all hooks fo4r a repository
* @param Request $request
* @return mixed test commit123
*/
public function getHooks(Request $request)
{
//$repository = Repository::find($request->get('repository_id'));

\Log::info ($request);
$repository = Repository::find(1);
\Log::info ($repository);


return $this->github->getHooks($repository->owner, $repository->name);
}

public function createHooks(Request $request)
{
// create
// POST /repos/:owner/:repo/hooks
// https://api.github.com/repos/octocat/Hello-World/hooks/1
//api-post(repos/rustyhumfleet/rollaball/hooks)
// end create

$repository = Repository::find(1);
// \Log::info ($repository);

return $this->github->createHooks($repository->owner, $repository->name);
}

/**
* Redirects to GitHub to get user access to web-hooks & public/private repositories
*/
Expand All @@ -42,15 +75,42 @@ public function getAccess()

/**
* Callback from GitHub for getAccess()
* @param Request $request
* @return \Illuminate\Http\RedirectResponse
*/
public function getAccessCallback()
public function getAccessCallback(Request $request)
{
$token = $this->github->getAccessToken(request('code'));
$token = $this->github->getAccessToken($request->get('code'));

Auth::user()->update([
'github_access_token' => Crypt::encryptString($token)
]);

return redirect()->route('view.profile')->with(['message' => 'Successfully linked up GitHub account']);
}

/**
* Callback from GitHub for getPayload()
* @param Request $request
* @return string
*/
public function getPayload(Request $request)
{
\Log::info($request->all());
\Log::info('this is a nice fuckin fish');
// $plan = DeploymentPlan::create([
// 'title' => $request->get('title'),
// 'environment_id' => $request->get('environment_id'),
// 'repository_id' => $request->get('repository_id'),
// 'repository_branch' => $request->get('repository_branch'),
// 'is_automatic' => true, // CHANGE
// 'remote_path' => $request->get('remote_path'),
// ]);
//this->api-post(repos/owner/reponame/hooks)
//on the repository controller on store and update you can create one after

return json_encode('this is a nice fuckin fish');
}


}
114 changes: 0 additions & 114 deletions app/Http/Controllers/Auth/AuthController.php

This file was deleted.

Loading