Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .github/workflows/migrate-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name: Migrate Production
on:
workflow_dispatch:

permissions:
contents: read

jobs:
migrate:
runs-on: ubuntu-latest
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/test-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Test (Integration)

on:
pull_request:
types: [synchronize, opened, reopened]
push:
branches:
- main
- production

permissions:
contents: read

jobs:
integration-test:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: sweetr_test
ports:
- 5433:5432
options: >-
--health-cmd pg_isready
--health-interval 2s
--health-timeout 5s
--health-retries 10

env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5433/sweetr_test

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Run Integration Tests
run: npm run test:integration
working-directory: apps/api
env:
DATABASE_URL: ${{ env.DATABASE_URL }}
Comment thread Fixed
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Unit Tests
name: Test (Unit)

on:
pull_request:
Expand All @@ -8,8 +8,11 @@ on:
- main
- production

permissions:
contents: read

jobs:
test:
unit-test:
runs-on: ubuntu-latest

steps:
Expand All @@ -27,5 +30,5 @@ jobs:
- name: Build
run: npm run build

- name: Run Vitest tests
run: npm run test
- name: Run Unit Tests
run: npm run test:unit
1 change: 1 addition & 0 deletions apps/api/.env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL=postgres://postgres:postgres@localhost:5433/sweetr_test
10 changes: 7 additions & 3 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build": "tsc -b",
"typecheck": "tsc --noEmit",
"dev": "tsx watch --clear-screen=false src/index.ts | pino-pretty --I msg,payload",
"start": "node ./build/index.js",
"start": "node ./build/src/index.js",
"prebuild": "npm run rimraf build && npm run prisma:generate",
"rimraf": "rimraf",
"lint": "eslint \"src/**/*.ts\" --fix",
Expand All @@ -18,7 +18,9 @@
"prisma:studio": "prisma studio",
"prisma:push": "prisma db push",
"prisma:migrate:new": "prisma migrate dev --create-only --name",
"prisma:migrate:production": "prisma migrate deploy"
"prisma:migrate:production": "prisma migrate deploy",
"test:unit": "vitest run --project unit",
"test:integration": "cross-env NODE_ENV=test 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 @@ -76,10 +78,12 @@
"@types/micromatch": "^4.0.9",
"@types/node": "^20.9.0",
"@typescript-eslint/eslint-plugin": "^8.26.0",
"cross-env": "^10.1.0",
"pino-pretty": "^10.2.3",
"prisma": "^5.5.2",
"tsx": "^4.15.9",
"typescript": "^5.2.2"
"typescript": "^5.2.2",
"vitest": "^3.2.4"
},
"packageManager": "npm@8.5.5"
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
CodeReviewActivityEvent,
PullRequestActivityEvent,
isCodeReviewActivityEvent,
} from "../services/activity-events.types";
} from "./activity-events.types";

type CreateCodeReviewEventArgs = {
eventAt: Date;
Expand Down
5 changes: 3 additions & 2 deletions apps/api/src/app/billing/services/billing.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { BusinessRuleException } from "../../errors/exceptions/business-rule.exc
import { logger } from "../../../lib/logger";
import { findWorkspaceById } from "../../workspaces/services/workspace.service";
import { getStripeSubscription } from "./stripe.service";
import { isPast, startOfDay, subDays } from "date-fns";
import { isPast } from "date-fns";
import { getStripeClient } from "../../../lib/stripe";
import { ResourceNotFoundException } from "../../errors/exceptions/resource-not-found.exception";
import { isAppSelfHosted } from "../../../lib/self-host";
import { SubscriptionRequiredException } from "../../errors/exceptions/subscription-required.exception";
import { isActiveCustomer } from "../../authorization.service";
import { thirtyDaysAgo } from "../../../lib/date";

export const findSubscription = (workspaceId: number) => {
return getPrisma(workspaceId).subscription.findUnique({
Expand Down Expand Up @@ -61,7 +62,7 @@ export const syncSubscriptionQuantity = async (subscription: Subscription) => {
};

export const countContributors = (workspaceId: number) => {
const sinceDate = startOfDay(subDays(new Date(), 30));
const sinceDate = thirtyDaysAgo();
Comment thread
waltergalvao marked this conversation as resolved.

return getPrisma(workspaceId).workspaceMembership.count({
where: {
Expand Down
105 changes: 105 additions & 0 deletions apps/api/src/app/metrics/resolvers/dora-metrics.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
export default /* GraphQL */ `
type Metrics {
dora: DoraMetrics!
}

type DoraMetrics {
leadTime(input: WorkspaceMetricInput!): LeadTimeMetric!
changeFailureRate(input: WorkspaceMetricInput!): ChangeFailureRateMetric!
deploymentFrequency(
input: WorkspaceMetricInput!
): DeploymentFrequencyMetric!
meanTimeToRecover(input: WorkspaceMetricInput!): MeanTimeToRecoverMetric!
}

input WorkspaceMetricInput {
"The date range."
dateRange: DateTimeRange!

"The period to group by."
period: Period!

"The team ids to filter by."
teamIds: [SweetID!]

"The application ids to filter by."
applicationIds: [SweetID!]

"The environment ids to filter by."
environmentIds: [SweetID!]

"The repository ids to filter by."
repositoryIds: [SweetID!]
}

type LeadTimeMetric {
"The lead time for the current period"
currentAmount: Int!

"The lead time before the current period"
previousAmount: Int!

"The change in lead time"
change: Float!

"The columns for the chart"
columns: [DateTime!]!

"The amounts over time for the chart"
data: [BigInt!]!
}

type ChangeFailureRateMetric {
"The change failure rate for the current period"
currentAmount: Float!

"The change failure rate before the current period"
previousAmount: Float!

"The change in change failure rate"
change: Float!

"The columns for the chart"
columns: [DateTime!]!

"The amounts over time for the chart"
data: [BigInt!]!
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

type DeploymentFrequencyMetric {
"The amount of deployments for the current period"
currentAmount: Int!

"The average number of deployments per day"
avg: Float!

"The number of deployments before the current period"
previousAmount: Int!

"The change in the number of deployments"
change: Float!

"The columns for the chart"
columns: [DateTime!]!

"The amounts over time for the chart"
data: [BigInt!]!
}

type MeanTimeToRecoverMetric {
"The mean time to recover in milliseconds for the current period"
currentAmount: Int!

"The mean time to recover in milliseconds before the current period"
previousAmount: Int!

"The change in mean time to recover"
change: Float!

"The columns for the chart"
columns: [DateTime!]!

"The amounts over time for the chart"
data: [BigInt!]!
}
`;
5 changes: 5 additions & 0 deletions apps/api/src/app/metrics/resolvers/metrics.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default /* GraphQL */ `
extend type Workspace {
metrics: Metrics!
}
`;
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
export default /* GraphQL */ `
enum Period {
DAILY
WEEKLY
MONTHLY
QUARTERLY
YEARLY
}

extend type Workspace {
charts(input: ChartInput!): Charts
}

type Charts {
pullRequestSizeDistribution: NumericSeriesChartData
timeToMerge: NumericChartData
timeForFirstReview: NumericChartData
timeForApproval: NumericChartData
cycleTime: NumericChartData
codeReviewDistribution: CodeReviewDistributionChartData
extend type Metrics {
pullRequestSizeDistribution(input: TeamMetricInput!): NumericSeriesChartData
timeToMerge(input: TeamMetricInput!): NumericChartData
timeForFirstReview(input: TeamMetricInput!): NumericChartData
timeForApproval(input: TeamMetricInput!): NumericChartData
cycleTime(input: TeamMetricInput!): NumericChartData
codeReviewDistribution(
input: TeamMetricInput!
): CodeReviewDistributionChartData
}

# ----------------------------------------------------------------------------------
Expand Down Expand Up @@ -64,7 +54,7 @@ export default /* GraphQL */ `
value: Int!
}

input ChartInput {
input TeamMetricInput {
"The date range."
dateRange: DateTimeRange!

Expand Down
32 changes: 0 additions & 32 deletions apps/api/src/app/metrics/resolvers/queries/charts.query.ts

This file was deleted.

This file was deleted.

Loading
Loading