#add git monitor
This commit is contained in:
@@ -5,12 +5,14 @@ namespace App\Services;
|
||||
use JiraRestApi\Configuration\ArrayConfiguration;
|
||||
use JiraRestApi\Issue\IssueService;
|
||||
use JiraRestApi\JiraException;
|
||||
use JiraRestApi\Project\ProjectService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class JiraService
|
||||
{
|
||||
private IssueService $issueService;
|
||||
private ProjectService $projectService;
|
||||
private array $config;
|
||||
|
||||
public function __construct()
|
||||
@@ -19,9 +21,12 @@ class JiraService
|
||||
$this->initializeJiraClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws JiraException
|
||||
*/
|
||||
private function initializeJiraClient(): void
|
||||
{
|
||||
$jiraConfig = new ArrayConfiguration([
|
||||
$clientConfig = new ArrayConfiguration([
|
||||
'jiraHost' => $this->config['host'],
|
||||
'jiraUser' => $this->config['username'],
|
||||
'jiraPassword' => $this->config['auth_type'] === 'token'
|
||||
@@ -30,7 +35,8 @@ class JiraService
|
||||
'timeout' => $this->config['timeout'],
|
||||
]);
|
||||
|
||||
$this->issueService = new IssueService($jiraConfig);
|
||||
$this->issueService = new IssueService($clientConfig);
|
||||
$this->projectService = new ProjectService($clientConfig);
|
||||
}
|
||||
|
||||
|
||||
@@ -738,5 +744,47 @@ class JiraService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最近的 release 版本
|
||||
*/
|
||||
public function getUpcomingReleaseVersion(string $projectKey): ?array
|
||||
{
|
||||
try {
|
||||
$versions = $this->projectService->getVersions($projectKey);
|
||||
} catch (JiraException $e) {
|
||||
throw new \RuntimeException('获取 release 版本失败: ' . $e->getMessage(), previous: $e);
|
||||
}
|
||||
|
||||
if (empty($versions)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$now = Carbon::now()->startOfDay();
|
||||
|
||||
$candidate = collect($versions)
|
||||
->filter(function ($version) use ($now) {
|
||||
if (($version->released ?? false) || empty($version->releaseDate)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
return Carbon::parse($version->releaseDate)->greaterThanOrEqualTo($now);
|
||||
} catch (\Throwable) {
|
||||
return false;
|
||||
}
|
||||
})
|
||||
->sortBy(function ($version) {
|
||||
return Carbon::parse($version->releaseDate);
|
||||
})
|
||||
->first();
|
||||
|
||||
if (!$candidate) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'version' => $candidate->name,
|
||||
'release_date' => Carbon::parse($candidate->releaseDate)->toDateString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user