Comments (21)
I just tried to set this up for a GitHub repository and it's failing. Printing out the array $json returns nothing. Am I missing anything?
This is because I didn't RTFM. Forgot to change the Content Type to json on the Webhooks screen in the repository. Shwoopsie!
from git-deploy.
Same here
from git-deploy.
Hi Edo/Vincenteguerra
I've found the error in the script and solved it,
the error happens at line 60 of deploy.php as we're unable to reference the branch properly.
As it looks like JSON Structure from bitbucket/git has changed and cannot read response properly from branch.
Try replacing the whole IF section with following code:
foreach ($json["push"]["changes"] as $change) {
if (
(
isset($change["old"]["type"])
&& isset($change["old"]["name"])
&& $change["old"]["type"] == "branch"
&& $change["old"]["name"] == "master"
)
|| (
isset($change["new"]["type"])
&& isset($change["new"]["name"])
&& $change["new"]["type"] == "branch"
&& $change["new"]["name"] == "master"
)
) {
exec("git pull https://YOUR_GIT_USERNAME:[email protected]/YOUR_GIT_USER/GIT_NAME.git YOUR_BRANCH_NAME");
die("Complete.");
}
}
you can structure your code as per vicenteguerra script as well but i've reduced my script code as i'm just going to pull from specific branch when webhook is called
from git-deploy.
As all changes should relate to the same branch I would think, maybe a check like $json['push']['changes'][0]['new']['name'] === BRANCH
is sufficient for bitbucket, as long as BRANCH is set to the raw branch name like 'master'.
from git-deploy.
Same here with bitbucket
from git-deploy.
Add this line in deployer.php on line 10:
if (isset($json['push']['changes'][0]['new']['name'])&&empty($json['ref'])) $json['ref']=$json['push']['changes'][0]['new']['name'];
That worked for me.
from git-deploy.
¿Do you have more info about this?
from git-deploy.
Hi @vatsh95
can you send your complete deploy.php?
I have the error"Unexpected 'else' (74, 3)" and "syntax error, unexpected 'else' (T_ELSE) (74, 9)"
from git-deploy.
@vicenteguerra do you have any plans to support merge request events? With gitlab the property to compare is "target_branch" instead of "ref".
from git-deploy.
@aanderse can you open a new issue for that?
from git-deploy.
from git-deploy.
I am using Bitbucket, and I still get an error.
Only time is recorded in the log file. 17-04-2019 (03:38:59)
Which part is the problem? :(
##deployer.php
// Check for a GitHub signature
if (!empty(TOKEN) && isset($_SERVER["HTTP_X_HUB_SIGNATURE"]) && $token !== hash_hmac($algo, $content, TOKEN)) {
forbid($file, "X-Hub-Signature does not match TOKEN");
// Check for a GitLab token
} elseif (!empty(TOKEN) && isset($_SERVER["HTTP_X_GITLAB_TOKEN"]) && $token !== TOKEN) {
forbid($file, "X-GitLab-Token does not match TOKEN");
// Check for a $_GET token
} elseif (!empty(TOKEN) && isset($_GET["token"]) && $token !== TOKEN) {
forbid($file, "$_GET["token"] does not match TOKEN");
// if none of the above match, but a token exists, exit
} elseif (!empty(TOKEN) && !isset($_SERVER["HTTP_X_HUB_SIGNATURE"]) && !isset($_SERVER["HTTP_X_GITLAB_TOKEN"]) && !isset($_GET["token"])) {
forbid($file, "No token detected");
} else {
// check if pushed branch matches branch specified in config
foreach ($json["push"]["changes"] as $change) {
if (
(
isset($change["old"]["type"])
&& isset($change["old"]["name"])
&& $change["old"]["type"] == "branch"
&& $change["old"]["name"] == "master"
)
|| (
isset($change["new"]["type"])
&& isset($change["new"]["name"])
&& $change["new"]["type"] == "branch"
&& $change["new"]["name"] == "master"
)
) {
exec("git pull origin master");
die("Complete.");
}
}
}
from git-deploy.
I just tried to set this up for a GitHub repository and it's failing. Printing out the array $json returns nothing. Am I missing anything?
from git-deploy.
Any status updates on this issue? It's still broken for Bitbucket.
from git-deploy.
Add this line in deployer.php on line 10:
if (isset($json['push']['changes'][0]['new']['name'])&&empty($json['ref'])) $json['ref']=$json['push']['changes'][0]['new']['name'];
That worked for me.
Could you be more specific with this? On line 10 in deployer.php I see this:
// retrieve the token
What version do you have?
from git-deploy.
Add this line in deployer.php on line 10:
if (isset($json['push']['changes'][0]['new']['name'])&&empty($json['ref'])) $json['ref']=$json['push']['changes'][0]['new']['name'];
That worked for me.Could you be more specific with this? On line 10 in deployer.php I see this:
// retrieve the token
What version do you have?
I added it before the comment:
$DIR = preg_match("//$/", DIR) ? DIR : DIR . "/";
// bitbucket ref issue https://github.com/vicenteguerra/git-deploy/issues/23
if (isset($json['push']['changes'][0]['new']['name'])&&empty($json['ref'])) $json['ref']=$json['push']['changes'][0]['new']['name'];
// retrieve the token
if (!$token && isset($_SERVER["HTTP_X_HUB_SIGNATURE"])) {
list($algo, $token) = explode("=", $_SERVER["HTTP_X_HUB_SIGNATURE"], 2) + array("", "");
from git-deploy.
hey , i was getting the same error , and after a few hours i was trying different changes in the code to figure out what was the problem (fun fact it was me) I realized that i was having the Content type from the github webhook settings set to application/x-www-form-urlencoded.
So the "fix" for me was to set the Content type to application/json
from git-deploy.
hey , i was getting the same error , and after a few hours i was trying different changes in the code to figure out what was the problem (fun fact it was me) I realized that i was having the Content type from the github webhook settings set to application/x-www-form-urlencoded.
So the "fix" for me was to set the Content type to application/json
Are you using bitbucket or github ?
from git-deploy.
hey , i was getting the same error , and after a few hours i was trying different changes in the code to figure out what was the problem (fun fact it was me) I realized that i was having the Content type from the github webhook settings set to application/x-www-form-urlencoded.
So the "fix" for me was to set the Content type to application/jsonAre you using bitbucket or github ?
Github
from git-deploy.
Hi,
Same here with gitlab
=== ERROR: Pushed branch does not match BRANCH ===
from git-deploy.
Hi Edo/Vincenteguerra
I've found the error in the script and solved it,
the error happens at line 60 of deploy.php as we're unable to reference the branch properly.As it looks like JSON Structure from bitbucket/git has changed and cannot read response properly from branch.
Try replacing the whole IF section with following code:
foreach ($json["push"]["changes"] as $change) { if ( ( isset($change["old"]["type"]) && isset($change["old"]["name"]) && $change["old"]["type"] == "branch" && $change["old"]["name"] == "master" ) || ( isset($change["new"]["type"]) && isset($change["new"]["name"]) && $change["new"]["type"] == "branch" && $change["new"]["name"] == "master" ) ) { exec("git pull https://YOUR_GIT_USERNAME:[email protected]/YOUR_GIT_USER/GIT_NAME.git YOUR_BRANCH_NAME"); die("Complete."); } }
you can structure your code as per vicenteguerra script as well but i've reduced my script code as i'm just going to pull from specific branch when webhook is called
Are you talking about deployer.php?
from git-deploy.
Related Issues (20)
- what is secret-token? HOT 1
- [feature request] response message body HOT 3
- Git pull not being executed over SSH HOT 1
- SSH not allowed on some hosts HOT 1
- `DIR` always needs to end in a forward slash, otherwise the script errors HOT 2
- always sh: 1: /usr/bin/git: not found HOT 2
- [feature request] support merge request events
- error on runtime T_PAAMAYIM_NEKUDOTAYIM
- [feature request] limit log file size
- Support for https for private OAUTH accounts using personal access tokens HOT 1
- Pull failed - permission denied HOT 2
- "No token detected" when token is provided HOT 2
- Not working for private repository HOT 3
- had problem
- had problem "Warning: shell_exec() has been disabled for security reasons" HOT 1
- "No output" error with github, works fine with gitlab HOT 1
- Permission Denied HOT 3
- Local commits / uncommitted changes are always reset when using gitlab webhooks
- Host key verification failed. HOT 2
- Paths HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from git-deploy.