-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
2,450 additions
and
684 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
/.vscode | ||
/.vagrant | ||
.phpunit.result.cache | ||
/database/database.sqlite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace App\Commands; | ||
|
||
use App\Coding\Issue; | ||
use App\Coding\Project; | ||
use App\Imports\IssuesImport; | ||
use LaravelZero\Framework\Commands\Command; | ||
use Maatwebsite\Excel\Facades\Excel; | ||
|
||
class IssueImportCommand extends Command | ||
{ | ||
use WithCoding; | ||
|
||
/** | ||
* The signature of the command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'issue:import | ||
{file : 文件(支持格式:csv)} | ||
{--type= : 类型(使用英文),如 DEFECT(缺陷)、REQUIREMENT(需求)、MISSION(任务)、EPIC(史诗)、SUB_TASK(子任务)} | ||
{--coding_token= : CODING 令牌} | ||
{--coding_team_domain= : CODING 团队域名,如 xxx.coding.net 即填写 xxx} | ||
{--coding_project_uri= : CODING 项目标识,如 xxx.coding.net/p/yyy 即填写 yyy} | ||
'; | ||
|
||
/** | ||
* The description of the command. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = '导入事项'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
*/ | ||
public function handle(Issue $codingIssue, Project $codingProject): int | ||
{ | ||
$this->setCodingApi(); | ||
|
||
$filePath = $this->argument('file'); | ||
if (!file_exists($filePath)) { | ||
$this->error("文件不存在:$filePath"); | ||
return 1; | ||
} | ||
|
||
$result = $codingProject->getIssueTypes($this->codingToken, $this->codingProjectUri); | ||
$issueTypes = []; | ||
foreach ($result as $item) { | ||
$issueTypes[$item['Name']] = $item; | ||
} | ||
$rows = Excel::toArray(new IssuesImport(), $filePath)[0]; | ||
foreach ($rows as $row) { | ||
$data = [ | ||
'Type' => $issueTypes[$row['事项类型']]['IssueType'], | ||
'IssueTypeId' => $issueTypes[$row['事项类型']]['Id'], | ||
'Name' => $row['标题'], | ||
'Priority' => \App\Models\Issue::PRIORITY_MAP[$row['优先级']], | ||
]; | ||
try { | ||
$result = $codingIssue->create($this->codingToken, $this->codingProjectUri, $data); | ||
} catch (\Exception $e) { | ||
$this->error('Error: ' . $e->getMessage()); | ||
return 1; | ||
} | ||
$this->info("https://{$this->codingTeamDomain}.coding.net/p/{$this->codingProjectUri}" . | ||
"/all/issues/${result['Code']}"); | ||
} | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace App\Imports; | ||
|
||
use Maatwebsite\Excel\Concerns\WithHeadingRow; | ||
use Maatwebsite\Excel\Imports\HeadingRowFormatter; | ||
|
||
class IssuesImport implements WithHeadingRow | ||
{ | ||
public function __construct() | ||
{ | ||
HeadingRowFormatter::default('none'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Issue extends Model | ||
{ | ||
use HasFactory; | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'type', | ||
'name', | ||
'priority', | ||
]; | ||
|
||
public const PRIORITY_MAP = [ | ||
'低' => '0', | ||
'中' => '1', | ||
'高' => '2', | ||
'紧急' => '3', | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.