【问题标题】:Getting last commit's zip with php使用 php 获取最后一次提交的 zip
【发布时间】:2012-10-04 12:34:40
【问题描述】:

我在下面找到了自动部署 php 项目的代码。问题是“https://bitbucket.org/$username/$reponame/get/tip.zip”这个网址在bitbucket private git repo上的private git repo上不起作用:可能与身份验证有关(我还没有测试过这个公共仓库)我需要的是获取最后一次提交的 zip 文件并在我的项目中解压缩。我错过了什么?如何解决此问题

// your Bitbucket username
$username   = "edifreak";

// your Bitbucket repo name
$reponame   = "canvas-game-demo";

// extract to
$dest       = "./"; // leave ./ for relative destination

////////////////////////////////////////////////////////
// Let's get stuff done!

// set higher script timeout (for large repo's or slow servers)
set_time_limit(380);

// download the repo zip file
$repofile = file_get_contents("https://bitbucket.org/$username/$reponame/get/tip.zip");
file_put_contents('tip.zip', $repofile);
unset($repofile);

// unzip
$zip = new ZipArchive;
$res = $zip->open('tip.zip');
if ($res === TRUE) {
    $zip->extractTo('./');
    $zip->close();
} else {
    die('ZIP not supported on this server!');
}

// delete unnecessary .hg files
@unlink("$username-$reponame-tip/.hgignore");
@unlink("$username-$reponame-tip/.hg_archival.txt");

// function to delete all files in a directory recursively
function rmdir_recursively($dir) { 
    if (is_dir($dir)) { 
        $objects = scandir($dir); 
        foreach ($objects as $object) { 
            if ($object != "." && $object != "..") { 
                if (filetype($dir."/".$object) == "dir") rmdir_recursively($dir."/".$object); else unlink($dir."/".$object); 
            } 
        } 
        reset($objects); 
        rmdir($dir); 
    } 
} 

// function to recursively copy the files
function copy_recursively($src, $dest) {
    if (is_dir($src)) {
        if($dest != "./") rmdir_recursively($dest);
        @mkdir($dest);
        $files = scandir($src);
        foreach ($files as $file)
            if ($file != "." && $file != "..") copy_recursively("$src/$file", "$dest/$file"); 
        }
    else if (file_exists($src)) copy($src, $dest);
    rmdir_recursively($src);
}

// start copying the files from extracted repo and delete the old directory recursively
copy_recursively("$username-$reponame-tip", $dest);

// delete the repo zip file
unlink("tip.zip");

// Yep, we're done :)
echo "We're done!";

?>

【问题讨论】:

    标签: php bitbucket bitbucket-api


    【解决方案1】:

    尝试将身份验证(user:pass)放入 url:

    $repofile = file_get_contents("https://user:pass@bitbucket.org/$username/$reponame/get/tip.zip");
    

    身份验证必须是对存储库具有读取权限的用户。

    【讨论】:

      猜你喜欢
      • 2017-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-09
      • 1970-01-01
      • 2013-05-14
      • 1970-01-01
      相关资源
      最近更新 更多