Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5b5375f

Browse files
feat: #72 cli import issues
1 parent 38a4ca4 commit 5b5375f

File tree

11 files changed

+2450
-684
lines changed

11 files changed

+2450
-684
lines changed

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
/.vscode
66
/.vagrant
77
.phpunit.result.cache
8+
/database/database.sqlite

‎app/Commands/IssueImportCommand.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace App\Commands;
4+
5+
use App\Coding\Issue;
6+
use App\Coding\Project;
7+
use App\Imports\IssuesImport;
8+
use LaravelZero\Framework\Commands\Command;
9+
use Maatwebsite\Excel\Facades\Excel;
10+
11+
class IssueImportCommand extends Command
12+
{
13+
use WithCoding;
14+
15+
/**
16+
* The signature of the command.
17+
*
18+
* @var string
19+
*/
20+
protected $signature = 'issue:import
21+
{file : 文件(支持格式:csv)}
22+
{--type= : 类型(使用英文),如 DEFECT(缺陷)、REQUIREMENT(需求)、MISSION(任务)、EPIC(史诗)、SUB_TASK(子任务)}
23+
{--coding_token= : CODING 令牌}
24+
{--coding_team_domain= : CODING 团队域名,如 xxx.coding.net 即填写 xxx}
25+
{--coding_project_uri= : CODING 项目标识,如 xxx.coding.net/p/yyy 即填写 yyy}
26+
';
27+
28+
/**
29+
* The description of the command.
30+
*
31+
* @var string
32+
*/
33+
protected $description = '导入事项';
34+
35+
/**
36+
* Execute the console command.
37+
*
38+
*/
39+
public function handle(Issue $codingIssue, Project $codingProject): int
40+
{
41+
$this->setCodingApi();
42+
43+
$filePath = $this->argument('file');
44+
if (!file_exists($filePath)) {
45+
$this->error("文件不存在:$filePath");
46+
return 1;
47+
}
48+
49+
$result = $codingProject->getIssueTypes($this->codingToken, $this->codingProjectUri);
50+
$issueTypes = [];
51+
foreach ($result as $item) {
52+
$issueTypes[$item['Name']] = $item;
53+
}
54+
$rows = Excel::toArray(new IssuesImport(), $filePath)[0];
55+
foreach ($rows as $row) {
56+
$data = [
57+
'Type' => $issueTypes[$row['事项类型']]['IssueType'],
58+
'IssueTypeId' => $issueTypes[$row['事项类型']]['Id'],
59+
'Name' => $row['标题'],
60+
'Priority' => \App\Models\Issue::PRIORITY_MAP[$row['优先级']],
61+
];
62+
try {
63+
$result = $codingIssue->create($this->codingToken, $this->codingProjectUri, $data);
64+
} catch (\Exception $e) {
65+
$this->error('Error: ' . $e->getMessage());
66+
return 1;
67+
}
68+
$this->info("https://{$this->codingTeamDomain}.coding.net/p/{$this->codingProjectUri}" .
69+
"/all/issues/${result['Code']}");
70+
}
71+
72+
return 0;
73+
}
74+
}

‎app/Imports/IssuesImport.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace App\Imports;
4+
5+
use Maatwebsite\Excel\Concerns\WithHeadingRow;
6+
use Maatwebsite\Excel\Imports\HeadingRowFormatter;
7+
8+
class IssuesImport implements WithHeadingRow
9+
{
10+
public function __construct()
11+
{
12+
HeadingRowFormatter::default('none');
13+
}
14+
}

‎app/Models/Issue.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
8+
class Issue extends Model
9+
{
10+
use HasFactory;
11+
12+
/**
13+
* The attributes that are mass assignable.
14+
*
15+
* @var array
16+
*/
17+
protected $fillable = [
18+
'type',
19+
'name',
20+
'priority',
21+
];
22+
23+
public const PRIORITY_MAP = [
24+
'' => '0',
25+
'' => '1',
26+
'' => '2',
27+
'紧急' => '3',
28+
];
29+
}

‎composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,19 @@
2222
"ext-json": "*",
2323
"ext-libxml": "*",
2424
"ext-zip": "*",
25+
"illuminate/database": "^8.40",
2526
"illuminate/log": "^8.0",
27+
"illuminate/translation": "^8.64",
28+
"illuminate/validation": "^8.64",
2629
"laravel-fans/confluence": "^0.1.1",
2730
"laravel-zero/framework": "^8.8",
2831
"league/html-to-markdown": "^5.0",
32+
"maatwebsite/excel": "^3.1",
2933
"nesbot/carbon": "^2.53",
3034
"sinkcup/laravel-filesystem-cos-updated": "^4.0"
3135
},
3236
"require-dev": {
33-
"fakerphp/faker": "^1.14",
37+
"fakerphp/faker": "^1.9.1",
3438
"mockery/mockery": "^1.4.3",
3539
"phpmd/phpmd": "^2.10",
3640
"phpunit/phpunit": "^9.5",

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /