1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Part of the Joomla Framework GitHub Package |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved. |
6
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Joomla\Github\Package\Repositories; |
10
|
|
|
|
11
|
|
|
use Joomla\Github\AbstractPackage; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* GitHub API Repositories Merging class for the Joomla Framework. |
15
|
|
|
* |
16
|
|
|
* @documentation http://developer.github.com/v3/repos/merging |
17
|
|
|
* |
18
|
|
|
* @since 1.0 |
19
|
|
|
*/ |
20
|
|
|
class Merging extends AbstractPackage |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Perform a merge. |
24
|
|
|
* |
25
|
|
|
* @param string $owner The name of the owner of the GitHub repository. |
26
|
|
|
* @param string $repo The name of the GitHub repository. |
27
|
|
|
* @param string $base The name of the base branch that the head will be merged into. |
28
|
|
|
* @param string $head The head to merge. This can be a branch name or a commit SHA1. |
29
|
|
|
* @param string $commit_message Commit message to use for the merge commit. |
30
|
|
|
* If omitted, a default message will be used. |
31
|
|
|
* |
32
|
|
|
* @throws \UnexpectedValueException |
33
|
|
|
* @since 1.0 |
34
|
|
|
* |
35
|
|
|
* @return boolean |
36
|
|
|
*/ |
37
|
|
|
public function perform($owner, $repo, $base, $head, $commit_message = '') |
38
|
|
|
{ |
39
|
|
|
// Build the request path. |
40
|
|
|
$path = '/repos/' . $owner . '/' . $repo . '/merges'; |
41
|
|
|
|
42
|
|
|
$data = new \stdClass; |
43
|
|
|
|
44
|
|
|
$data->base = $base; |
45
|
|
|
$data->head = $head; |
46
|
|
|
|
47
|
|
|
if ($commit_message) |
48
|
|
|
{ |
49
|
|
|
$data->commit_message = $commit_message; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
// Send the request. |
53
|
|
|
$response = $this->client->post($this->fetchUrl($path), json_encode($data)); |
54
|
|
|
|
55
|
|
|
switch ($response->code) |
56
|
|
|
{ |
57
|
|
|
case '201': |
58
|
|
|
// Success |
59
|
|
|
return json_decode($response->body); |
60
|
|
|
break; |
|
|
|
|
61
|
|
|
|
62
|
|
|
case '204': |
63
|
|
|
// No-op response (base already contains the head, nothing to merge) |
64
|
|
|
throw new \UnexpectedValueException('Nothing to merge'); |
65
|
|
|
break; |
|
|
|
|
66
|
|
|
|
67
|
|
View Code Duplication |
case '404': |
|
|
|
|
68
|
|
|
// Missing base or Missing head response |
69
|
|
|
$error = json_decode($response->body); |
70
|
|
|
|
71
|
|
|
$message = (isset($error->message)) ? $error->message : 'Missing base or head: ' . $response->code; |
72
|
|
|
|
73
|
|
|
throw new \UnexpectedValueException($message); |
74
|
|
|
break; |
|
|
|
|
75
|
|
|
|
76
|
|
View Code Duplication |
case '409': |
|
|
|
|
77
|
|
|
// Merge conflict response |
78
|
|
|
$error = json_decode($response->body); |
79
|
|
|
|
80
|
|
|
$message = (isset($error->message)) ? $error->message : 'Merge conflict ' . $response->code; |
81
|
|
|
|
82
|
|
|
throw new \UnexpectedValueException($message); |
83
|
|
|
break; |
|
|
|
|
84
|
|
|
|
85
|
|
|
default : |
86
|
|
|
throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); |
87
|
|
|
break; |
|
|
|
|
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.