Git Product home page Git Product logo

Comments (21)

jordantrizz avatar jordantrizz commented on July 18, 2024 4

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.

vatsh95 avatar vatsh95 commented on July 18, 2024 3

Same here

from git-deploy.

vatsh95 avatar vatsh95 commented on July 18, 2024 2

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.

renehamburger avatar renehamburger commented on July 18, 2024 2

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.

3pepe3 avatar 3pepe3 commented on July 18, 2024 1

Same here with bitbucket

from git-deploy.

pragmas avatar pragmas commented on July 18, 2024 1

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.

vicenteguerra avatar vicenteguerra commented on July 18, 2024

¿Do you have more info about this?

from git-deploy.

ShadowFM avatar ShadowFM commented on July 18, 2024

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.

aanderse avatar aanderse commented on July 18, 2024

@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.

JacobDB avatar JacobDB commented on July 18, 2024

@aanderse can you open a new issue for that?

from git-deploy.

aanderse avatar aanderse commented on July 18, 2024

@JacobDB certainly: #33

from git-deploy.

rocker76 avatar rocker76 commented on July 18, 2024

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.

jordantrizz avatar jordantrizz commented on July 18, 2024

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.

DarrellBrogdon avatar DarrellBrogdon commented on July 18, 2024

Any status updates on this issue? It's still broken for Bitbucket.

from git-deploy.

konkhra avatar konkhra commented on July 18, 2024

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.

pragmas avatar pragmas commented on July 18, 2024

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.

Serversapollo avatar Serversapollo commented on July 18, 2024

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.

konkhra avatar konkhra commented on July 18, 2024

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.

Serversapollo avatar Serversapollo commented on July 18, 2024

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 ?

Github

from git-deploy.

nvjacobo avatar nvjacobo commented on July 18, 2024

Hi,

Same here with gitlab

=== ERROR: Pushed branch does not match BRANCH ===

from git-deploy.

obhishekbatif avatar obhishekbatif commented on July 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.