Rough cut of Repositories and GitHub post-receive hooks.

Summary:

Test Plan:

Reviewers:

CC:
This commit is contained in:
epriestley
2011-02-12 18:26:15 -08:00
parent 8784b5bd3b
commit f55a30a288
18 changed files with 778 additions and 6 deletions

View File

@@ -0,0 +1,66 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class PhabricatorRepositoryGitHubPostReceiveController
extends PhabricatorRepositoryController {
public function shouldRequireAuthentication() {
return false;
}
private $id;
private $token;
public function willProcessRequest(array $data) {
$this->id = $data['id'];
$this->token = $data['token'];
}
public function processRequest() {
$request = $this->getRequest();
$repo = id(new PhabricatorRepository())->load($this->id);
if (!$repo) {
return new Aphront404Response();
}
if ($repo->getDetail('github-token') != $this->token) {
return new Aphront400Response();
}
if (!$request->isHTTPPost()) {
return id(new AphrontFileResponse())
->setMimeType('text/plain')
->setContent(
"Put this URL in your GitHub configuration. Accessing it directly ".
"won't do anything!");
}
$notification = new PhabricatorRepositoryGitHubNotification();
$notification->setRepositoryPHID($repo->getPHID());
$notification->setRemoteAddress($_SERVER['REMOTE_ADDR']);
$notification->setPayload($request->getStr('payload', ''));
$notification->save();
return id(new AphrontFileResponse())
->setMimeType('text/plain')
->setContent('OK');
}
}

View File

@@ -0,0 +1,19 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'aphront/response/400');
phutil_require_module('phabricator', 'aphront/response/404');
phutil_require_module('phabricator', 'aphront/response/file');
phutil_require_module('phabricator', 'applications/repository/controller/base');
phutil_require_module('phabricator', 'applications/repository/storage/githubnotification');
phutil_require_module('phabricator', 'applications/repository/storage/repository');
phutil_require_module('phutil', 'utils');
phutil_require_source('PhabricatorRepositoryGitHubPostReceiveController.php');