I have a SVN repository for a PHP package that multiple people work together on. We wish to make the package publicly available, so we have added it to packagist with the url svn://svn.xxxx.com/my-package
How do I add a hook to the repository such that whenever a developer makes a commit, packagist is automatically updated, similar to the service hook available in Github?
Update
I managed to find the what I was looking for on this page of packagist with the relevant section below:
I have written a script in PHP to do this for me (simply because I am far more comfortable with PHP than python), for which you will need to install PHP5-cli and php curl packages, which can be done on ubuntu with the following command:
sudo apt-get install php5-cli php5-curl -y
post-commit file
#!/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);
Make sure to chmod +x
the file after creating it.
Current Issue
Unfortunately, this I get stuck with the following response error message:
array(2) {
["status"]=>
string(5) "error"
["message"]=>
string(38) "Could not parse payload repository URL"
}
When I var_dump the data I am sending, it is as follows:
string(43) "{"repository":{"url":"xxx/table-creator"}}"