2013-11-09 16:16:12 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class HarbormasterHTTPRequestBuildStepImplementation
|
2014-03-26 00:02:07 +01:00
|
|
|
extends BuildStepImplementation {
|
2013-11-09 16:16:12 +01:00
|
|
|
|
|
|
|
public function getName() {
|
|
|
|
return pht('Make HTTP Request');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getGenericDescription() {
|
|
|
|
return pht('Make an HTTP request.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDescription() {
|
|
|
|
$settings = $this->getSettings();
|
|
|
|
|
|
|
|
$uri = new PhutilURI($settings['uri']);
|
|
|
|
$domain = $uri->getDomain();
|
Added 'method' field to the HTTP request build step.
Summary:
This revision adds a 'method' field to the HTTP request harbormaster build step. This allows the user to specify GET, POST, DELETE, and PUT (limited by the underlying wrapper phabricator uses for HTTP requests). I'm not sure how much sense PUT makes, but oh well.
Existing plans shouldn't break, as if this field is an empty string, we default to POST, which is the old behavior.
Fixes T4604
Test Plan: 1) Verified that the empty string does, in fact, issue a POST request. Changed the method to be GET and observed that the problem described in T4604 is resolved.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: aran, epriestley
Maniphest Tasks: T4604
Differential Revision: https://secure.phabricator.com/D8520
2014-03-13 23:49:42 +01:00
|
|
|
return pht('Make an HTTP %s request to %s', $settings['method'], $domain);
|
2013-11-09 16:16:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(
|
|
|
|
HarbormasterBuild $build,
|
2013-12-05 02:01:12 +01:00
|
|
|
HarbormasterBuildTarget $build_target) {
|
2013-11-09 16:16:12 +01:00
|
|
|
|
|
|
|
$settings = $this->getSettings();
|
2013-12-05 02:01:12 +01:00
|
|
|
$variables = $build_target->getVariables();
|
2013-11-09 16:16:12 +01:00
|
|
|
|
|
|
|
$uri = $this->mergeVariables(
|
|
|
|
'vurisprintf',
|
|
|
|
$settings['uri'],
|
|
|
|
$variables);
|
|
|
|
|
2013-12-05 02:01:12 +01:00
|
|
|
$log_body = $build->createLog($build_target, $uri, 'http-body');
|
2013-11-09 16:16:12 +01:00
|
|
|
$start = $log_body->start();
|
|
|
|
|
Added 'method' field to the HTTP request build step.
Summary:
This revision adds a 'method' field to the HTTP request harbormaster build step. This allows the user to specify GET, POST, DELETE, and PUT (limited by the underlying wrapper phabricator uses for HTTP requests). I'm not sure how much sense PUT makes, but oh well.
Existing plans shouldn't break, as if this field is an empty string, we default to POST, which is the old behavior.
Fixes T4604
Test Plan: 1) Verified that the empty string does, in fact, issue a POST request. Changed the method to be GET and observed that the problem described in T4604 is resolved.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: aran, epriestley
Maniphest Tasks: T4604
Differential Revision: https://secure.phabricator.com/D8520
2014-03-13 23:49:42 +01:00
|
|
|
$method = 'POST';
|
|
|
|
if ($settings['method'] !== '') {
|
|
|
|
$method = $settings['method'];
|
|
|
|
}
|
|
|
|
|
2013-11-09 16:16:12 +01:00
|
|
|
list($status, $body, $headers) = id(new HTTPSFuture($uri))
|
Added 'method' field to the HTTP request build step.
Summary:
This revision adds a 'method' field to the HTTP request harbormaster build step. This allows the user to specify GET, POST, DELETE, and PUT (limited by the underlying wrapper phabricator uses for HTTP requests). I'm not sure how much sense PUT makes, but oh well.
Existing plans shouldn't break, as if this field is an empty string, we default to POST, which is the old behavior.
Fixes T4604
Test Plan: 1) Verified that the empty string does, in fact, issue a POST request. Changed the method to be GET and observed that the problem described in T4604 is resolved.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: aran, epriestley
Maniphest Tasks: T4604
Differential Revision: https://secure.phabricator.com/D8520
2014-03-13 23:49:42 +01:00
|
|
|
->setMethod($method)
|
2013-11-09 16:16:12 +01:00
|
|
|
->setTimeout(60)
|
|
|
|
->resolve();
|
|
|
|
|
|
|
|
$log_body->append($body);
|
|
|
|
$log_body->finalize($start);
|
|
|
|
|
|
|
|
if ($status->getStatusCode() != 200) {
|
|
|
|
$build->setBuildStatus(HarbormasterBuild::STATUS_FAILED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function validateSettings() {
|
|
|
|
$settings = $this->getSettings();
|
|
|
|
|
|
|
|
if ($settings['uri'] === null || !is_string($settings['uri'])) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-18 20:05:14 +01:00
|
|
|
$methods = array(
|
|
|
|
'GET' => true,
|
|
|
|
'POST' => true,
|
|
|
|
'DELETE' => true,
|
|
|
|
'PUT' => true,
|
|
|
|
);
|
|
|
|
|
|
|
|
$method = idx($settings, 'method');
|
|
|
|
if (strlen($method)) {
|
|
|
|
if (empty($methods[$method])) {
|
|
|
|
return false;
|
|
|
|
}
|
Added 'method' field to the HTTP request build step.
Summary:
This revision adds a 'method' field to the HTTP request harbormaster build step. This allows the user to specify GET, POST, DELETE, and PUT (limited by the underlying wrapper phabricator uses for HTTP requests). I'm not sure how much sense PUT makes, but oh well.
Existing plans shouldn't break, as if this field is an empty string, we default to POST, which is the old behavior.
Fixes T4604
Test Plan: 1) Verified that the empty string does, in fact, issue a POST request. Changed the method to be GET and observed that the problem described in T4604 is resolved.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: aran, epriestley
Maniphest Tasks: T4604
Differential Revision: https://secure.phabricator.com/D8520
2014-03-13 23:49:42 +01:00
|
|
|
}
|
|
|
|
|
2013-11-09 16:16:12 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSettingDefinitions() {
|
|
|
|
return array(
|
|
|
|
'uri' => array(
|
|
|
|
'name' => 'URI',
|
|
|
|
'description' => pht('The URI to request.'),
|
|
|
|
'type' => BuildStepImplementation::SETTING_TYPE_STRING,
|
|
|
|
),
|
Added 'method' field to the HTTP request build step.
Summary:
This revision adds a 'method' field to the HTTP request harbormaster build step. This allows the user to specify GET, POST, DELETE, and PUT (limited by the underlying wrapper phabricator uses for HTTP requests). I'm not sure how much sense PUT makes, but oh well.
Existing plans shouldn't break, as if this field is an empty string, we default to POST, which is the old behavior.
Fixes T4604
Test Plan: 1) Verified that the empty string does, in fact, issue a POST request. Changed the method to be GET and observed that the problem described in T4604 is resolved.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: aran, epriestley
Maniphest Tasks: T4604
Differential Revision: https://secure.phabricator.com/D8520
2014-03-13 23:49:42 +01:00
|
|
|
'method' => array(
|
|
|
|
'name' => 'Method',
|
|
|
|
'description' =>
|
|
|
|
pht('Request type. Should be GET, POST, PUT, or DELETE.'),
|
|
|
|
'type' => BuildStepImplementation::SETTING_TYPE_STRING,
|
|
|
|
),
|
2013-11-09 16:16:12 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|