-
Notifications
You must be signed in to change notification settings - Fork 6
feat(gitlab): add getPullRequest, getPullRequestFiles, getPullRequestFromBranch, createComment, getComment, updateComment and getUser #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
76df5e7
d56ec3b
8a688e8
e86e659
7fb6a4b
4374e22
c6f5ac4
3076066
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -465,22 +465,85 @@ public function createWebhook(string $owner, string $repositoryName, string $url | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public function createComment(string $owner, string $repositoryName, int $pullRequestNumber, string $comment): string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Exception("Not implemented"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $ownerPath = $this->getOwnerPath($owner); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $projectPath = urlencode("{$ownerPath}/{$repositoryName}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $url = "/projects/{$projectPath}/merge_requests/{$pullRequestNumber}/notes"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $response = $this->call(self::METHOD_POST, $url, ['PRIVATE-TOKEN' => $this->accessToken], ['body' => $comment]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $responseHeaders = $response['headers'] ?? []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $statusCode = $responseHeaders['status-code'] ?? 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ($statusCode >= 400) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Exception("Failed to create comment: HTTP {$statusCode}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $responseBody = $response['body'] ?? []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!array_key_exists('id', $responseBody)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Exception("Comment creation response is missing comment ID."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return $pullRequestNumber . ':' . ($responseBody['id'] ?? ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public function getComment(string $owner, string $repositoryName, string $commentId): string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Exception("Not implemented"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $ownerPath = $this->getOwnerPath($owner); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $projectPath = urlencode("{$ownerPath}/{$repositoryName}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $parts = explode(':', $commentId, 2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (count($parts) !== 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [$mrIid, $noteId] = $parts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $url = "/projects/{$projectPath}/merge_requests/{$mrIid}/notes/{$noteId}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $response = $this->call(self::METHOD_GET, $url, ['PRIVATE-TOKEN' => $this->accessToken]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return $response['body']['body'] ?? ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public function updateComment(string $owner, string $repositoryName, int $commentId, string $comment): string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public function updateComment(string $owner, string $repositoryName, string $commentId, string $comment): string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Exception("Not implemented"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $ownerPath = $this->getOwnerPath($owner); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $projectPath = urlencode("{$ownerPath}/{$repositoryName}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $parts = explode(':', $commentId, 2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (count($parts) !== 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Exception("Invalid comment ID format: {$commentId}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [$mrIid, $noteId] = $parts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $url = "/projects/{$projectPath}/merge_requests/{$mrIid}/notes/{$noteId}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $response = $this->call(self::METHOD_PUT, $url, ['PRIVATE-TOKEN' => $this->accessToken], ['body' => $comment]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $responseHeaders = $response['headers'] ?? []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (($responseHeaders['status-code'] ?? 0) !== 200) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Exception("Failed to update comment: HTTP " . ($responseHeaders['status-code'] ?? 0)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return $commentId; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public function getUser(string $username): array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Exception("Not implemented"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $url = "/users?username=" . rawurlencode($username); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $response = $this->call(self::METHOD_GET, $url, ['PRIVATE-TOKEN' => $this->accessToken]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $responseHeaders = $response['headers'] ?? []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $statusCode = $responseHeaders['status-code'] ?? 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ($statusCode >= 400) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Exception("Failed to get user: HTTP {$statusCode}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $body = $response['body'] ?? []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // GitLab returns an array of users — return first match | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (empty($body[0])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Exception("User not found: {$username}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return $body[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public function getOwnerName(string $installationId, ?int $repositoryId = null): string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -511,17 +574,123 @@ public function getOwnerName(string $installationId, ?int $repositoryId = null): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public function getPullRequest(string $owner, string $repositoryName, int $pullRequestNumber): array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Exception("Not implemented"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $ownerPath = $this->getOwnerPath($owner); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $projectPath = urlencode("{$ownerPath}/{$repositoryName}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $url = "/projects/{$projectPath}/merge_requests/{$pullRequestNumber}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $response = $this->call(self::METHOD_GET, $url, ['PRIVATE-TOKEN' => $this->accessToken]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $responseHeaders = $response['headers'] ?? []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $statusCode = $responseHeaders['status-code'] ?? 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ($statusCode >= 400) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Exception("Failed to get merge request: HTTP {$statusCode}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $mr = $response['body'] ?? []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Normalize to match expected shape (consistent with Gitea/GitHub) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'number' => $mr['iid'] ?? 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'title' => $mr['title'] ?? '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'state' => $mr['state'] ?? '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'head' => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'ref' => $mr['source_branch'] ?? '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'sha' => $mr['sha'] ?? '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'base' => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'ref' => $mr['target_branch'] ?? '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+591
to
+603
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public function getPullRequestFiles(string $owner, string $repositoryName, int $pullRequestNumber): array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Exception("Not implemented"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $ownerPath = $this->getOwnerPath($owner); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $projectPath = urlencode("{$ownerPath}/{$repositoryName}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Poll until diff is ready (patch_id_sha not null) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $maxAttempts = 10; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for ($attempt = 0; $attempt < $maxAttempts; $attempt++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $mrResponse = $this->call( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self::METHOD_GET, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "/projects/{$projectPath}/merge_requests/{$pullRequestNumber}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ['PRIVATE-TOKEN' => $this->accessToken] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $mrBody = $mrResponse['body'] ?? []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (($mrBody['patch_id_sha'] ?? null) !== null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| usleep(1000000); // 1 second | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
jaysomani marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Fetch diffs with pagination | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $allFiles = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $page = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $perPage = 100; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while (true) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $url = "/projects/{$projectPath}/merge_requests/{$pullRequestNumber}/diffs?page={$page}&per_page={$perPage}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $response = $this->call(self::METHOD_GET, $url, ['PRIVATE-TOKEN' => $this->accessToken]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $responseHeaders = $response['headers'] ?? []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $statusCode = $responseHeaders['status-code'] ?? 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ($statusCode >= 400) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Exception("Failed to get merge request files: HTTP {$statusCode}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $files = $response['body'] ?? []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!is_array($files) || empty($files)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| foreach ($files as $diff) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $allFiles[] = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'filename' => $diff['new_path'] ?? $diff['old_path'] ?? '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (count($files) < $perPage) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $page++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return $allFiles; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public function getPullRequestFromBranch(string $owner, string $repositoryName, string $branch): array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Exception("Not implemented"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $ownerPath = $this->getOwnerPath($owner); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $projectPath = urlencode("{$ownerPath}/{$repositoryName}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $url = "/projects/{$projectPath}/merge_requests?state=opened&source_branch=" . urlencode($branch); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $response = $this->call(self::METHOD_GET, $url, ['PRIVATE-TOKEN' => $this->accessToken]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $responseHeaders = $response['headers'] ?? []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $statusCode = $responseHeaders['status-code'] ?? 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ($statusCode >= 400) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Exception("Failed to list merge requests: HTTP {$statusCode}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $body = $response['body'] ?? []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (empty($body[0])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $mr = $body[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'number' => $mr['iid'] ?? 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'title' => $mr['title'] ?? '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'state' => $mr['state'] ?? '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'head' => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'ref' => $mr['source_branch'] ?? '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'sha' => $mr['sha'] ?? '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'base' => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'ref' => $mr['target_branch'] ?? '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public function listBranches(string $owner, string $repositoryName): array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -704,14 +873,24 @@ public function generateCloneCommand(string $owner, string $repositoryName, stri | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public function getEvent(string $event, string $payload): array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $payloadArray = json_decode($payload, true); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ($payloadArray === false || $payloadArray === null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ($payloadArray === null || !is_array($payloadArray)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| switch ($event) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case 'Push Hook': | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $commits = $payloadArray['commits'] ?? []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $latestCommit = !empty($commits) ? $commits[0] : []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $checkoutSha = $payloadArray['checkout_sha'] ?? ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $latestCommit = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| foreach ($commits as $c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (($c['id'] ?? '') === $checkoutSha) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $latestCommit = $c; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (empty($latestCommit) && !empty($commits)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $latestCommit = $commits[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $ref = $payloadArray['ref'] ?? ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ref format: refs/heads/main | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $branch = str_replace('refs/heads/', '', $ref); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.