dongtan3395 2012-10-04 12:34
浏览 87
已采纳

用php获取最后一次提交的zip

I found the code below for automated deploying php project. The problem is "https://bitbucket.org/$username/$reponame/get/tip.zip" this url doesnt work on private git repo on bitbucket private git repo: probably related with authentication (I haven't tested this on public repo) What i need is to get the last commit's zip file and unzip inside my project. What am i missing? How to fix this issue

// 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!";

?>
  • 写回答

1条回答 默认 最新

  • doucuodan0897 2013-06-05 02:59
    关注

    Try putting the authentication (user:pass) in the url:

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

    The authentication must be of a user with read access to the repository.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 qgcomp混合物线性模型分析的代码出现错误:Model aliasing occurred
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答
  • ¥20 在本地部署CHATRWKV时遇到了AttributeError: 'str' object has no attribute 'requires_grad'