Skip to content

Commit 77d1547

Browse files
committed
feat: #75 get project issue types
1 parent 8e8a092 commit 77d1547

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

Diff for: app/Coding/Project.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace App\Coding;
4+
5+
use Exception;
6+
7+
class Project extends Base
8+
{
9+
public function getIssueTypes($token, $projectName)
10+
{
11+
$response = $this->client->request('POST', 'https://e.coding.net/open-api', [
12+
'headers' => [
13+
'Accept' => 'application/json',
14+
'Authorization' => "token ${token}",
15+
'Content-Type' => 'application/json'
16+
],
17+
'json' => array_merge([
18+
'Action' => 'DescribeProjectIssueTypeList',
19+
'ProjectName' => $projectName,
20+
]),
21+
]);
22+
$result = json_decode($response->getBody(), true);
23+
return $result['Response']['IssueTypes'];
24+
}
25+
}

Diff for: tests/Unit/CodingProjectTest.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Tests\Unit;
4+
5+
use App\Coding\Project;
6+
use GuzzleHttp\Client;
7+
use GuzzleHttp\Psr7\Response;
8+
use Tests\TestCase;
9+
10+
class CodingProjectTest extends TestCase
11+
{
12+
public function testCreateSuccess()
13+
{
14+
$responseBody = file_get_contents($this->dataDir . 'coding/DescribeProjectIssueTypeListResponse.json');
15+
$codingToken = $this->faker->md5;
16+
$codingProjectUri = $this->faker->slug;
17+
18+
$clientMock = $this->getMockBuilder(Client::class)->getMock();
19+
$clientMock->expects($this->once())
20+
->method('request')
21+
->with(
22+
'POST',
23+
'https://e.coding.net/open-api',
24+
[
25+
'headers' => [
26+
'Accept' => 'application/json',
27+
'Authorization' => "token ${codingToken}",
28+
'Content-Type' => 'application/json'
29+
],
30+
'json' => array_merge([
31+
'Action' => 'DescribeProjectIssueTypeList',
32+
'ProjectName' => $codingProjectUri,
33+
])
34+
]
35+
)
36+
->willReturn(new Response(200, [], $responseBody));
37+
$coding = new Project($clientMock);
38+
$result = $coding->getIssueTypes($codingToken, $codingProjectUri);
39+
$this->assertEquals(json_decode($responseBody, true)['Response']['IssueTypes'], $result);
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"Response" : {
3+
"IssueTypes" : [
4+
{
5+
"Description" : "史诗是一个较大的功能或特性,可以分解为多个较小的需求或任务。通常其需要分多次迭代才可完成。",
6+
"Id" : 213217,
7+
"IsSystem" : true,
8+
"IssueType" : "EPIC",
9+
"Name" : "史诗",
10+
"SplitTargetIssueTypeId" : [],
11+
"SplitType" : "UNSPLITTABLE"
12+
},
13+
{
14+
"Description" : "用户故事是敏捷框架中最小的工作单元,是从用户角度描述软件如何为其带来特定的价值。",
15+
"Id" : 213218,
16+
"IsSystem" : true,
17+
"IssueType" : "REQUIREMENT",
18+
"Name" : "用户故事",
19+
"SplitTargetIssueTypeId" : [],
20+
"SplitType" : "ALL_REQUIREMENT"
21+
},
22+
{
23+
"Description" : "任务是指为实现某个目标或需求所进行的具体活动。",
24+
"Id" : 213220,
25+
"IsSystem" : true,
26+
"IssueType" : "MISSION",
27+
"Name" : "任务",
28+
"SplitTargetIssueTypeId" : [],
29+
"SplitType" : "UNSPLITTABLE"
30+
},
31+
{
32+
"Description" : "缺陷是指软件不符合最初定义的业务需求的现象,缺陷管理用于跟踪这些问题和错误。",
33+
"Id" : 213221,
34+
"IsSystem" : true,
35+
"IssueType" : "DEFECT",
36+
"Name" : "缺陷",
37+
"SplitTargetIssueTypeId" : [],
38+
"SplitType" : "UNSPLITTABLE"
39+
},
40+
{
41+
"Description" : "在敏捷模式下,将一个事项拆分成更小的块。",
42+
"Id" : 213222,
43+
"IsSystem" : true,
44+
"IssueType" : "SUB_TASK",
45+
"Name" : "子工作项",
46+
"SplitTargetIssueTypeId" : [],
47+
"SplitType" : "UNSPLITTABLE"
48+
}
49+
],
50+
"RequestId" : "9f7e8405-943d-fb02-96bf-3ee3c63e0fe6"
51+
}
52+
}

0 commit comments

Comments
 (0)