Skip to content

Instantly share code, notes, and snippets.

@guywarner
Created May 17, 2014 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guywarner/522916f4d21fa66123d7 to your computer and use it in GitHub Desktop.
Save guywarner/522916f4d21fa66123d7 to your computer and use it in GitHub Desktop.
<?php
/*
* Copyright 2013 Disqus, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Hacked up by Guy Warner - gwarner@blendtec.com
*/
class JenkinsDiffEventListener extends PhutilEventListener
{
public function register()
{
$this->listen(PhabricatorEventType::TYPE_DIFFERENTIAL_DIDEDITREVISION);
}
public function handleEvent(PhutilEvent $event)
{
$revision = $event->getValue('revision');
$jenkinsUri = "";
$jenkinsJob = "";
$jenkinsToken = "";
// get the latest - with assumption that its the right one
$diff = array_shift(id(new DifferentialDiff())->loadAllWhere(
'revisionID = %s ORDER BY id LIMIT 1', $revision->getID()
));
// Example to set based on repo's PHID
//if ($diff->getArcanistProjectPHID() == "PHID-APRJ-otkaa6qb62yfm5i7ioe2") {
// $jenkinsUri = "http://ci.domain.com:8080";
// $jenkinsJob = "AWESOME-JOB";
// $jenkinsToken = "thisIsTheToken";
//}
if ($jenkinsUri) {
$diffID = $diff->getId();
$url = $jenkinsUri . "/job/" . $jenkinsJob . "/buildWithParameters";
$data = array(
'token' => $jenkinsToken,
'DIFF_ID' => $diffID,
'cause' => 'D' . $revision->getID() . ' - diff id ' . $diffID
);
$dataString = "";
foreach ($data as $key => $value) {
$dataString .= $key . '=' . $value . '&';
}
rtrim($dataString, '&');
$url = "$url?$dataString";
HTTPSFuture::loadContent($url);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment