Skip to content

Commit

Permalink
convert file format to UNIX
Browse files Browse the repository at this point in the history
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
  • Loading branch information
appleboy committed Feb 18, 2013
1 parent 3126308 commit 64d9581
Show file tree
Hide file tree
Showing 5 changed files with 295 additions and 295 deletions.
108 changes: 54 additions & 54 deletions codeigniter/config/github.php
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
* @package CodeIgniter Git Deploy
* @author Bo-Yi Wu
* @copyright Copyright (c) 2012, Bo-Yi Wu
* @link https://github.com/appleboy/PHP-Git-Deploy
* @since Version 1.0
*/

/**
* Github config
*
* 1. git command absolute path
* 2. project name, path and branch name
*
* Format:
* array(
* 'project_name' => array(
* 'branch_name' => array('base_path' => 'folder_path')
* )
* );
*
* If your github project url path:
* https://github.com/appleboy/CodeIgniter-Git-Deploy
*
* For example: Single project, multi branch
* array(
* 'codeigniter-git-deploy' => array(
* 'master' => array('base_path' => '/path/CodeIgniter-Git-Deploy_1/'),
* 'develop' => array('base_path' => '/path/CodeIgniter-Git-Deploy_2/')
* )
* );
*
* For example: Multi project, multi branch
* array(
* 'codeigniter-git-deploy' => array(
* 'master' => array('base_path' => '/path/CodeIgniter-Git-Deploy_1/'),
* 'develop' => array('base_path' => '/path/CodeIgniter-Git-Deploy_2/')
* ),
* 'codeigniter-my-model' => array(
* 'master' => array('base_path' => '/path/CodeIgniter-MY-Model_1/'),
* 'develop' => array('base_path' => '/path/CodeIgniter-MY-Model_2/')
* )
* );
*
*/

$config['git_path'] = '/usr/local/bin/git';
$config['github'] = array(
'php-git-deploy' => array(
'master' => array('base_path' => '/home/git/test/PHP-Git-Deploy/')
)
);
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
* @package CodeIgniter Git Deploy
* @author Bo-Yi Wu
* @copyright Copyright (c) 2012, Bo-Yi Wu
* @link https://github.com/appleboy/PHP-Git-Deploy
* @since Version 1.0
*/

/**
* Github config
*
* 1. git command absolute path
* 2. project name, path and branch name
*
* Format:
* array(
* 'project_name' => array(
* 'branch_name' => array('base_path' => 'folder_path')
* )
* );
*
* If your github project url path:
* https://github.com/appleboy/CodeIgniter-Git-Deploy
*
* For example: Single project, multi branch
* array(
* 'codeigniter-git-deploy' => array(
* 'master' => array('base_path' => '/path/CodeIgniter-Git-Deploy_1/'),
* 'develop' => array('base_path' => '/path/CodeIgniter-Git-Deploy_2/')
* )
* );
*
* For example: Multi project, multi branch
* array(
* 'codeigniter-git-deploy' => array(
* 'master' => array('base_path' => '/path/CodeIgniter-Git-Deploy_1/'),
* 'develop' => array('base_path' => '/path/CodeIgniter-Git-Deploy_2/')
* ),
* 'codeigniter-my-model' => array(
* 'master' => array('base_path' => '/path/CodeIgniter-MY-Model_1/'),
* 'develop' => array('base_path' => '/path/CodeIgniter-MY-Model_2/')
* )
* );
*
*/

$config['git_path'] = '/usr/local/bin/git';
$config['github'] = array(
'php-git-deploy' => array(
'master' => array('base_path' => '/home/git/test/PHP-Git-Deploy/')
)
);
162 changes: 81 additions & 81 deletions codeigniter/controllers/deploy.php
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
* Post-Receive Hooks API
*
* @author appleboy
* @copyright 2012 appleboy
* @link https://github.com/appleboy/PHP-Git-Deploy
* @package CodeIgniter Git Deploy
*/
class Deploy extends CI_Controller
{
/**
* Default __construct
*
* @author appleboy
*/
public function __construct()
{
parent::__construct();
$this->config->load('github');
}

/**
*
* Post-Receive Hooks
*
* @author appleboy
*/
public function receive()
{
// receive git payload
$payload = $this->input->get_post('payload');
// load git command path config
$git_config = $this->config->item('github');
$git_path = $this->config->item('git_path');

if ($payload and is_array($git_config)) {
$payload = json_decode($payload);

log_message('debug', 'Post-receive hook initial');

foreach ($git_config as $key => $val) {

// check repository name exist in config
$repository_name = strtolower($payload->repository->name);
if ($repository_name != strtolower($key)) {
continue;
}

foreach ($val as $k => $v) {
// check if match payload ref branch
$head = 'refs/heads/' . $k;
if ($payload->ref != $head) {
continue;
}

// git reset head and pull origin branch
if (isset($v['base_path']) and !empty($v['base_path'])) {
$base_path = realpath($v['base_path']) . '/';

$shell = sprintf('%s --git-dir="%s.git" --work-tree="%s" reset --hard HEAD',
$git_path, $base_path, $base_path);
log_message('debug', '$shell value ' . $shell);
$output = shell_exec(escapeshellcmd($shell));

$shell = sprintf('%s --git-dir="%s.git" --work-tree="%s" clean -f',
$git_path, $base_path, $base_path);
log_message('debug', '$shell value ' . $shell);
$output = shell_exec(escapeshellcmd($shell));

$shell = sprintf('%s --git-dir="%s.git" --work-tree="%s" pull origin %s',
$git_path, $base_path, $base_path, $k);
log_message('debug', '$shell value ' . $shell);
$output = shell_exec(escapeshellcmd($shell));
}
}
}
}
}
}
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
* Post-Receive Hooks API
*
* @author appleboy
* @copyright 2012 appleboy
* @link https://github.com/appleboy/PHP-Git-Deploy
* @package CodeIgniter Git Deploy
*/
class Deploy extends CI_Controller
{
/**
* Default __construct
*
* @author appleboy
*/
public function __construct()
{
parent::__construct();
$this->config->load('github');
}

/**
*
* Post-Receive Hooks
*
* @author appleboy
*/
public function receive()
{
// receive git payload
$payload = $this->input->get_post('payload');
// load git command path config
$git_config = $this->config->item('github');
$git_path = $this->config->item('git_path');

if ($payload and is_array($git_config)) {
$payload = json_decode($payload);

log_message('debug', 'Post-receive hook initial');

foreach ($git_config as $key => $val) {

// check repository name exist in config
$repository_name = strtolower($payload->repository->name);
if ($repository_name != strtolower($key)) {
continue;
}

foreach ($val as $k => $v) {
// check if match payload ref branch
$head = 'refs/heads/' . $k;
if ($payload->ref != $head) {
continue;
}

// git reset head and pull origin branch
if (isset($v['base_path']) and !empty($v['base_path'])) {
$base_path = realpath($v['base_path']) . '/';

$shell = sprintf('%s --git-dir="%s.git" --work-tree="%s" reset --hard HEAD',
$git_path, $base_path, $base_path);
log_message('debug', '$shell value ' . $shell);
$output = shell_exec(escapeshellcmd($shell));

$shell = sprintf('%s --git-dir="%s.git" --work-tree="%s" clean -f',
$git_path, $base_path, $base_path);
log_message('debug', '$shell value ' . $shell);
$output = shell_exec(escapeshellcmd($shell));

$shell = sprintf('%s --git-dir="%s.git" --work-tree="%s" pull origin %s',
$git_path, $base_path, $base_path, $k);
log_message('debug', '$shell value ' . $shell);
$output = shell_exec(escapeshellcmd($shell));
}
}
}
}
}
}
Loading

0 comments on commit 64d9581

Please sign in to comment.