Skip to content

Commit ce14a99

Browse files
committed
feat: #29 get git branches
1 parent c4eda17 commit ce14a99

File tree

4 files changed

+109
-0
lines changed

4 files changed

+109
-0
lines changed

src/GitBranch.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Coding;
4+
5+
use Illuminate\Validation\Rule;
6+
7+
class GitBranch extends Base
8+
{
9+
public function index(array $data)
10+
{
11+
$this->validate($data, [
12+
'DepotId' => 'integer|required',
13+
'PageNumber' => 'integer',
14+
'PageSize' => 'integer',
15+
'KeyWord' => 'string', // 搜索关键字
16+
]);
17+
$data['DepotId'] = intval($data['DepotId']);
18+
$response = $this->core->request('DescribeGitBranches', $data);
19+
return $response['Branches'];
20+
}
21+
}

tests/Acceptance/GitBranchTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Tests\Acceptance;
4+
5+
use Coding\Core;
6+
use Coding\GitBranch;
7+
8+
class GitBranchTest extends TestCase
9+
{
10+
public function testIndex()
11+
{
12+
$data = [
13+
'DepotId' => getenv('CODING_DEPOT_ID'),
14+
];
15+
$branch = new GitBranch($this->token);
16+
$result = $branch->index($data);
17+
$names = [];
18+
foreach ($result as $branch) {
19+
$names[] = $branch['BranchName'];
20+
sort($names);
21+
}
22+
$this->assertEquals(['develop', 'main'], $names);
23+
}
24+
}

tests/Unit/GitBranchTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Tests\Unit;
4+
5+
use Coding\Core;
6+
use Coding\GitBranch;
7+
use Tests\TestCase;
8+
9+
class GitBranchTest extends TestCase
10+
{
11+
public function testIndex()
12+
{
13+
$response = json_decode(
14+
file_get_contents($this->dataPath('DescribeGitBranchesResponse.json')),
15+
true
16+
)['Response'];
17+
$data = [
18+
'DepotId' => $this->faker->randomNumber(),
19+
'PageNumber' => $this->faker->randomNumber(),
20+
'PageSize' => $this->faker->randomNumber(),
21+
'KeyWord' => $this->faker->word(),
22+
];
23+
$this->coreMock->shouldReceive('request')->times(1)->withArgs([
24+
'DescribeGitBranches',
25+
$data
26+
])->andReturn($response);
27+
28+
$branch = new GitBranch($this->token, $this->coreMock);
29+
$result = $branch->index($data);
30+
$this->assertEquals($response['Branches'], $result);
31+
}
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"Response": {
3+
"RequestId": "7c57d93d-e731-6150-8575-b3bf68f11b05",
4+
"TotalCount": 4,
5+
"Branches": [
6+
{
7+
"BranchName": "master",
8+
"IsDefaultBranch": true,
9+
"IsProtected": false,
10+
"Sha": "92811220f02b7c9f1ef5559c74ced479f271c905"
11+
},
12+
{
13+
"BranchName": "branch-1",
14+
"IsDefaultBranch": false,
15+
"IsProtected": false,
16+
"Sha": "92811220f02b7c9f1ef5559c74ced479f271c905"
17+
},
18+
{
19+
"BranchName": "branch-2",
20+
"IsDefaultBranch": false,
21+
"IsProtected": false,
22+
"Sha": "92811220f02b7c9f1ef5559c74ced479f271c905"
23+
},
24+
{
25+
"BranchName": "branch-3",
26+
"IsDefaultBranch": false,
27+
"IsProtected": false,
28+
"Sha": "92811220f02b7c9f1ef5559c74ced479f271c905"
29+
}
30+
]
31+
}
32+
}

0 commit comments

Comments
 (0)