Skip to content

Commit d6ebad4

Browse files
committed
refactor: #81 use coding sdk
1 parent 12be361 commit d6ebad4

File tree

6 files changed

+694
-129
lines changed

6 files changed

+694
-129
lines changed

Diff for: app/Coding/Iteration.php

-21
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,9 @@
33
namespace App\Coding;
44

55
use Carbon\Carbon;
6-
use Exception;
76

87
class Iteration extends Base
98
{
10-
public function create($token, $projectName, $data)
11-
{
12-
$response = $this->client->request('POST', 'https://e.coding.net/open-api', [
13-
'headers' => [
14-
'Accept' => 'application/json',
15-
'Authorization' => "token ${token}",
16-
'Content-Type' => 'application/json'
17-
],
18-
'json' => array_merge([
19-
'Action' => 'CreateIteration',
20-
'ProjectName' => $projectName,
21-
], $data),
22-
]);
23-
$result = json_decode($response->getBody(), true);
24-
if (isset($result['Response']['Error']['Message'])) {
25-
throw new Exception($result['Response']['Error']['Message']);
26-
}
27-
return $result['Response']['Iteration'];
28-
}
29-
309
public static function generateName(Carbon $startAt, Carbon $endAt): string
3110
{
3211
$endFormat = $startAt->year == $endAt->year ? 'm/d' : 'Y/m/d';

Diff for: app/Commands/IterationCreateCommand.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
namespace App\Commands;
44

5-
use App\Coding\Iteration;
5+
use App\Coding\Iteration as LocalIteration;
66
use Carbon\Carbon;
7+
use Coding\Iteration;
78
use LaravelZero\Framework\Commands\Command;
89

910
class IterationCreateCommand extends Command
@@ -40,20 +41,23 @@ class IterationCreateCommand extends Command
4041
public function handle(Iteration $iteration): int
4142
{
4243
$this->setCodingApi();
44+
$iteration->setToken($this->codingToken);
4345

44-
$data = [];
46+
$data = [
47+
'ProjectName' => $this->codingProjectUri,
48+
];
4549
$startAt = Carbon::parse($this->option('start_at') ?? $this->ask('开始时间:', Carbon::today()->toDateString()));
4650
$data['StartAt'] = $startAt->toDateString();
4751
$endAt = Carbon::parse($this->option('end_at') ?? $this->ask(
4852
'结束时间:',
4953
Carbon::today()->addDays(14)->toDateString()
5054
));
5155
$data['EndAt'] = $endAt->toDateString();
52-
$data['Name'] = $this->option('name') ?? $this->ask('标题:', Iteration::generateName($startAt, $endAt));
56+
$data['Name'] = $this->option('name') ?? $this->ask('标题:', LocalIteration::generateName($startAt, $endAt));
5357
$data['Goal'] = $this->option('goal');
5458
$data['Assignee'] = $this->option('assignee');
5559

56-
$result = $iteration->create($this->codingToken, $this->codingProjectUri, $data);
60+
$result = $iteration->create($data);
5761

5862
$this->info('创建成功');
5963
$this->info("https://{$this->codingTeamDomain}.coding.net/p/{$this->codingProjectUri}" .

Diff for: composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"ext-json": "*",
2323
"ext-libxml": "*",
2424
"ext-zip": "*",
25+
"coding/sdk": "^0.1.2",
2526
"illuminate/log": "^8.0",
2627
"laravel-fans/confluence": "^0.1.1",
2728
"laravel-zero/framework": "^8.8",

0 commit comments

Comments
 (0)