Skip to content

Commit

Permalink
refactor: #81 use coding sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkcup committed Oct 24, 2021
1 parent 12be361 commit 2285baf
Show file tree
Hide file tree
Showing 6 changed files with 694 additions and 129 deletions.
21 changes: 0 additions & 21 deletions app/Coding/Iteration.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,9 @@
namespace App\Coding;

use Carbon\Carbon;
use Exception;

class Iteration extends Base
{
public function create($token, $projectName, $data)
{
$response = $this->client->request('POST', 'https://e.coding.net/open-api', [
'headers' => [
'Accept' => 'application/json',
'Authorization' => "token ${token}",
'Content-Type' => 'application/json'
],
'json' => array_merge([
'Action' => 'CreateIteration',
'ProjectName' => $projectName,
], $data),
]);
$result = json_decode($response->getBody(), true);
if (isset($result['Response']['Error']['Message'])) {
throw new Exception($result['Response']['Error']['Message']);
}
return $result['Response']['Iteration'];
}

public static function generateName(Carbon $startAt, Carbon $endAt): string
{
$endFormat = $startAt->year == $endAt->year ? 'm/d' : 'Y/m/d';
Expand Down
12 changes: 8 additions & 4 deletions app/Commands/IterationCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace App\Commands;

use App\Coding\Iteration;
use App\Coding\Iteration as LocalIteration;
use Carbon\Carbon;
use Coding\Iteration;
use LaravelZero\Framework\Commands\Command;

class IterationCreateCommand extends Command
Expand Down Expand Up @@ -40,20 +41,23 @@ class IterationCreateCommand extends Command
public function handle(Iteration $iteration): int
{
$this->setCodingApi();
$iteration->setToken($this->codingToken);

$data = [];
$data = [
'ProjectName' => $this->codingProjectUri,
];
$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['Name'] = $this->option('name') ?? $this->ask('标题:', LocalIteration::generateName($startAt, $endAt));
$data['Goal'] = $this->option('goal');
$data['Assignee'] = $this->option('assignee');

$result = $iteration->create($this->codingToken, $this->codingProjectUri, $data);
$result = $iteration->create($data);

$this->info('创建成功');
$this->info("https://{$this->codingTeamDomain}.coding.net/p/{$this->codingProjectUri}" .
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"ext-json": "*",
"ext-libxml": "*",
"ext-zip": "*",
"coding/sdk": "^0.1.2",
"illuminate/log": "^8.0",
"laravel-fans/confluence": "^0.1.1",
"laravel-zero/framework": "^8.8",
Expand Down
Loading

0 comments on commit 2285baf

Please sign in to comment.