Skip to content

Commit 5417c68

Browse files
committed
Bitbucket support added
1 parent 68c7a12 commit 5417c68

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/GitHook/GitHook.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,42 @@ public function getLogger(){
9595
public function parseRequest($rawRequest){
9696
$this->aRequest = collect(json_decode($rawRequest, true));
9797

98+
/* Check if the Request comes from bitbucket
99+
* An example payload can be found here: https://confluence.atlassian.com/bitbucket/event-payloads-740262817.html#EventPayloads-Push
100+
* */
101+
if($this->aRequest->has('push')){
102+
$aPush = $this->aRequest->get('push');
103+
$aRepository = $this->aRequest->get('repository');
104+
$aCommit = [];
105+
106+
foreach($aPush['changes'] as $aChange){
107+
foreach($aChange['commits'] as $commit){
108+
109+
$this->aRequest->put('user_name', $commit['author']['user']['display_name']);
110+
$this->aRequest->put('before', $aChange['new']['target']['parents'][0]['hash']);
111+
$this->aRequest->put('after', $aChange['new']['target']['hash']);
112+
113+
$commit['id'] = $commit['hash'];
114+
$commit['timestamp'] = $commit['date'];
115+
$commit['url'] = $commit['links']['html']['href'];
116+
$commit['author'] = [
117+
'name' => $commit['author']['user']['display_name'],
118+
'email' => '',
119+
];
120+
121+
$aCommit[] = $commit;
122+
}
123+
$this->aRequest->put('ref', 'ref/branch/'.$aChange['new']['name']);
124+
}
125+
126+
$aRepository['description'] = '';
127+
$aRepository['url'] = $aRepository['links']['html']['href'];
128+
$aRepository['homepage'] = $aRepository['website'];
129+
130+
$this->aRequest->put('commits', $aCommit);
131+
$this->aRequest->put('repository', $aRepository);
132+
}
133+
98134
if($this->aRequest->has('commits'))
99135
$this->aRequest->put('commits', collect($this->aRequest->get('commits')));
100136

0 commit comments

Comments
 (0)