Skip to content

Commit 04d57fa

Browse files
committed
feat: #73 coding sdk create issue
1 parent d28398b commit 04d57fa

File tree

3 files changed

+192
-0
lines changed

3 files changed

+192
-0
lines changed

Diff for: app/Coding/Issue.php

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

Diff for: tests/Unit/CodingIssueTest.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Tests\Unit;
4+
5+
use App\Coding\Issue;
6+
use GuzzleHttp\Client;
7+
use GuzzleHttp\Psr7\Response;
8+
use Tests\TestCase;
9+
10+
class CodingIssueTest extends TestCase
11+
{
12+
public function testCreate()
13+
{
14+
$responseBody = file_get_contents($this->dataDir . 'coding/CreateIssueResponse.json');
15+
$codingToken = $this->faker->md5;
16+
$codingProjectUri = $this->faker->slug;
17+
$data = [
18+
'Type' => 'REQUIREMENT',
19+
'Name' => $this->faker->title,
20+
'Priority' => $this->faker->randomElement([0, 1, 2, 3]),
21+
];
22+
23+
$clientMock = $this->getMockBuilder(Client::class)->getMock();
24+
$clientMock->expects($this->once())
25+
->method('request')
26+
->with(
27+
'POST',
28+
'https://e.coding.net/open-api',
29+
[
30+
'headers' => [
31+
'Accept' => 'application/json',
32+
'Authorization' => "token ${codingToken}",
33+
'Content-Type' => 'application/json'
34+
],
35+
'json' => array_merge([
36+
'Action' => 'CreateIssue',
37+
'ProjectName' => $codingProjectUri,
38+
], $data)
39+
]
40+
)
41+
->willReturn(new Response(200, [], $responseBody));
42+
$coding = new Issue($clientMock);
43+
$result = $coding->create($codingToken, $codingProjectUri, $data);
44+
$this->assertEquals(json_decode($responseBody, true)['Response']['Issue'], $result);
45+
}
46+
}

Diff for: tests/data/coding/CreateIssueResponse.json

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
{
2+
"Response" : {
3+
"Issue" : {
4+
"Assignee" : {
5+
"Avatar" : "",
6+
"Email" : "",
7+
"GlobalKey" : "",
8+
"Id" : 0,
9+
"Name" : "",
10+
"Phone" : "",
11+
"Status" : 0,
12+
"TeamGlobalKey" : "",
13+
"TeamId" : 0
14+
},
15+
"Code" : 2742,
16+
"CompletedAt" : 0,
17+
"CreatedAt" : 1634541907501,
18+
"Creator" : {
19+
"Avatar" : "https://coding-net-production-static-ci.codehub.cn/2cb665a3-bebc-4b09-aa00-2b6df3e33edc.jpg?imageMogr2/auto-orient/format/jpeg/cut/400x400x0x0",
20+
"Email" : "",
21+
"GlobalKey" : "",
22+
"Id" : 183478,
23+
"Name" : "sinkcup",
24+
"Phone" : "",
25+
"Status" : 1,
26+
"TeamGlobalKey" : "",
27+
"TeamId" : 0
28+
},
29+
"CustomFields" : [],
30+
"DefectType" : {
31+
"IconUrl" : "",
32+
"Id" : 0,
33+
"Name" : ""
34+
},
35+
"Description" : "",
36+
"DueDate" : 0,
37+
"Epic" : {
38+
"Assignee" : {
39+
"Avatar" : "",
40+
"Email" : "",
41+
"GlobalKey" : "",
42+
"Id" : 0,
43+
"Name" : "",
44+
"Phone" : "",
45+
"Status" : 0,
46+
"TeamGlobalKey" : "",
47+
"TeamId" : 0
48+
},
49+
"Code" : 0,
50+
"IssueStatusId" : 0,
51+
"IssueStatusName" : "",
52+
"Name" : "",
53+
"Priority" : "",
54+
"Type" : ""
55+
},
56+
"Files" : [],
57+
"IssueStatusId" : 1227034,
58+
"IssueStatusName" : "未开始",
59+
"IssueStatusType" : "TODO",
60+
"IssueTypeDetail" : {
61+
"Description" : "需求是指用户解决某一个问题或达到某一目标所需的软件功能。",
62+
"Id" : 213219,
63+
"IsSystem" : true,
64+
"IssueType" : "REQUIREMENT",
65+
"Name" : "需求"
66+
},
67+
"IssueTypeId" : 213219,
68+
"Iteration" : {
69+
"Code" : 0,
70+
"Name" : "",
71+
"Status" : ""
72+
},
73+
"IterationId" : 0,
74+
"Labels" : [],
75+
"Name" : "issue by curl",
76+
"Parent" : {
77+
"Assignee" : {
78+
"Avatar" : "",
79+
"Email" : "",
80+
"GlobalKey" : "",
81+
"Id" : 0,
82+
"Name" : "",
83+
"Phone" : "",
84+
"Status" : 0,
85+
"TeamGlobalKey" : "",
86+
"TeamId" : 0
87+
},
88+
"Code" : 0,
89+
"IssueStatusId" : 0,
90+
"IssueStatusName" : "",
91+
"IssueStatusType" : "",
92+
"IssueTypeDetail" : {
93+
"Description" : "",
94+
"Id" : 0,
95+
"IsSystem" : false,
96+
"IssueType" : "",
97+
"Name" : ""
98+
},
99+
"Name" : "",
100+
"Priority" : "",
101+
"Type" : ""
102+
},
103+
"ParentType" : "REQUIREMENT",
104+
"Priority" : "0",
105+
"ProjectModule" : {
106+
"Id" : 0,
107+
"Name" : ""
108+
},
109+
"RequirementType" : {
110+
"Id" : 0,
111+
"Name" : ""
112+
},
113+
"StartDate" : 0,
114+
"StoryPoint" : "",
115+
"SubTasks" : [],
116+
"ThirdLinks" : [],
117+
"Type" : "REQUIREMENT",
118+
"UpdatedAt" : 1634541907501,
119+
"Watchers" : [],
120+
"WorkingHours" : 0
121+
},
122+
"RequestId" : "5b7bae01-f26f-16d7-0d61-c8fa67ea0472"
123+
}
124+
}

0 commit comments

Comments
 (0)