Skip to content

Commit

Permalink
feat: #72 import issue type status
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkcup committed Oct 22, 2021
1 parent 5c6734f commit ac38550
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 11 deletions.
21 changes: 19 additions & 2 deletions app/Commands/IssueImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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']);
Expand Down
50 changes: 41 additions & 9 deletions tests/Feature/IssueImportCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -101,6 +125,7 @@ public function testImportUserStorySuccess()
'IterationCode' => 2746,
'DueDate' => '2021-10-21',
'StoryPoint' => '2',
'StatusId' => 9,
]
])->andReturn($result);

Expand All @@ -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);
Expand All @@ -139,6 +168,7 @@ public function testImportSubTask()
'Name' => '用户可通过手机号注册账户',
'DueDate' => '2021-10-21',
'StoryPoint' => '2',
'StatusId' => 9,
]
])->andReturn($parentIssue);

Expand All @@ -153,6 +183,7 @@ public function testImportSubTask()
'Name' => '完成手机号注册的短信验证码发送接口',
'Priority' => "0",
'ParentCode' => 2742,
'StatusId' => 13,
]
])->andReturn($subTask1);

Expand All @@ -167,6 +198,7 @@ public function testImportSubTask()
'Name' => '完成通过手机号注册用户的接口',
'Priority' => "1",
'ParentCode' => 2742,
'StatusId' => 13,
]
])->andReturn($subTask2);

Expand Down

0 comments on commit ac38550

Please sign in to comment.