add git source: HIT

pull/493/head
qkqpttgf 2021-12-20 10:40:33 +08:00 committed by GitHub
parent faf5027f04
commit 65d57a5d24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 25 deletions

View File

@ -421,42 +421,27 @@ function setConfigResponse($response)
return json_decode($response, true); return json_decode($response, true);
} }
function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master') function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
{ {
$source = '/tmp/code.zip'; $source = '/tmp/code.zip';
$outPath = '/tmp/'; $outPath = '/tmp/';
// 从github下载对应tar.gz并解压 if ($GitSource=='Github') {
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/'; // 从github下载对应tar.gz并解压
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
} elseif ($GitSource=='HITGitlab') {
$url = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz';
} else return json_encode(['ErrorMessage'=>'Git Source input Error!']);
$tarfile = '/tmp/github.tar.gz'; $tarfile = '/tmp/github.tar.gz';
file_put_contents($tarfile, file_get_contents($url)); file_put_contents($tarfile, file_get_contents($url));
$phar = new PharData($tarfile); $phar = new PharData($tarfile);
$html = $phar->extractTo($outPath, null, true);//路径 要解压的文件 是否覆盖 $html = $phar->extractTo($outPath, null, true);//路径 要解压的文件 是否覆盖
// 获取解压出的目录名 // 获取解压出的目录名
/* $outPath = findIndexPath($outPath);
@ob_start();
passthru('ls /tmp | grep '.$auth.'-'.$project.'',$stat);
$html.='状态:' . $stat . '
结果:
';
$archivefolder = ob_get_clean();
if (substr($archivefolder,-1)==PHP_EOL) $archivefolder = substr($archivefolder, 0, -1);
$outPath .= $archivefolder;
$html.=htmlspecialchars($archivefolder);
//return $html;
*/
$tmp = scandir($outPath);
$name = $auth.'-'.$project;
foreach ($tmp as $f) {
if ( substr($f, 0, strlen($name)) == $name) {
$outPath .= $f;
break;
}
}
// 将目录中文件打包成zip // 将目录中文件打包成zip
$zip=new ZipArchive(); $zip = new ZipArchive();
if($zip->open($source, ZipArchive::CREATE)){ if($zip->open($source, ZipArchive::CREATE)){
addFileToZip($zip, $outPath); //调用方法对要打包的根目录进行操作并将ZipArchive的对象传递给方法 addFileToZip($zip, $outPath); //调用方法对要打包的根目录进行操作并将ZipArchive的对象传递给方法
$zip->close(); //关闭处理的zip文件 $zip->close(); //关闭处理的zip文件
@ -483,7 +468,7 @@ function addFileToZip($zip, $rootpath, $path = '')
} }
} }
} }
@closedir($path); @closedir($handler);
} }
function myErrorHandler($errno, $errstr, $errfile, $errline) { function myErrorHandler($errno, $errstr, $errfile, $errline) {