Below my class:
class JenkinsDiffEventListener extends PhutilEventListener {
public function register() {
$this->listen(ArcanistEventType::TYPE_DIFF_WASCREATED);
}
public function handleEvent(PhutilEvent $event) {
$diff_id = $event->getValue('diffID');
/* Need to send a get request to jenkins to trigger the job. We pass the
* diff id to jenkins via its api.
*/
$workflow = $event->getValue('workflow');
$jenkins_uri = $workflow->getConfigFromAnySource('jenkins.uri');
$jenkins_jobs = $workflow->getConfigFromAnySource('jenkins.jobs');
if (!$jenkins_uri || !$jenkins_jobs) {
return;
}
foreach ($jenkins_jobs as $job) {
$url = $jenkins_uri."/job/".$job."/buildWithParameters?DIFF_ID=".$diff_id;
file_get_contents($url);
}
}
}
Do you know how can I get the name of the current git branch from this class? I would like to do something as below:
$branch = $workflow->getSomething()->getBranch();
$url = $jenkins_uri."/job/".$job."/buildWithParameters?DIFF_ID=".$diff_id."&BRANCH=".$branch;
Thanks
I found the answer :
$branch = $workflow->getRepositoryAPI()->getBranchName();
Thanks