Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webhook observe configured branches #1333

Open
wants to merge 20 commits into
base: master
from

Conversation

Projects
None yet
3 participants
@phizzl
Copy link

phizzl commented Jun 8, 2017

Contribution Type: new feature

This pull request affects the following areas:

  • Front-End
  • Builder
  • Build Plugins

In raising this pull request, I confirm the following (please check boxes):

  • I have read and understood the contributing guidelines?
  • I have checked that another pull request for this purpose does not exist.
  • I have considered, and confirmed that this submission will be valuable to others.
  • I have created or updated the relevant documentation for this change on the PHPCI Wiki.
  • Do the PHPCI tests pass?

Detailed description of change:

When working with GIT webhooks every commit of every contributor triggers a build in PHPCI. As I have very time consuming acceptance tests with Codeception and my contributors are pushing a lot of stuff PHPCI is always very busy. For me there is no need to run all tests for every commit on every branch. Important for me is my master branch and my release candidate branches where I put all branches of my contributors together to see if it works.
So I've added a textarea with the name "observed_branches" to the project configuration page.
Before a build is triggered via webhook by WebhookController::createBuild I check if the requestet branch is in the projects branch observation by getting the text from "observed_branches" and exploding it by PHP_EOL. After that I'll check if the branch name submitted by the webhook is in my exploded array. If not I will not create the build.
If the project option "observed_branches" is empty all incoming branch names are triggering a build creation as it is now.
You may also use the * sign as a wildcard for branch names when configuring the "observed_branches" option, as I use this for my RC branches. For example a configuration like

master
rc-*

would accept a build creation via webhook for the "master" branch and all branch names starting with "rc-"

Maybe this can be helpful to others.

branchobservation
branchobservationwebhookignored

@@ -425,6 +425,13 @@ protected function createBuild(
$commitMessage,
array $extra = null
) {
if(!$this->isBranchObserved($branch, $project)){

This comment has been minimized.

Copy link
@phpcibot

phpcibot Jun 8, 2017

PHPCS: Expected 1 space after IF keyword; 0 found

@@ -425,6 +425,13 @@ protected function createBuild(
$commitMessage,
array $extra = null
) {
if(!$this->isBranchObserved($branch, $project)){

This comment has been minimized.

Copy link
@phpcibot

phpcibot Jun 8, 2017

PHPCS: Expected 1 space after closing parenthesis; found 0

*/
protected function isBranchObserved($branch, Project $project)
{
if(($observedBranchesStr = trim($project->getObservedBranches())) === ''){

This comment has been minimized.

Copy link
@phpcibot

phpcibot Jun 8, 2017

PHPCS: Expected 1 space after IF keyword; 0 found

*/
protected function isBranchObserved($branch, Project $project)
{
if(($observedBranchesStr = trim($project->getObservedBranches())) === ''){

This comment has been minimized.

Copy link
@phpcibot

phpcibot Jun 8, 2017

PHPCS: Expected 1 space after closing parenthesis; found 0

}

$observedBranches = explode(PHP_EOL, $observedBranchesStr);
foreach($observedBranches as $observedBranch){

This comment has been minimized.

Copy link
@phpcibot

phpcibot Jun 8, 2017

PHPCS: Expected 1 space after FOREACH keyword; 0 found

}

$observedBranches = explode(PHP_EOL, $observedBranchesStr);
foreach($observedBranches as $observedBranch){

This comment has been minimized.

Copy link
@phpcibot

phpcibot Jun 8, 2017

PHPCS: Expected 1 space after closing parenthesis; found 0


$observedBranches = explode(PHP_EOL, $observedBranchesStr);
foreach($observedBranches as $observedBranch){
if($this->stringContains($branch, $observedBranch)){

This comment has been minimized.

Copy link
@phpcibot

phpcibot Jun 8, 2017

PHPCS: Expected 1 space after IF keyword; 0 found


$observedBranches = explode(PHP_EOL, $observedBranchesStr);
foreach($observedBranches as $observedBranch){
if($this->stringContains($branch, $observedBranch)){

This comment has been minimized.

Copy link
@phpcibot

phpcibot Jun 8, 2017

PHPCS: Expected 1 space after closing parenthesis; found 0

*/
protected function stringContains($str1, $str2)
{
if($str1 === $str2){

This comment has been minimized.

Copy link
@phpcibot

phpcibot Jun 8, 2017

PHPCS: Expected 1 space after IF keyword; 0 found

*/
protected function stringContains($str1, $str2)
{
if($str1 === $str2){

This comment has been minimized.

Copy link
@phpcibot

phpcibot Jun 8, 2017

PHPCS: Expected 1 space after closing parenthesis; found 0

return true;
}

if(($pos = strrpos($str2, '*')) !== false){

This comment has been minimized.

Copy link
@phpcibot

phpcibot Jun 8, 2017

PHPCS: Expected 1 space after IF keyword; 0 found

return true;
}

if(($pos = strrpos($str2, '*')) !== false){

This comment has been minimized.

Copy link
@phpcibot

phpcibot Jun 8, 2017

PHPCS: Expected 1 space after closing parenthesis; found 0

@@ -425,6 +425,13 @@ protected function createBuild(
$commitMessage,
array $extra = null
) {
if(!$this->isBranchObserved($branch, $project)){

This comment has been minimized.

Copy link
@phpcibot

phpcibot Jun 9, 2017

PHPCS: Expected 1 space after IF keyword; 0 found

@@ -425,6 +425,13 @@ protected function createBuild(
$commitMessage,
array $extra = null
) {
if(!$this->isBranchObserved($branch, $project)){

This comment has been minimized.

Copy link
@phpcibot

phpcibot Jun 9, 2017

PHPCS: Expected 1 space after closing parenthesis; found 0

*/
protected function isBranchObserved($branch, Project $project)
{
if(($observedBranchesStr = trim($project->getObservedBranches())) === ''){

This comment has been minimized.

Copy link
@phpcibot

phpcibot Jun 9, 2017

PHPCS: Expected 1 space after IF keyword; 0 found

*/
protected function isBranchObserved($branch, Project $project)
{
if(($observedBranchesStr = trim($project->getObservedBranches())) === ''){

This comment has been minimized.

Copy link
@phpcibot

phpcibot Jun 9, 2017

PHPCS: Expected 1 space after closing parenthesis; found 0

}

$observedBranches = explode(PHP_EOL, $observedBranchesStr);
foreach($observedBranches as $observedBranch){

This comment has been minimized.

Copy link
@phpcibot

phpcibot Jun 9, 2017

PHPCS: Expected 1 space after FOREACH keyword; 0 found

}

$observedBranches = explode(PHP_EOL, $observedBranchesStr);
foreach($observedBranches as $observedBranch){

This comment has been minimized.

Copy link
@phpcibot

phpcibot Jun 9, 2017

PHPCS: Expected 1 space after closing parenthesis; found 0


$observedBranches = explode(PHP_EOL, $observedBranchesStr);
foreach($observedBranches as $observedBranch){
if($this->stringContains($branch, $observedBranch)){

This comment has been minimized.

Copy link
@phpcibot

phpcibot Jun 9, 2017

PHPCS: Expected 1 space after IF keyword; 0 found


$observedBranches = explode(PHP_EOL, $observedBranchesStr);
foreach($observedBranches as $observedBranch){
if($this->stringContains($branch, $observedBranch)){

This comment has been minimized.

Copy link
@phpcibot

phpcibot Jun 9, 2017

PHPCS: Expected 1 space after closing parenthesis; found 0

*/
protected function stringContains($str1, $str2)
{
if($str1 === $str2){

This comment has been minimized.

Copy link
@phpcibot

phpcibot Jun 9, 2017

PHPCS: Expected 1 space after IF keyword; 0 found

*/
protected function stringContains($str1, $str2)
{
if($str1 === $str2){

This comment has been minimized.

Copy link
@phpcibot

phpcibot Jun 9, 2017

PHPCS: Expected 1 space after closing parenthesis; found 0

return true;
}

if(($pos = strrpos($str2, '*')) !== false){

This comment has been minimized.

Copy link
@phpcibot

phpcibot Jun 9, 2017

PHPCS: Expected 1 space after IF keyword; 0 found

return true;
}

if(($pos = strrpos($str2, '*')) !== false){

This comment has been minimized.

Copy link
@phpcibot

phpcibot Jun 9, 2017

PHPCS: Expected 1 space after closing parenthesis; found 0

@dancryer
Copy link
Owner

dancryer left a comment

@phizzl Apologies for the slow response. I really like this PR - if you could fix up the various bits that PHPCI flagged in the diffs, I'll happily merge it!

Thanks! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.