【发布时间】:2015-04-22 08:18:49
【问题描述】:
我有一个多个人一起工作的 PHP 包的 SVN 存储库。我们希望公开该软件包,因此我们已将其添加到 packagist 中,网址为 svn://svn.xxxx.com/my-package
如何向存储库添加挂钩,以便每当开发人员提交时,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"}}"
【问题讨论】:
-
我认为您的 REPO_URL 结构有问题。错误提示“无法解析有效负载存储库 URL”,这可能意味着您的 composer.json 文件不在存储库的顶部。您的 REPO_URL 是指向 packagist.org 还是您的 svn 存储库 url?它应该指向你的 svn url。
-
是的,问题似乎出在有效载荷 url 上。感谢您澄清它应该指向哪个 URL,我现在正在尝试这个(仍然无法正常工作)。也许packagist不支持通过钩子支持SVN协议,即使它手动支持?我需要用修订号或其他东西扩展网址吗?
-
我刚刚挖掘了代码并找到了它所期望的 url 正则表达式,这似乎取消了 svn 存储库的资格,但支持 git(github.com/composer/packagist/blob/master/src/Packagist/… 中的 updatePackageAction 方法)。这是我从这个错误报告中得出的结论:packagist 的人不支持 SVN 的问题:github.com/composer/packagist/issues/151
-
您可以通过 http/https 协议公开您的 svn 存储库。设置 apache svn 模块并不是很困难。
-
@Boris 是的,我必须回到那个话题。上次我尝试时卡在“webdav”上