fix(github): skip opened PR previews with skip ci

This commit is contained in:
Andras Bacsai 2026-07-08 14:41:37 +02:00
parent f4f4274cee
commit 3f960d94c3
2 changed files with 48 additions and 1 deletions

View file

@ -101,7 +101,7 @@ private function handleOpenAction(Application $application, ?GithubApp $githubAp
$repo = $repository_parts[1] ?? '';
$headCommitMessage = null;
if ($this->action === 'synchronize') {
if ($this->action === 'opened' || $this->action === 'synchronize' || $this->action === 'reopened') {
$headCommitMessage = getGithubCommitMessage($githubApp, $owner, $repo, $this->commitSha);
}

View file

@ -108,3 +108,50 @@ protected function dispatchPullRequestClosedUpdate(Application $application, App
Http::assertSent(fn (Request $request): bool => $request->url() === 'https://api.github.com/repos/example/repo/commits/after-sha');
});
it('skips a GitHub pull request preview when the opened or reopened head commit message contains skip ci', function (string $action) {
Queue::fake();
$this->application->settings->update([
'is_preview_deployments_enabled' => true,
]);
$githubApp = GithubApp::create([
'name' => 'Public GitHub',
'api_url' => 'https://api.github.com',
'html_url' => 'https://github.com',
'is_public' => true,
'team_id' => $this->team->id,
]);
Http::fake([
'https://api.github.com/repos/example/repo/commits/head-sha' => Http::response([
'commit' => [
'message' => 'docs: fix typo [skip ci]',
],
]),
'https://api.github.com/repos/example/repo/pulls/42/files' => Http::response([]),
]);
$job = new ProcessGithubPullRequestWebhook(
applicationId: $this->application->id,
githubAppId: $githubApp->id,
action: $action,
pullRequestId: 42,
pullRequestHtmlUrl: 'https://github.com/example/repo/pull/42',
pullRequestTitle: 'Add feature',
beforeSha: null,
afterSha: null,
commitSha: 'head-sha',
authorAssociation: 'OWNER',
fullName: 'example/repo',
);
$job->handle();
expect(ApplicationPreview::where('application_id', $this->application->id)->where('pull_request_id', 42)->exists())->toBeFalse()
->and(ApplicationDeploymentQueue::where('application_id', $this->application->id)->where('pull_request_id', 42)->exists())->toBeFalse();
Http::assertSent(fn (Request $request): bool => $request->url() === 'https://api.github.com/repos/example/repo/commits/head-sha');
Http::assertNotSent(fn (Request $request): bool => $request->url() === 'https://api.github.com/repos/example/repo/pulls/42/files');
})->with(['opened', 'reopened']);