PHP code example of denx-b / bitbucket-webhook

1. Go to this page and download the library: Download denx-b/bitbucket-webhook library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

denx-b / bitbucket-webhook example snippets


use Dbogdanoff\Bitbucket;

// Repository events (Push, Fork, Updated, Commit, ...) 
$repo = new Bitbucket\Repo();
$push = $repo->getPush(); // array
$fork = $repo->getFork(); // array
$branch = $repo->getBranch(); // string
$changes = $repo->getChanges(); // array — 'changes' from root or 'changes' key from 'push'
$authorNickName = $repo->getAuthorNickName(); // string

// Issue events (Created, Updated, Comment created)
$issue = new Bitbucket\Issue();
$issue = $issue->getIssue(); // array

// Pull request events (Created, Updated, Change, ...)
$pullRequest = new Bitbucket\PullRequest();
$title = $pullRequest->getTitle(); // string
$link = $pullRequest->getLink(); // string
$data = $pullRequest->getPullRequest(); // array
$author = $pullRequest->getAuthor(); // array
$authorNickName = $pullRequest->getAuthorNickName(); // string
$commentText = $pullRequest->getCommentText(); // string
$commentInlinePath = $pullRequest->getCommentInlinePath(); // string
$commentInlineNumber = $pullRequest->getCommentInlineNumber(); // string

// All objects extended from Bitbucket\Base()
$actor = $repo->getActor(); // array
$nickname = $repo->getNickName(); // string
$repository = $repo->getRepository(); // array
$projectName = $repo->getProjectName(); // string
$eventType = $repo->getEventKey(); // string — repo:push, repo:updated, pullrequest:created, ...
$rawData = $repo->getRawData(); // array — full data

// Bitbucket\Repo::__construct()
if (strpos($_SERVER['HTTP_X_EVENT_KEY'], 'repo:') === false) {
    throw new Exception('Invalid request type');
}

// Bitbucket\Issue::__construct()
if (strpos($_SERVER['HTTP_X_EVENT_KEY'], 'issue:') === false) {
    throw new Exception('Invalid request type');
}

// Bitbucket\PullRequest::__construct()
if (strpos($_SERVER['HTTP_X_EVENT_KEY'], 'pullrequest:') === false) {
    throw new Exception('Invalid request type');
}