-
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
6 changed files
with
145 additions
and
9 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
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,64 @@ | ||
<?php | ||
|
||
namespace App\Commands; | ||
|
||
use App\Coding\Iteration; | ||
use Carbon\Carbon; | ||
use LaravelZero\Framework\Commands\Command; | ||
|
||
class IterationCreateCommand extends Command | ||
{ | ||
use WithCoding; | ||
|
||
/** | ||
* The signature of the command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'iteration:create | ||
{--start_at= : 开始时间,格式:2021-10-20} | ||
{--end_at= : 结束时间,格式:2021-10-30} | ||
{--name= : 标题} | ||
{--goal= : 目标} | ||
{--assignee= : 处理人 ID} | ||
{--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(Iteration $iteration): int | ||
{ | ||
$this->setCodingApi(); | ||
|
||
$data = []; | ||
$startAt = Carbon::parse($this->option('start_at') ?? $this->ask('开始时间:', Carbon::today()->toDateString())); | ||
$data['StartAt'] = $startAt->toDateString(); | ||
$endAt = Carbon::parse($this->option('end_at') ?? $this->ask( | ||
'结束时间:', | ||
Carbon::today()->addDays(14)->toDateString() | ||
)); | ||
$data['EndAt'] = $endAt->toDateString(); | ||
$data['Name'] = $this->option('name') ?? $this->ask('标题:', Iteration::generateName($startAt, $endAt)); | ||
$data['Goal'] = $this->option('goal'); | ||
$data['Assignee'] = $this->option('assignee'); | ||
|
||
$result = $iteration->create($this->codingToken, $this->codingProjectUri, $data); | ||
|
||
$this->info('创建成功'); | ||
$this->info("https://{$this->codingTeamDomain}.coding.net/p/{$this->codingProjectUri}" . | ||
"/iterations/${result['Code']}/issues"); | ||
|
||
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,48 @@ | ||
<?php | ||
|
||
namespace Tests\Feature; | ||
|
||
use App\Coding\Iteration; | ||
use Carbon\Carbon; | ||
use Tests\TestCase; | ||
|
||
class IterationCreateCommandTest extends TestCase | ||
{ | ||
private string $teamDomain; | ||
private string $projectUri; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$codingToken = $this->faker->md5; | ||
config(['coding.token' => $codingToken]); | ||
$this->teamDomain = $this->faker->domainWord; | ||
config(['coding.team_domain' => $this->teamDomain]); | ||
$this->projectUri = $this->faker->slug; | ||
config(['coding.project_uri' => $this->projectUri]); | ||
} | ||
|
||
public function testCreateSuccess() | ||
{ | ||
$mock = \Mockery::mock(Iteration::class, [])->makePartial(); | ||
$this->instance(Iteration::class, $mock); | ||
|
||
$mock->shouldReceive('create')->times(1)->andReturn(json_decode( | ||
file_get_contents($this->dataDir . 'coding/' . 'CreateIterationResponse.json'), | ||
true | ||
)['Response']['Iteration']); | ||
|
||
$startAt = $this->faker->date(); | ||
$endAt = Carbon::parse($startAt)->addDays($this->faker->randomNumber())->toDateString(); | ||
$this->artisan('iteration:create', [ | ||
'--goal' => $this->faker->text(), | ||
'--assignee' => $this->faker->randomNumber(), | ||
]) | ||
->expectsQuestion('开始时间:', $startAt) | ||
->expectsQuestion('结束时间:', $endAt) | ||
->expectsQuestion('标题:', $startAt . '~' . $endAt . ' 迭代') | ||
->expectsOutput('创建成功') | ||
->expectsOutput("https://$this->teamDomain.coding.net/p/$this->projectUri/iterations/2746/issues") | ||
->assertExitCode(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