我有一个多人共同工作的PHP包的SVN存储库。我们希望使该包公开可用,因此我们使用url svn://svn.xxxx.com/my-package将其添加到packagist中
我如何向存储库添加一个钩子,以便每当开发人员提交时,packagist都会自动更新,类似于Github中提供的服务钩子?
更新
我设法在packagist的this page上找到了我正在寻找的东西,相关部分如下:

我已经用PHP编写了一个脚本来为我做这件事(简单地说,因为我对PHP比python更熟悉),你需要安装PHP5-cli和php curl包,这可以在ubuntu上用以下命令完成:
sudo apt-get install php5-cli php5-curl -y提交后文件
#!/usr/bin/php
<?php
# Code for sending post request taken from:
# https://stackoverflow.com/questions/16920291/post-request-with-json-body
define('API_TOKEN', 'xxx');
define('USER', 'xxx');
define('REPO_URL', 'https://packagist.org/packages/xxx/xxx');
#define('REPO_URL', 'svn://svn.xxx.com/xxx');
$data = array(
'repository' => array('url' => REPO_URL)
);
// Setup cURL
$url = 'https://packagist.org/api/update-package?username=' . USER . '&apiToken=' . API_TOKEN;
$ch = curl_init($url);
curl_setopt_array($ch, array(
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPHEADER => array('Content-Type: application/json'),
CURLOPT_POSTFIELDS => json_encode($data)
));
// Send the request
$response = curl_exec($ch);
// Check for errors
if ($response === FALSE)
{
die(curl_error($ch));
}
// Decode the response
$responseData = json_decode($response, TRUE);
// Print the date from the response
var_dump($responseData);确保在创建文件后对其执行chmod +x操作。
当前问题
不幸的是,我遇到了以下响应错误消息:
array(2) {
["status"]=>
string(5) "error"
["message"]=>
string(38) "Could not parse payload repository URL"
}当我var_dump我正在发送的数据时,它如下所示:
string(43) "{"repository":{"url":"xxx/table-creator"}}"发布于 2015-02-21 10:31:46
您可以通过使用svn post-commit挂钩来实现这一点。这段代码非常接近您所要求的内容。它是用python编写的,你可以很容易地用bash甚至php重写它。我假设您有标准的svn存储库结构,其中包含主干、标记和分支目录。此外,您还必须更改包名称和目录路径。
#!/usr/bin/env python
import sys
import tempfile
import subprocess
import tarfile
import shutil
SVN = '/usr/bin/svn'
SVNLOOK = '/usr/bin/svnlook'
PACKAGE_NAME = 'my-package'
if __name__ == '__main__':
repository = sys.argv[1]
revision = sys.argv[2]
tmpdir = tempfile.mkdtemp()
exportdir = tmpdir + '/' + PACKAGE_NAME
archive = tmpdir + '/' + PACKAGE_NAME + '.tar.gz'
# Stop hook from running recursively
cmd = SVNLOOK + ' dirs-changed -r ' + str(revision) + ' ' + repository
output = subprocess.check_output(cmd, shell = True)
if 'tags' in output:
sys.exit(0)
cmd = SVN + ' export ' + 'file://' + repository + '/trunk ' + exportdir
output = subprocess.check_output(cmd, shell = True)
if 'Exported' in output:
tar = tarfile.open(archive, 'w:gz')
tar.add(exportdir, arcname = PACKAGE_NAME)
tar.close()
# Copy archive to the final destination or add package back to your repository
# Example 1:
# shutil.copyfile(archive, '/path/to/new/location/file.tar.gz')
# Example 2:
cmd = SVN + ' rm file://' + repository + '/tags/' + PACKAGE_NAME + '.tar.gz -m \"Removed old package.\"'
output = subprocess.check_output(cmd, shell = True)
cmd = SVN + ' import ' + archive + ' file://' + repository + '/tags/' + PACKAGE_NAME + '.tar.gz --force -m \"Imported new package.\"'
output = subprocess.check_output(cmd, shell = True)
shutil.rmtree(tmpdir)
sys.exit(0)确保将其添加到/path/to/ repository /hooks/post-commit文件中,并在将其放入生产存储库之前对其进行彻底测试。
https://stackoverflow.com/questions/28632612
复制相似问题