Skip to content

Commit

Permalink
refactor: #81 use sdk to create issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkcup committed Oct 25, 2021
1 parent 2285baf commit 0e20b8c
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 136 deletions.
28 changes: 0 additions & 28 deletions app/Coding/Issue.php

This file was deleted.

9 changes: 6 additions & 3 deletions app/Commands/IssueCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Commands;

use App\Coding\Issue;
use Coding\Issue;
use LaravelZero\Framework\Commands\Command;

class IssueCreateCommand extends Command
Expand Down Expand Up @@ -37,8 +37,11 @@ class IssueCreateCommand extends Command
public function handle(Issue $codingIssue): int
{
$this->setCodingApi();
$codingIssue->setToken($this->codingToken);

$data = [];
$data = [
'ProjectName' => $this->codingProjectUri,
];
$data['Type'] = $this->option('type') ?? $this->choice(
'类型:',
['DEFECT', 'REQUIREMENT', 'MISSION', 'EPIC', 'SUB_TASK'],
Expand All @@ -52,7 +55,7 @@ public function handle(Issue $codingIssue): int
);

try {
$result = $codingIssue->create($this->codingToken, $this->codingProjectUri, $data);
$result = $codingIssue->create($data);
} catch (\Exception $e) {
$this->error('Error: ' . $e->getMessage());
return 1;
Expand Down
15 changes: 10 additions & 5 deletions app/Commands/IssueImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

namespace App\Commands;

use App\Coding\Issue;
use App\Coding\Iteration;
use Coding\Issue;
use 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 @@ -45,6 +44,8 @@ class IssueImportCommand extends Command
public function handle(Issue $codingIssue, ProjectSetting $projectSetting, Iteration $iteration): int
{
$this->setCodingApi();
$codingIssue->setToken($this->codingToken);
$iteration->setToken($this->codingToken);

$filePath = $this->argument('file');
if (!file_exists($filePath)) {
Expand Down Expand Up @@ -105,6 +106,7 @@ private function createIssueByRow(ProjectSetting $projectSetting, Issue $issue,
{
$this->getIssueTypes($projectSetting, $row);
$data = [
'ProjectName' => $this->codingProjectUri,
'Type' => $this->issueTypes[$row['事项类型']]['IssueType'],
'IssueTypeId' => $this->issueTypes[$row['事项类型']]['Id'],
'Name' => $row['标题'],
Expand Down Expand Up @@ -133,7 +135,7 @@ private function createIssueByRow(ProjectSetting $projectSetting, Issue $issue,
if (!empty($row['状态'])) {
$data['StatusId'] = $this->getStatusId($projectSetting, $row['事项类型'], $row['状态']);
}
$result = $issue->create($this->codingToken, $this->codingProjectUri, $data);
$result = $issue->create($data);
if (isset($row['ID'])) {
$this->issueCodeMap[$row['ID']] = intval($result['Code']);
}
Expand All @@ -143,7 +145,10 @@ private function createIssueByRow(ProjectSetting $projectSetting, Issue $issue,
private function getIterationCode(Iteration $iteration, string $name)
{
if (!isset($this->iterationMap[$name])) {
$result = $iteration->create($this->codingToken, $this->codingProjectUri, ['name' => $name]);
$result = $iteration->create([
'ProjectName' => $this->codingProjectUri,
'Name' => $name,
]);
$this->iterationMap[$name] = $result['Code'];
}
return $this->iterationMap[$name];
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"ext-json": "*",
"ext-libxml": "*",
"ext-zip": "*",
"coding/sdk": "^0.1.2",
"coding/sdk": "^0.2.0",
"illuminate/log": "^8.0",
"laravel-fans/confluence": "^0.1.1",
"laravel-zero/framework": "^8.8",
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/Feature/IssueCreateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Tests\Feature;

use App\Coding\Issue;
use Coding\Issue;
use Tests\TestCase;

class IssueCreateCommandTest extends TestCase
Expand Down
16 changes: 6 additions & 10 deletions tests/Feature/IssueImportCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Tests\Feature;

use App\Coding\Issue;
use App\Coding\Iteration;
use Coding\Issue;
use Coding\Iteration;
use App\Coding\ProjectSetting;
use Tests\TestCase;

Expand Down Expand Up @@ -109,9 +109,8 @@ public function testImportUserStorySuccess()
)['Response']['Iteration']);

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

$parentIssue = $response;
$issueMock->shouldReceive('create')->times(1)->withArgs([
$this->token,
$this->projectUri,
[
'ProjectName' => $this->projectUri,
'Type' => 'REQUIREMENT',
'IssueTypeId' => 213218,
'Name' => '用户可通过手机号注册账户',
Expand All @@ -169,9 +167,8 @@ public function testImportSubTask()
$subTask1 = $response;
$subTask1['Code'] = $this->faker->randomNumber();
$issueMock->shouldReceive('create')->times(1)->withArgs([
$this->token,
$this->projectUri,
[
'ProjectName' => $this->projectUri,
'Type' => 'SUB_TASK',
'IssueTypeId' => 213222,
'Name' => '完成手机号注册的短信验证码发送接口',
Expand All @@ -184,9 +181,8 @@ public function testImportSubTask()
$subTask2 = $response;
$subTask2['Code'] = $this->faker->randomNumber();
$issueMock->shouldReceive('create')->times(1)->withArgs([
$this->token,
$this->projectUri,
[
'ProjectName' => $this->projectUri,
'Type' => 'SUB_TASK',
'IssueTypeId' => 213222,
'Name' => '完成通过手机号注册用户的接口',
Expand Down
81 changes: 0 additions & 81 deletions tests/Unit/CodingIssueTest.php

This file was deleted.

0 comments on commit 0e20b8c

Please sign in to comment.