Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/test-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ jobs:
- name: Run Integration Tests
run: npm run test:integration
working-directory: apps/api

env:
DATABASE_URL: ${{ env.DATABASE_URL }}
SUPERUSER_DATABASE_URL: ${{ env.SUPERUSER_DATABASE_URL }}
USE_SELF_SIGNED_SSL: false
JWT_SECRET: test-secret
REDIS_CONNECTION_STRING: redis://localhost:6379
BULLMQ_ENABLED: false
GITHUB_CLIENT_SECRET: test
GITHUB_CLIENT_ID: test
GITHUB_APP_HANDLE: test
GITHUB_APP_ID: test
GITHUB_APP_PRIVATE_KEY: test
GITHUB_WEBHOOK_SECRET: test
Comment thread
waltergalvao marked this conversation as resolved.
3 changes: 2 additions & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"prisma:migrate:new": "prisma migrate dev --create-only --name",
"prisma:migrate:production": "prisma migrate deploy",
"test:unit": "vitest run --project unit",
"test:integration": "cross-env NODE_ENV=test DATABASE_URL=postgresql://app_user:app_user@localhost:5433/sweetr_test SUPERUSER_DATABASE_URL=postgresql://postgres:postgres@localhost:5433/sweetr_test vitest run --project integration"
"test:integration": "cross-env LOG_LEVEL=warn NODE_ENV=production DATABASE_URL=postgresql://app_user:app_user@localhost:5433/sweetr_test SUPERUSER_DATABASE_URL=postgresql://postgres:postgres@localhost:5433/sweetr_test vitest run --project integration"
Comment thread
waltergalvao marked this conversation as resolved.
},
"prisma": {
"seed": "tsx prisma/seed/run-seeder.ts"
Expand Down Expand Up @@ -65,6 +65,7 @@
"octokit": "^3.2.2",
"pino": "^9.13.1",
"radash": "^11.0.0",
"re2": "^1.23.3",
"resend": "^6.0.0",
"semver": "^7.5.4",
"stripe": "^16.6.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- AlterTable
ALTER TABLE "PullRequest" ADD COLUMN "body" TEXT NOT NULL DEFAULT '',
ADD COLUMN "labels" JSONB NOT NULL DEFAULT '[]',
ADD COLUMN "sourceBranch" TEXT NOT NULL DEFAULT '';
Comment thread
waltergalvao marked this conversation as resolved.
4 changes: 4 additions & 0 deletions apps/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,11 @@ model PullRequest {

title String
number String
sourceBranch String @default("")
targetBranch String @default("main")
body String @default("")

labels Json @default("[]")
files Json @default("[]")
commentCount Int
changedFilesCount Int
Expand Down Expand Up @@ -766,6 +769,7 @@ model Incident {

archivedAt DateTime?

@@unique([workspaceId, causeDeploymentId])
Comment thread
waltergalvao marked this conversation as resolved.
Outdated
Comment thread
waltergalvao marked this conversation as resolved.
Outdated
@@index([causeDeploymentId])
@@index([fixDeploymentId])
@@index([teamId])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ describe("groupSerialReviews", () => {
type,
eventAt,
pullRequest: {
sourceBranch: "feat/test",
targetBranch: "main",
mergeCommitSha: null,
gitProvider: "GITHUB",
gitPullRequestId: "1",
gitUrl: "https://github.com/test/test/pull/1",
title: "Test PR",
body: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
number: "1",
files: [],
commentCount: 0,
Expand All @@ -78,6 +80,7 @@ describe("groupSerialReviews", () => {
authorId: John,
repositoryId: 1,
workspaceId: 1,
labels: [],
...pullRequest,
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from "./deployment-pr-linking.service";
import { CreateDeploymentFromPullRequestMergeArgs } from "./deployment-create-from-merge.types";
import { BusinessRuleException } from "../../errors/exceptions/business-rule.exception";
import { addJob, SweetQueue } from "../../../bull-mq/queues";

export const createDeploymentFromPullRequestMerge = async ({
application,
Expand Down Expand Up @@ -79,6 +80,11 @@ export const createDeploymentFromPullRequestMerge = async ({
workspaceId,
});

await addJob(SweetQueue.AUTOMATION_INCIDENT_DETECTION, {
deploymentId: deployment.id,
workspaceId,
});

logger.info("deploymentCreateFromMergeWorker: Deployment created", {
deployment,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { getTimeToDeploy } from "../../github/services/github-pull-request-track
import { DataIntegrityException } from "../../errors/exceptions/data-integrity.exception";
import { isBefore } from "date-fns";
import { captureException } from "../../../lib/sentry";
import { addJob, SweetQueue } from "../../../bull-mq/queues";

export const handleDeploymentPullRequestAutoLinking = async ({
workspaceId,
Expand Down Expand Up @@ -140,6 +141,11 @@ export const handleDeploymentPullRequestAutoLinking = async ({
}
);

await addJob(SweetQueue.AUTOMATION_INCIDENT_DETECTION, {
deploymentId,
workspaceId,
});

return;
}

Expand All @@ -158,6 +164,11 @@ export const handleDeploymentPullRequestAutoLinking = async ({
pullRequestIds: filteredPullRequests.map((pr) => pr.id),
});

await addJob(SweetQueue.AUTOMATION_INCIDENT_DETECTION, {
deploymentId,
workspaceId,
});

await Promise.all(
filteredPullRequests.map(async (pr) => {
if (!pr.tracking) {
Expand Down
11 changes: 11 additions & 0 deletions apps/api/src/app/github/services/github-pull-request.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ const fetchPullRequest = async (
closedAt
mergedAt
baseRefName
headRefName
body

labels(first: ${GITHUB_MAX_PAGE_LIMIT}) {
nodes {
name
}
}

createdAt
updatedAt
Expand Down Expand Up @@ -287,8 +295,11 @@ const upsertPullRequest = async (
gitPullRequestId: gitPrData.id,
gitUrl: gitPrData.url,
title: gitPrData.title,
sourceBranch: gitPrData.headRefName ?? "",
targetBranch: gitPrData.baseRefName,
body: gitPrData.body ?? "",
number: gitPrData.number.toString(),
labels: gitPrData.labels?.nodes?.map((l: { name: string }) => l.name) ?? [],
commentCount: gitPrData.totalCommentsCount,
changedFilesCount: gitPrData.changedFiles,
linesAddedCount: gitPrData.additions,
Expand Down
Loading
Loading