我是 GitHub 的新手,我正在执行以下操作
- 本地文件推送到 GitHub 远程仓库(本地 -> git 远程仓库)
- 然后使用网络挂钩(一旦本地文件推送到 git 远程仓库)自动将所有文件发送到我的服务器/虚拟主机(git 远程仓库->虚拟主机)
这是我的 webhook 网址
http://domainname.com/ghautodeploy.php?server_id=625349&app_id=2031109&git_url=git@github.com:xxxx/yyyy.git&branch_name=main&deploy_path=it
它工作得很好,但是它将所有远程仓库推送到我的主机,而不是仅最后提交的文件。
我的 webhook 代码
<?php
const API_KEY = "xxxxxx";
const API_URL = "yyyy";
const EMAIL = "email@domainame.com";
function callAPI($method, $url, $accessToken, $post = [])
{
$baseURL = API_URL;
$ch = curl_init();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_URL, $baseURL . $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//Set Authorization Header
if ($accessToken) {
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer ' . $accessToken]);
}
//Set Post Parameters
$encoded = '';
if (count($post)) {
foreach ($post as $name => $value) {
$encoded .= urlencode($name) . '=' . urlencode($value) . '&';
}
$encoded = substr($encoded, 0, strlen($encoded) - 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded);
curl_setopt($ch, CURLOPT_POST, 1);
}
$output = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpcode != '200') {
die('An error occurred code: ' . $httpcode . ' output: ' . substr($output, 0, 10000));
}
curl_close($ch);
return json_decode($output);
}
//Fetch Access Token
$tokenResponse = callAPI('POST', '/oauth/access_token', null
, [
'email' => EMAIL,
'api_key' => API_KEY
]);
$accessToken = $tokenResponse->access_token;
$gitPullResponse = callAPI('POST', '/git/pull', $accessToken, [
'server_id' => $_GET['server_id'],
'app_id' => $_GET['app_id'],
'git_url' => $_GET['git_url'],
'branch_name' => $_GET['branch_name'],
/* Uncomment it if you want to use deploy path, Also add the new parameter in your link */
'deploy_path' => $_GET['deploy_path']
]);
echo (json_encode($gitPullResponse));
?>
我的 github webhook 选项
问题是仅从(git remote repo -> web hosting)推送最后提交的文件,它推送整个文件。
我想解决这个问题,指导我怎么做?注意:web-hook 工作正常,没问题