|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * This file is part of the bitbucket-api package. |
| 5 | + * |
| 6 | + * (c) Alexandru G. <alex@gentle.ro> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Bitbucket\API\Repositories; |
| 13 | + |
| 14 | +use Bitbucket\API\Api; |
| 15 | +use Buzz\Message\MessageInterface; |
| 16 | + |
| 17 | +/** |
| 18 | + * Manage the pipelines of a repository |
| 19 | + * |
| 20 | + * @author Marco Veenendaal <marco@deinternetjongens.nl> |
| 21 | + */ |
| 22 | +class Pipelines extends Api |
| 23 | +{ |
| 24 | + /** |
| 25 | + * Get the information associated with a repository's pipelines |
| 26 | + * |
| 27 | + * @access public |
| 28 | + * @param string $account The team or individual account owning the repository. |
| 29 | + * @param string $repo The repository identifier. |
| 30 | + * @return MessageInterface |
| 31 | + */ |
| 32 | + public function all($account, $repo) |
| 33 | + { |
| 34 | + return $this->getClient()->setApiVersion('2.0')->get( |
| 35 | + sprintf('repositories/%s/%s/pipelines/', $account, $repo) |
| 36 | + ); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * Creates a pipeline for the specified repository. |
| 41 | + * |
| 42 | + * @access public |
| 43 | + * @param string $account The team or individual account owning the repository. |
| 44 | + * @param string $repo The repository identifier. |
| 45 | + * @param array|string $params Additional parameters as array or JSON string |
| 46 | + * @return MessageInterface |
| 47 | + */ |
| 48 | + public function create($account, $repo, $params = array()) |
| 49 | + { |
| 50 | + // allow developer to directly specify params as json if (s)he wants. |
| 51 | + if ('array' !== gettype($params)) { |
| 52 | + if (empty($params)) { |
| 53 | + throw new \InvalidArgumentException('Invalid JSON provided.'); |
| 54 | + } |
| 55 | + |
| 56 | + $params = $this->decodeJSON($params); |
| 57 | + } |
| 58 | + |
| 59 | + return $this->getClient()->setApiVersion('2.0')->post( |
| 60 | + sprintf('repositories/%s/%s/pipelines/', $account, $repo), |
| 61 | + json_encode($params), |
| 62 | + array('Content-Type' => 'application/json') |
| 63 | + ); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Get a specific pipeline |
| 68 | + * |
| 69 | + * @access public |
| 70 | + * @param string $account The team or individual account owning the repository. |
| 71 | + * @param string $repo The repository identifier. |
| 72 | + * @param string $uuid The pipeline's identifier. |
| 73 | + * @return MessageInterface |
| 74 | + */ |
| 75 | + public function get($account, $repo, $uuid) |
| 76 | + { |
| 77 | + return $this->getClient()->setApiVersion('2.0')->get( |
| 78 | + sprintf('repositories/%s/%s/pipelines/%s', $account, $repo, $uuid) |
| 79 | + ); |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * Stop a specific pipeline |
| 84 | + * |
| 85 | + * @access public |
| 86 | + * @param string $account The team or individual account owning the repository. |
| 87 | + * @param string $repo The repository identifier. |
| 88 | + * @param string $uuid The pipeline's identifier. |
| 89 | + * @return MessageInterface |
| 90 | + */ |
| 91 | + public function stopPipeline($account, $repo, $uuid) |
| 92 | + { |
| 93 | + return $this->getClient()->setApiVersion('2.0')->post( |
| 94 | + sprintf('repositories/%s/%s/pipelines/%s/stopPipeline', $account, $repo, $uuid) |
| 95 | + ); |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * Get steps |
| 100 | + * |
| 101 | + * @access public |
| 102 | + * @return Pipelines\Steps |
| 103 | + * |
| 104 | + * @throws \InvalidArgumentException |
| 105 | + * @codeCoverageIgnore |
| 106 | + */ |
| 107 | + public function steps() |
| 108 | + { |
| 109 | + return $this->api('Repositories\\Pipelines\\Steps'); |
| 110 | + } |
| 111 | +} |
0 commit comments