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 8e8a092

Browse files
feat: #73 cli create issue
1 parent 2c1373a commit 8e8a092

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed

‎app/Commands/IssueCreateCommand.php‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace App\Commands;
4+
5+
use App\Coding\Issue;
6+
use LaravelZero\Framework\Commands\Command;
7+
8+
class IssueCreateCommand extends Command
9+
{
10+
use WithCoding;
11+
12+
/**
13+
* The signature of the command.
14+
*
15+
* @var string
16+
*/
17+
protected $signature = 'issue:create
18+
{--type= : 类型(使用英文),如 DEFECT(缺陷)、REQUIREMENT(需求)、MISSION(任务)、EPIC(史诗)、SUB_TASK(子任务)}
19+
{--name= : 标题}
20+
{--priority=2 : 优先级,0(低), 1(中), 2(高), 3(紧急)}
21+
{--coding_token= : CODING 令牌}
22+
{--coding_team_domain= : CODING 团队域名,如 xxx.coding.net 即填写 xxx}
23+
{--coding_project_uri= : CODING 项目标识,如 xxx.coding.net/p/yyy 即填写 yyy}
24+
';
25+
26+
/**
27+
* The description of the command.
28+
*
29+
* @var string
30+
*/
31+
protected $description = '创建事项';
32+
33+
/**
34+
* Execute the console command.
35+
*
36+
*/
37+
public function handle(Issue $codingIssue): int
38+
{
39+
$this->setCodingApi();
40+
41+
$data = [];
42+
$data['Type'] = $this->option('type') ?? $this->choice(
43+
'类型:',
44+
['DEFECT', 'REQUIREMENT', 'MISSION', 'EPIC', 'SUB_TASK'],
45+
0
46+
);
47+
$data['Name'] = $this->option('name') ?? $this->ask('标题:');
48+
$data['Priority'] = $this->option('priority') ?? $this->choice(
49+
'优先级:',
50+
['0', '1', '2', '3'],
51+
0
52+
);
53+
54+
try {
55+
$result = $codingIssue->create($this->codingToken, $this->codingProjectUri, $data);
56+
} catch (\Exception $e) {
57+
$this->error('Error: ' . $e->getMessage());
58+
return 1;
59+
}
60+
61+
$this->info('创建成功');
62+
$this->info("https://{$this->codingTeamDomain}.coding.net/p/{$this->codingProjectUri}" .
63+
"/all/issues/${result['Code']}");
64+
65+
return 0;
66+
}
67+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace Tests\Feature;
4+
5+
use App\Coding\Issue;
6+
use Tests\TestCase;
7+
8+
class IssueCreateCommandTest extends TestCase
9+
{
10+
private string $codingToken;
11+
private string $codingTeamDomain;
12+
private string $codingProjectUri;
13+
14+
protected function setUp(): void
15+
{
16+
parent::setUp();
17+
$this->codingToken = $this->faker->md5;
18+
config(['coding.token' => $this->codingToken]);
19+
$this->codingTeamDomain = $this->faker->domainWord;
20+
config(['coding.team_domain' => $this->codingTeamDomain]);
21+
$this->codingProjectUri = $this->faker->slug;
22+
config(['coding.project_uri' => $this->codingProjectUri]);
23+
}
24+
25+
public function testCreateSuccess()
26+
{
27+
$mock = \Mockery::mock(Issue::class, [])->makePartial();
28+
$this->instance(Issue::class, $mock);
29+
30+
$mock->shouldReceive('create')->times(1)->andReturn(json_decode(
31+
file_get_contents($this->dataDir . 'coding/' . 'CreateIssueResponse.json'),
32+
true
33+
)['Response']['Issue']);
34+
35+
$this->artisan('issue:create')
36+
->expectsQuestion('类型:', 'REQUIREMENT')
37+
->expectsQuestion('标题:', $this->faker->title)
38+
->expectsOutput('创建成功')
39+
->expectsOutput("https://$this->codingTeamDomain.coding.net/p/$this->codingProjectUri/all/issues/2742")
40+
->assertExitCode(0);
41+
}
42+
43+
public function testCreateFailed()
44+
{
45+
$mock = \Mockery::mock(Issue::class, [])->makePartial();
46+
$this->instance(Issue::class, $mock);
47+
48+
$mock->shouldReceive('create')->times(1)->andThrow(\Exception::class, json_decode(
49+
file_get_contents($this->dataDir . 'coding/' . 'CreateIssueFailedResponse.json'),
50+
true
51+
)['Response']['Error']['Message']);
52+
53+
$this->artisan('issue:create')
54+
->expectsQuestion('类型:', 'REQUIREMENT')
55+
->expectsQuestion('标题:', $this->faker->title)
56+
->expectsOutput('Error: issue_custom_field_required')
57+
->assertExitCode(1);
58+
}
59+
}

0 commit comments

Comments
(0)

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