Skip to content

Commit cdbfd5d

Browse files
committed
refactor: #81 use sdk to create issue
1 parent 2285baf commit cdbfd5d

8 files changed

+31
-136
lines changed

app/Coding/Issue.php

-28
This file was deleted.

app/Commands/IssueCreateCommand.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace App\Commands;
44

5-
use App\Coding\Issue;
5+
use Coding\Issue;
66
use LaravelZero\Framework\Commands\Command;
77

88
class IssueCreateCommand extends Command
@@ -37,8 +37,11 @@ class IssueCreateCommand extends Command
3737
public function handle(Issue $codingIssue): int
3838
{
3939
$this->setCodingApi();
40+
$codingIssue->setToken($this->codingToken);
4041

41-
$data = [];
42+
$data = [
43+
'ProjectName' => $this->codingProjectUri,
44+
];
4245
$data['Type'] = $this->option('type') ?? $this->choice(
4346
'类型:',
4447
['DEFECT', 'REQUIREMENT', 'MISSION', 'EPIC', 'SUB_TASK'],
@@ -52,7 +55,7 @@ public function handle(Issue $codingIssue): int
5255
);
5356

5457
try {
55-
$result = $codingIssue->create($this->codingToken, $this->codingProjectUri, $data);
58+
$result = $codingIssue->create($data);
5659
} catch (\Exception $e) {
5760
$this->error('Error: ' . $e->getMessage());
5861
return 1;

app/Commands/IssueImportCommand.php

+10-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
namespace App\Commands;
44

5-
use App\Coding\Issue;
6-
use App\Coding\Iteration;
5+
use Coding\Issue;
6+
use Coding\Iteration;
77
use App\Coding\ProjectSetting;
88
use Exception;
9-
use Illuminate\Support\Arr;
109
use LaravelZero\Framework\Commands\Command;
1110
use Rap2hpoutre\FastExcel\Facades\FastExcel;
1211

@@ -45,6 +44,8 @@ class IssueImportCommand extends Command
4544
public function handle(Issue $codingIssue, ProjectSetting $projectSetting, Iteration $iteration): int
4645
{
4746
$this->setCodingApi();
47+
$codingIssue->setToken($this->codingToken);
48+
$iteration->setToken($this->codingToken);
4849

4950
$filePath = $this->argument('file');
5051
if (!file_exists($filePath)) {
@@ -105,6 +106,7 @@ private function createIssueByRow(ProjectSetting $projectSetting, Issue $issue,
105106
{
106107
$this->getIssueTypes($projectSetting, $row);
107108
$data = [
109+
'ProjectName' => $this->codingProjectUri,
108110
'Type' => $this->issueTypes[$row['事项类型']]['IssueType'],
109111
'IssueTypeId' => $this->issueTypes[$row['事项类型']]['Id'],
110112
'Name' => $row['标题'],
@@ -133,7 +135,7 @@ private function createIssueByRow(ProjectSetting $projectSetting, Issue $issue,
133135
if (!empty($row['状态'])) {
134136
$data['StatusId'] = $this->getStatusId($projectSetting, $row['事项类型'], $row['状态']);
135137
}
136-
$result = $issue->create($this->codingToken, $this->codingProjectUri, $data);
138+
$result = $issue->create($data);
137139
if (isset($row['ID'])) {
138140
$this->issueCodeMap[$row['ID']] = intval($result['Code']);
139141
}
@@ -143,7 +145,10 @@ private function createIssueByRow(ProjectSetting $projectSetting, Issue $issue,
143145
private function getIterationCode(Iteration $iteration, string $name)
144146
{
145147
if (!isset($this->iterationMap[$name])) {
146-
$result = $iteration->create($this->codingToken, $this->codingProjectUri, ['name' => $name]);
148+
$result = $iteration->create([
149+
'ProjectName' => $this->codingProjectUri,
150+
'Name' => $name,
151+
]);
147152
$this->iterationMap[$name] = $result['Code'];
148153
}
149154
return $this->iterationMap[$name];

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"ext-json": "*",
2323
"ext-libxml": "*",
2424
"ext-zip": "*",
25-
"coding/sdk": "^0.1.2",
25+
"coding/sdk": "^0.2.0",
2626
"illuminate/log": "^8.0",
2727
"laravel-fans/confluence": "^0.1.1",
2828
"laravel-zero/framework": "^8.8",

composer.lock

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Feature/IssueCreateCommandTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Tests\Feature;
44

5-
use App\Coding\Issue;
5+
use Coding\Issue;
66
use Tests\TestCase;
77

88
class IssueCreateCommandTest extends TestCase

tests/Feature/IssueImportCommandTest.php

+6-10
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Tests\Feature;
44

5-
use App\Coding\Issue;
6-
use App\Coding\Iteration;
5+
use Coding\Issue;
6+
use Coding\Iteration;
77
use App\Coding\ProjectSetting;
88
use Tests\TestCase;
99

@@ -109,9 +109,8 @@ public function testImportUserStorySuccess()
109109
)['Response']['Iteration']);
110110

111111
$issueMock->shouldReceive('create')->times(1)->withArgs([
112-
$this->token,
113-
$this->projectUri,
114112
[
113+
'ProjectName' => $this->projectUri,
115114
'Type' => 'REQUIREMENT',
116115
'IssueTypeId' => 213218,
117116
'Name' => '用户可通过手机号注册账户',
@@ -154,9 +153,8 @@ public function testImportSubTask()
154153

155154
$parentIssue = $response;
156155
$issueMock->shouldReceive('create')->times(1)->withArgs([
157-
$this->token,
158-
$this->projectUri,
159156
[
157+
'ProjectName' => $this->projectUri,
160158
'Type' => 'REQUIREMENT',
161159
'IssueTypeId' => 213218,
162160
'Name' => '用户可通过手机号注册账户',
@@ -169,9 +167,8 @@ public function testImportSubTask()
169167
$subTask1 = $response;
170168
$subTask1['Code'] = $this->faker->randomNumber();
171169
$issueMock->shouldReceive('create')->times(1)->withArgs([
172-
$this->token,
173-
$this->projectUri,
174170
[
171+
'ProjectName' => $this->projectUri,
175172
'Type' => 'SUB_TASK',
176173
'IssueTypeId' => 213222,
177174
'Name' => '完成手机号注册的短信验证码发送接口',
@@ -184,9 +181,8 @@ public function testImportSubTask()
184181
$subTask2 = $response;
185182
$subTask2['Code'] = $this->faker->randomNumber();
186183
$issueMock->shouldReceive('create')->times(1)->withArgs([
187-
$this->token,
188-
$this->projectUri,
189184
[
185+
'ProjectName' => $this->projectUri,
190186
'Type' => 'SUB_TASK',
191187
'IssueTypeId' => 213222,
192188
'Name' => '完成通过手机号注册用户的接口',

tests/Unit/CodingIssueTest.php

-81
This file was deleted.

0 commit comments

Comments
 (0)