示例#1
0
function updateVersion()
{
    require_once 'lib/class.settings.php';
    require_once 'lib/class.github.php';
    $github = new GitHub('gugahoi', 'mediafrontpage');
    $commit = $github->getCommits();
    $commitNo = $commit['0']['sha'];
    $config = new ConfigMagik('config.ini', true, true);
    try {
        $config->set('version', $commitNo, 'ADVANCED');
    } catch (Exception $e) {
        echo false;
        exit;
    }
    echo true;
}
示例#2
0
文件: Repo.php 项目: jankal/mvc
 /**
  * @return array[\GitHub\WebhookList]
  */
 public function webhooks()
 {
     $url = \GitHub::$endpoint . "repositories/{$this->id}/hooks";
     $data = \GitHub::request($url);
     $return = new WebhookList((array) $data, $this);
     return $return;
 }
 public function gitDeployProject($git_branch, $extends = null)
 {
     $config = Config::get('github');
     $config['branch'] = $git_branch;
     $config['post_data'] = Input::get('payload');
     if ($config['active'] === FALSE) {
         App::abort(403, 'Модуль отключен');
     }
     if ($config['test_mode_key'] == $extends) {
         $config['test_mode'] = TRUE;
     } else {
         $config['test_mode'] = FALSE;
     }
     $github = new GitHub();
     $github->init($config);
     if ($extends == 'test') {
         echo $github->testConnect('/usr/bin/ssh -T git@github.com');
     } else {
         echo $github->execute('git reset --hard HEAD');
         echo "\n";
         echo $github->pull();
         echo "\n";
         echo $github->setAccessMode();
         echo "\n";
         foreach ($config['directories'] as $directory) {
             echo $github->setAccessMode($directory, '0777');
         }
     }
 }
示例#4
0
 /**
  * add a webhook
  * @param string $url the url for the hook
  * @param Array $events the evnets on which this webhook should be called (all events with ['*'])
  * @return string|\stdClass|array
  */
 public function addNew($url, array $events)
 {
     \GitHub::setRQdata(['name' => 'web', 'config' => ['url' => $url, 'content_type' => 'json', 'secret' => \App::get('GitHub')->secret], 'events' => $events]);
     $url = \GitHub::$endpoint . "repositories/{$this->repo->id}/hooks";
     $k = count($this->webhooks);
     $this->webhooks[$k] = new \GitHub\WebhookMeta();
     $this->webhooks[$k]->setData(\GitHub::post($url));
     return $this;
 }
示例#5
0
文件: User.php 项目: jankal/mvc
 /**
  * @return array[\GitHub\Repo]
  */
 public function getRepos()
 {
     $url = \GitHub::$endpoint . "users/{$this->login}/repos";
     $data = \GitHub::request($url);
     $return = [];
     foreach ($data as $repo) {
         $return[$repo->name] = new Repo();
         $return[$repo->name]->setData($repo);
     }
     return (array) $return;
 }
示例#6
0
 public function handler()
 {
     global $clientsecret, $clientid;
     switch ($this->get('action')) {
         case 'compare_version':
             if (!$this->get('version') || !$this->get('repo')) {
                 break;
             }
             $lang = strlen($this->get('lang')) ? $this->get('lang') : 'en';
             $strCacheName = md5($this->get('repo') . '_' . $this->get('version') . '_' . $lang);
             $strCacheFolder = 'cache/data/';
             if (file_exists($strCacheFolder . $strCacheName . '.txt') && filemtime($strCacheFolder . $strCacheName . '.txt') + 3600 > time()) {
                 $arrText = unserialize(file_get_contents($strCacheFolder . $strCacheName . '.txt'));
             } else {
                 $eqdkp = new GitHub('EQdkpPlus', $this->get('repo'), $clientid, $clientsecret);
                 $arrText = $this->compareVersion($this->get('version'), $eqdkp->getLatestVersion(), $lang, $this->get('repo'));
                 file_put_contents($strCacheFolder . $strCacheName . '.txt', serialize($arrText));
             }
             $this->displayImage($arrText);
             break;
     }
 }
示例#7
0
    public function testIsUnderstood()
    {
        $subject = <<<EOD
{
    "repository": {
        "full_name": "aklump/jquery.slim_time"
    },
    "sender": {
        "login": "******"
    }
}    
EOD;
        $obj = new GitHub($subject);
        $this->assertTrue($obj->isUnderstood());
        $this->assertSame('aklump/jquery.slim_time', $obj->getRepoName());
        $this->assertSame('aklump', $obj->getUsername());
        $this->assertSame('*', $obj->getBranch());
        $obj->setContent('doremi');
        $this->assertFalse($obj->isUnderstood());
        $this->assertEmpty($obj->getRepoName());
        $this->assertEmpty($obj->getUsername());
        $this->assertSame('*', $obj->getBranch());
    }
示例#8
0
	public function process(){
		if(!empty($_POST['repository'])){
			try {
				$repoID = GitHub::parseRepository($_POST['repository']);
			} catch(Exception $e){
				self::redirect('Error', null, null, array('message'=>"Unable to process GitHub repository. Check the URL and ensure that the repository is public."));
				return;
			}
			
			self::redirect('Match', 'repository', array($repoID));
		} else if(!empty($_FILES['file']['tmp_name'])){
			$repoID = Upload::processFile($_FILES['file']['tmp_name'], $_FILES['file']['name']);
			self::redirect('Match', 'repository', array($repoID));
		} else {
			self::redirect();
		}
	}
示例#9
0
 function __construct($json)
 {
     $this->payload_type = 0;
     $this->priv_json = json_decode($json, true);
     if ($this->priv_json === null) {
         die("Unable to decode: " . $json);
     }
     if (array_key_exists("sender", $this->priv_json)) {
         $this->sender = new GitHub_SenderInfo($this->priv_json['sender']);
     }
     $this->repo_name = $this->priv_json['repository']['full_name'];
     if (array_key_exists("ref", $this->priv_json)) {
         // get a name of branch this is about
         $branch = $this->priv_json['ref'];
         if (GitHub::startsWith($branch, "refs/heads/")) {
             $branch = substr($branch, 11);
         }
         $this->repo_branch = $branch;
     }
     $action = "unknown";
     if (array_key_exists("action", $this->priv_json)) {
         $action = $this->priv_json['action'];
     }
     if ($action == "opened") {
         $this->payload_type = 2;
     } else {
         if ($action == "created") {
             $this->payload_type = 3;
         } else {
             if ($action == "closed") {
                 $this->payload_type = 4;
             } else {
                 if (array_key_exists("commits", $this->priv_json)) {
                     $this->payload_type = 1;
                 }
             }
         }
     }
     $this->process_msgs();
 }
 public static function _doSubmitIssue()
 {
     if (!empty($_POST['title'])) {
         $user = Member::findById($_POST['user'])->forum_name;
         $title = $_POST['title'];
         $link = $_POST['link'];
         $body = $_POST['body'];
         $body .= !empty($link) ? "<hr /><strong>Page reported</strong>: {$link}<br />" : null;
         $body .= "<strong>Reported by</strong>: {$user}";
         $issue = GitHub::createIssue($title, $body);
         if (is_object($issue)) {
             if ($issue->getNumber()) {
                 $data = array('success' => true, 'message' => "Your report has been submitted");
             }
         } else {
             $data = array('success' => false, 'message' => "Something went wrong");
         }
     } else {
         $data = array('success' => false, 'message' => "You must provide a title");
     }
     echo json_encode($data);
 }
 public function updateApp($app_id, $version = null)
 {
     $app = Mysql::getInstance()->from('apps')->where(array('id' => $app_id))->get()->first();
     if (empty($app)) {
         return false;
     }
     if ($version === null) {
         return $this->installApp($app_id);
     }
     $tmp_file = '/tmp/' . uniqid('app_') . '.zip';
     $repo = new GitHub($app['url']);
     $zip_url = 'https://github.com/' . $repo->getOwner() . '/' . $repo->getRepository() . '/archive/' . $version . '.zip';
     file_put_contents($tmp_file, fopen($zip_url, 'r', false, stream_context_create(array('http' => array('header' => "User-Agent: stalker_portal\r\n")))));
     if (empty($app['alias'])) {
         $app['alias'] = self::safeFilename($app['name']);
     }
     $path = PROJECT_PATH . '/../../' . Config::getSafe('apps_path', 'stalker_apps/') . $app['alias'];
     umask(0);
     if (!is_dir($path)) {
         mkdir($path, 0755, true);
     }
     $archive = new ZipArchive();
     if ($archive->open($tmp_file) === true) {
         $entry = $archive->getNameIndex(0);
         $dir = substr($entry, 0, strpos($entry, '/'));
         $result = $archive->extractTo($path);
         $archive->close();
         rename($path . '/' . $dir, $path . '/' . $version);
     } else {
         return false;
     }
     unlink($tmp_file);
     if ($result) {
         $update_data = array('current_version' => $version);
         $update_data['alias'] = $app['alias'];
         if (!isset($repo)) {
             $repo = new GitHub($app['url']);
         }
         $info = $repo->getFileContent('package.json');
         if (!empty($info['description'])) {
             $update_data['description'] = $info['description'];
         }
         if (!empty($info['config']['icons'])) {
             $update_data['icons'] = $info['config']['icons'];
         } else {
             $update_data['icons'] = 'icons';
         }
         if (!empty($info['config']['backgroundColor'])) {
             $update_data['icon_color'] = $info['config']['backgroundColor'];
         }
         Mysql::getInstance()->update('apps', $update_data, array('id' => $app_id));
     }
     return $result;
 }
 public function postSave($mod_name)
 {
     #Helper::dd(Input::all());
     $json_request = array('status' => FALSE, 'responseText' => '');
     $file = Input::get('file');
     $tpl = Input::get('tpl');
     if ($tpl === '') {
         return Response::json($json_request, 200);
     }
     if ($mod_name == 'layout') {
         $full_file = app_path('views/templates/' . Config::get('app.template') . '/' . $file . '.blade.php');
     } else {
         $full_file = app_path('modules/' . $mod_name . '/views/' . $file . '.blade.php');
     }
     $result = @file_put_contents($full_file, $tpl);
     /**
      * Send changes to GitHub
      */
     $config = Config::get('github');
     if ($config['active'] != FALSE && Input::get('git') && class_exists('GitHub')) {
         #if($config['test_mode_key'] == $extends):
         $config['test_mode'] = TRUE;
         #else:
         #    $config['test_mode'] = FALSE;
         #endif;
         $config['set_log'] = FALSE;
         $github = new GitHub();
         $github->init($config);
         $result = $github->execute('git add ' . $full_file);
         #echo $result . "\n";
         if ($result == 0) {
             $result = $github->execute('git commit -m "server commit - template editor; module: ' . $mod_name . ', file: ' . $file . '"');
             #echo $result . "\n";
             if ($result == 0) {
                 $result = $github->pull();
                 #echo $result . "\n";
                 $result = $github->push();
                 #echo $result . "\n";
             }
         }
     }
     $json_request['status'] = true;
     return Response::json($json_request, 200);
 }
示例#13
0
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the
//  Free Software Foundation, Inc.,
//  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
require "db.php";
require "irc.php";
require "github.php";
$input = file_get_contents('php://input');
if (empty($input)) {
    die("This is a webhook for github. You can only use it as a webhook, displaying in a browser is not supported. See https://meta.wikimedia.org/wiki/Wm-bot#Git_Hub");
}
$payload = new GitHub($input);
if (!$payload->IsKnown()) {
    die("Unknown payload");
}
// for debugging only
// file_put_contents("/tmp/github", $entityBody);
// connect to db
$conn = new mysqli('localhost', $github_user, $github_pw);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
// get information for this repository from db
$sql = "SELECT id, name, channel, channel_token FROM wmib.github_repo_info WHERE name = '" . $payload->GetRepositoryName() . "';";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) == 0) {
    die("This repository " . $payload->GetRepositoryName() . " is not known by wm-bot");
示例#14
0
<?php

require_once 'config.php';
require_once 'vendor/autoload.php';
use Phpanos\Github\Github;
use Phpanos\Github\HttpClient;
$github = new GitHub(new HttpClient());
if (!empty($_GET['code'])) {
    $github->requestAccessToken($config['client_id'], $config['client_secret'], $_GET['code']);
    $user = $github->get($github->apiBaseUrl() . 'user');
    var_dump($user);
}
?>
<a href="<?php 
echo $github->authorizeUrl($config['client_id'], 'user', $config['redirect_url']);
?>
">Authorize App</a>
示例#15
0
               <td>Homepage</td><td><a href="http://mediafrontpage.net/">http://mediafrontpage.net/</a></td>
             </tr>
             <tr align="left">
               <td>Forum</td><td><a href="http://forum.xbmc.org/showthread.php?t=83304">http://forum.xbmc.org/showthread.php?t=83304</a></td>
             </tr>
             <tr align="left">
               <td>Source</td><td><a href="https://github.com/MediaFrontPage/mediafrontpage">https://github.com/MediaFrontPage/mediafrontpage</a></td>
             </tr>
             <tr align="left">
               <td>Bug Tracker</td><td><a href="http://mediafrontpage.lighthouseapp.com">http://mediafrontpage.lighthouseapp.com</a></td>
             </tr>
             <tr align="left">
               <td>Last Updated</td>
               <td>
               <?php 
 $github = new GitHub('gugahoi', 'mediafrontpage');
 $date = $github->getInfo();
 echo $date['pushed_at'];
 ?>
               </td>
             </tr>
             <tr align="left">
               <td>
                 <?php 
 $commit = $github->getCommits();
 $commitNo = $commit['0']['sha'];
 $currentVersion = $config->get('version', 'ADVANCED');
 echo "Version </td><td><a href='https://github.com/gugahoi/mediafrontpage/commit/" . $currentVersion . "' target='_blank'>" . $currentVersion . '</a>';
 if ($commitNo != $currentVersion) {
     echo "\t<a href='#' onclick='updateVersion();' title='" . $commitNo . " - Description: " . $commit['0']['commit']['message'] . "'>***UPDATE Available***</a>";
 }
 public function application_get_data_from_repo()
 {
     if (!$this->isAjax || $this->method != 'POST' || empty($this->postData['apps']['url'])) {
         $this->app->abort(404, $this->setLocalization('Page not found'));
     }
     if ($no_auth = $this->checkAuth()) {
         return $no_auth;
     }
     $response['action'] = 'buildSaveForm';
     $response['data'] = array();
     $response['error'] = '';
     try {
         $repo = new \GitHub($this->postData['apps']['url']);
         $response['data'] = $repo->getFileContent('package.json');
         if (!array_key_exists('repository', $response['data'])) {
             $response['data']['repository']['url'] = $this->postData['apps']['url'];
         }
     } catch (\GitHubError $e) {
         $response['error'] = $this->setLocalization($e->getMessage());
     }
     $response = $this->generateAjaxResponse($response);
     return new Response(json_encode($response), empty($error) ? 200 : 500);
 }
示例#17
0
文件: GitHub.php 项目: jankal/mvc
 /**
  * @param string $username
  * @param string $token Users authentication token OR password if 2FA is not enabled
  * @return void
  */
 public static function authenticateUser($username, $token)
 {
     self::$authUser = "******";
     self::$authenticatedUser = true;
 }