Skip to content

Commit 3cd11fe

Browse files
tihomirovimishor
authored andcommitted
Merged in tihomiropacic/bitbucket-api (pull request #43)
Implemented the delete branch method
2 parents 8aa84ff + 6d0f9cf commit 3cd11fe

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

docs/examples/repositories/refs/branches.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ $branches->all($account_name, $repo_slug);
2323
$branches->get($account_name, $repo_slug, $branch_name);
2424
```
2525

26+
### Delete an individual branch:
27+
28+
```php
29+
$branches->delete($account_name, $repo_slug, $branch_name);
30+
```
31+
2632
----
2733

2834
#### Related:

lib/Bitbucket/API/Repositories/Refs/Branches.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,22 @@ public function get($account, $repo, $name)
5353
sprintf('repositories/%s/%s/refs/branches/%s', $account, $repo, $name)
5454
);
5555
}
56+
57+
/**
58+
* Deletes an individual branch
59+
*
60+
* @access public
61+
* @param string $account The team or individual account owning the repository.
62+
* @param string $repo The repository identifier.
63+
* @param string $name The branch identifier.
64+
* @return MessageInterface
65+
*
66+
* @throws \InvalidArgumentException
67+
*/
68+
public function delete($account, $repo, $name)
69+
{
70+
return $this->getClient()->setApiVersion('2.0')->delete(
71+
sprintf('repositories/%s/%s/refs/branches/%s', $account, $repo, $name)
72+
);
73+
}
5674
}

test/Bitbucket/Tests/API/Repositories/Refs/BranchesTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,23 @@ public function testGet()
6363

6464
$this->assertEquals($expectedResult, $actual);
6565
}
66+
67+
public function testDelete()
68+
{
69+
$endpoint = 'repositories/gentle/eof/refs/branches/abranch';
70+
$expectedResult = json_encode('dummy');
71+
72+
$client = $this->getHttpClientMock();
73+
$client->expects($this->once())
74+
->method('delete')
75+
->with($endpoint)
76+
->will($this->returnValue($expectedResult));
77+
78+
$repository = $this->getClassMock('Bitbucket\API\Repositories\Refs\Branches', $client);
79+
80+
/** @var $repository \Bitbucket\API\Repositories\Refs\Branches */
81+
$actual = $repository->delete('gentle', 'eof', 'abranch');
82+
83+
$this->assertEquals($expectedResult, $actual);
84+
}
6685
}

0 commit comments

Comments
 (0)