-
Notifications
You must be signed in to change notification settings - Fork 108
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
Support for spaces in Jenkins Builds names with getNameURLSafe(), add getDescription(), getGitRevision(), getGitBranch() and getGitRemoteURL() #37
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ class Jenkins | |
/** | ||
* @param string $baseUrl | ||
*/ | ||
public function __construct($baseUrl) | ||
public function __construct($baseUrl) | ||
{ | ||
$this->baseUrl = $baseUrl; | ||
} | ||
|
@@ -279,7 +279,7 @@ public function launchJob($jobName, $parameters = array()) | |
*/ | ||
public function getJob($jobName) | ||
{ | ||
$url = sprintf('%s/job/%s/api/json', $this->baseUrl, $jobName); | ||
$url = sprintf('%s/job/%s/api/json', $this->baseUrl, Jenkins::urlSanitise($jobName)); | ||
$curl = curl_init($url); | ||
|
||
curl_setopt($curl, \CURLOPT_RETURNTRANSFER, 1); | ||
|
@@ -427,7 +427,9 @@ public function getBuild($job, $buildId, $tree = 'actions[parameters,parameters[ | |
if ($tree !== null) { | ||
$tree = sprintf('?tree=%s', $tree); | ||
} | ||
|
||
$url = sprintf('%s/job/%s/%d/api/json%s', $this->baseUrl, $job, $buildId, $tree); | ||
|
||
$curl = curl_init($url); | ||
|
||
curl_setopt($curl, \CURLOPT_RETURNTRANSFER, 1); | ||
|
@@ -826,4 +828,15 @@ public function getComputerConfiguration($computerName) | |
{ | ||
return $this->execute(sprintf('/computer/%s/config.xml', $computerName), array(\CURLOPT_RETURNTRANSFER => 1,)); | ||
} | ||
|
||
/** | ||
* URL sanitise a given string | ||
* @param $string | ||
* @return mixed|string | ||
*/ | ||
static public function urlSanitise($string){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. urlSanitize ? |
||
$string = urlencode($string); | ||
$string = str_replace("+", "%20", $string); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use http://us2.php.net/rawurlencode which seems to encode '+' character. |
||
return $string; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,41 @@ public function getNumber() | |
return $this->build->number; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getDescription() | ||
{ | ||
return $this->build->description; | ||
} | ||
|
||
public function getGitRevision() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these properties specific to git ? |
||
{ | ||
foreach($this->build->actions as $action){ | ||
if(property_exists($action, 'buildsByBranchName')){ | ||
return $action->lastBuiltRevision->SHA1; | ||
} | ||
} | ||
} | ||
|
||
public function getGitBranch() | ||
{ | ||
foreach($this->build->actions as $action){ | ||
if(property_exists($action, 'buildsByBranchName')){ | ||
return $action->lastBuiltRevision->branch[0]->name; | ||
} | ||
} | ||
} | ||
|
||
public function getGitRemoteURL() | ||
{ | ||
foreach($this->build->actions as $action){ | ||
if(property_exists($action, 'buildsByBranchName')){ | ||
return $action->remoteUrls[0]; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @return null|int | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change is not necessary