From a745451a59374151155da2ab5d8a15d89bf434a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20B=C3=A4hr?= Date: Mon, 25 Sep 2023 11:16:18 +0200 Subject: [PATCH] no-task Refactor GitLabClient to handle null start and end dates for Jira sprints. --- src/AiJira/GitLab/GitLabClient.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/AiJira/GitLab/GitLabClient.php b/src/AiJira/GitLab/GitLabClient.php index f230cd6..8702903 100644 --- a/src/AiJira/GitLab/GitLabClient.php +++ b/src/AiJira/GitLab/GitLabClient.php @@ -10,10 +10,17 @@ class GitLabClient { public function getMergeRequestsForJiraSprint(array $jiraSprint): array { - $startDate = new \DateTimeImmutable($jiraSprint['startDate']); - $endDate = new \DateTimeImmutable($jiraSprint['endDate']); - $mergeRequests = []; + + $startDate = $jiraSprint['startDate'] ?? null; + $endDate = $jiraSprint['endDate'] ?? null; + + if (!$startDate || !$endDate) { + return $mergeRequests; + } + + $startDate = new \DateTimeImmutable($startDate); + $endDate = new \DateTimeImmutable($endDate); foreach (explode(',', getenv('AI_GITLAB_PROJECT_IDS')) as $gitlabProjectID) { $mergeRequests = array_merge($mergeRequests, $this->getMergeRequestsByDateRange($gitlabProjectID, $startDate, $endDate)); }