From ac38550e5e0d952058b764852f5aaf3cf2374be8 Mon Sep 17 00:00:00 2001 From: sinkcup Date: Fri, 22 Oct 2021 12:53:10 +0800 Subject: [PATCH] feat: #72 import issue type status --- app/Commands/IssueImportCommand.php | 21 +++++++++- tests/Feature/IssueImportCommandTest.php | 50 +++++++++++++++++++----- 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/app/Commands/IssueImportCommand.php b/app/Commands/IssueImportCommand.php index 5049e0a..522692b 100644 --- a/app/Commands/IssueImportCommand.php +++ b/app/Commands/IssueImportCommand.php @@ -6,6 +6,7 @@ use App\Coding\Iteration; use App\Coding\ProjectSetting; use Exception; +use Illuminate\Support\Arr; use LaravelZero\Framework\Commands\Command; use Rap2hpoutre\FastExcel\Facades\FastExcel; @@ -33,9 +34,10 @@ class IssueImportCommand extends Command */ protected $description = '导入事项'; - protected array $iterationMap = []; - protected array $issueTypes = []; protected array $issueCodeMap = []; + protected array $issueTypes = []; + protected array $issueTypeStatus = []; + protected array $iterationMap = []; /** * Execute the console command. @@ -83,6 +85,18 @@ private function getIssueTypes(ProjectSetting $projectSetting, array $row): void } } + private function getStatusId(ProjectSetting $projectSetting, string $issueType, string $statusChinese): int + { + if (!isset($this->issueTypeStatus[$issueType])) { + $result = $projectSetting->getIssueTypeStatus($this->codingToken, $this->codingProjectUri, $issueType); + foreach ($result as $item) { + $tmp = $item['IssueStatus']; + $this->issueTypeStatus[$issueType][$tmp['Name']] = $tmp['Id']; + } + } + return intval($this->issueTypeStatus[$issueType][$statusChinese]); + } + private function createIssueByRow(ProjectSetting $projectSetting, Issue $issue, Iteration $iteration, array $row) { $this->getIssueTypes($projectSetting, $row); @@ -112,6 +126,9 @@ private function createIssueByRow(ProjectSetting $projectSetting, Issue $issue, $data[$english] = $row[$chinese]; } } + if (!empty($row['状态'])) { + $data['StatusId'] = $this->getStatusId($projectSetting, $data['Type'], $row['状态']); + } $result = $issue->create($this->codingToken, $this->codingProjectUri, $data); if (isset($row['ID'])) { $this->issueCodeMap[$row['ID']] = intval($result['Code']); diff --git a/tests/Feature/IssueImportCommandTest.php b/tests/Feature/IssueImportCommandTest.php index 7d7d501..6dccc71 100755 --- a/tests/Feature/IssueImportCommandTest.php +++ b/tests/Feature/IssueImportCommandTest.php @@ -26,13 +26,33 @@ protected function setUp(): void public function testImportSuccess() { - $mock = \Mockery::mock(ProjectSetting::class, [])->makePartial(); - $this->instance(ProjectSetting::class, $mock); + $projectSettingMock = \Mockery::mock(ProjectSetting::class, [])->makePartial(); + $this->instance(ProjectSetting::class, $projectSettingMock); - $mock->shouldReceive('getIssueTypes')->times(1)->andReturn(json_decode( + $projectSettingMock->shouldReceive('getIssueTypes')->times(1)->andReturn(json_decode( file_get_contents($this->dataDir . 'coding/' . 'DescribeProjectIssueTypeListResponse.json'), true )['Response']['IssueTypes']); + $requirementStatus = json_decode( + file_get_contents($this->dataDir . 'coding/' . 'DescribeProjectIssueStatusListResponse.json'), + true + )['Response']['ProjectIssueStatusList']; + $projectSettingMock->shouldReceive('getIssueTypeStatus')->times(5)->andReturn( + $requirementStatus, + $requirementStatus, + [ + ['IssueStatus' => ['Id' => 11, 'Name' => '已完成']], + ['IssueStatus' => ['Id' => 12, 'Name' => '处理中']], + ], + [ + ['IssueStatus' => ['Id' => 11, 'Name' => '未开始']], + ['IssueStatus' => ['Id' => 12, 'Name' => '处理中']], + ], + [ + ['IssueStatus' => ['Id' => 22, 'Name' => '处理中']], + ['IssueStatus' => ['Id' => 23, 'Name' => '待处理']], + ] + ); $issueMock = \Mockery::mock(Issue::class, [])->makePartial(); $this->instance(Issue::class, $issueMock); @@ -66,13 +86,17 @@ public function testImportSuccess() public function testImportUserStorySuccess() { - $mock = \Mockery::mock(ProjectSetting::class, [])->makePartial(); - $this->instance(ProjectSetting::class, $mock); + $projectSettingMock = \Mockery::mock(ProjectSetting::class, [])->makePartial(); + $this->instance(ProjectSetting::class, $projectSettingMock); - $mock->shouldReceive('getIssueTypes')->times(1)->andReturn(json_decode( + $projectSettingMock->shouldReceive('getIssueTypes')->times(1)->andReturn(json_decode( file_get_contents($this->dataDir . 'coding/' . 'DescribeProjectIssueTypeListResponse.json'), true )['Response']['IssueTypes']); + $projectSettingMock->shouldReceive('getIssueTypeStatus')->times(1)->andReturn(json_decode( + file_get_contents($this->dataDir . 'coding/' . 'DescribeProjectIssueStatusListResponse.json'), + true + )['Response']['ProjectIssueStatusList']); $issueMock = \Mockery::mock(Issue::class, [])->makePartial(); $this->instance(Issue::class, $issueMock); @@ -101,6 +125,7 @@ public function testImportUserStorySuccess() 'IterationCode' => 2746, 'DueDate' => '2021-10-21', 'StoryPoint' => '2', + 'StatusId' => 9, ] ])->andReturn($result); @@ -113,13 +138,17 @@ public function testImportUserStorySuccess() public function testImportSubTask() { - $mock = \Mockery::mock(ProjectSetting::class, [])->makePartial(); - $this->instance(ProjectSetting::class, $mock); + $projectSettingMock = \Mockery::mock(ProjectSetting::class, [])->makePartial(); + $this->instance(ProjectSetting::class, $projectSettingMock); - $mock->shouldReceive('getIssueTypes')->times(1)->andReturn(json_decode( + $projectSettingMock->shouldReceive('getIssueTypes')->times(1)->andReturn(json_decode( file_get_contents($this->dataDir . 'coding/' . 'DescribeProjectIssueTypeListResponse.json'), true )['Response']['IssueTypes']); + $projectSettingMock->shouldReceive('getIssueTypeStatus')->times(2)->andReturn(json_decode( + file_get_contents($this->dataDir . 'coding/' . 'DescribeProjectIssueStatusListResponse.json'), + true + )['Response']['ProjectIssueStatusList']); $issueMock = \Mockery::mock(Issue::class, [])->makePartial(); $this->instance(Issue::class, $issueMock); @@ -139,6 +168,7 @@ public function testImportSubTask() 'Name' => '用户可通过手机号注册账户', 'DueDate' => '2021-10-21', 'StoryPoint' => '2', + 'StatusId' => 9, ] ])->andReturn($parentIssue); @@ -153,6 +183,7 @@ public function testImportSubTask() 'Name' => '完成手机号注册的短信验证码发送接口', 'Priority' => "0", 'ParentCode' => 2742, + 'StatusId' => 13, ] ])->andReturn($subTask1); @@ -167,6 +198,7 @@ public function testImportSubTask() 'Name' => '完成通过手机号注册用户的接口', 'Priority' => "1", 'ParentCode' => 2742, + 'StatusId' => 13, ] ])->andReturn($subTask2);