Skip to content

Commit 841eaff

Browse files
Merge pull request #921 from sparrowapp-dev/release/2.35.0
Release/2.35.0 to release-v2.
2 parents 543940e + add4147 commit 841eaff

File tree

15 files changed

+2311
-350
lines changed

15 files changed

+2311
-350
lines changed

.github/workflows/staging.yml

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,43 @@ name: Staging
22
on:
33
push:
44
branches:
5-
- release/2.34.0
5+
- release/2.35.0
66

77
jobs:
8-
build:
9-
runs-on: ubuntu-latest
10-
steps:
11-
- uses: actions/checkout@master
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@master
1212

13-
- uses: Azure/docker-login@v1
14-
with:
15-
login-server: sparrowprod.azurecr.io
16-
username: ${{ secrets.REGISTRY_USERNAME }}
17-
password: ${{ secrets.REGISTRY_PASSWORD }}
13+
- uses: Azure/docker-login@v1
14+
with:
15+
login-server: sparrowprod.azurecr.io
16+
username: ${{ secrets.REGISTRY_USERNAME }}
17+
password: ${{ secrets.REGISTRY_PASSWORD }}
1818

19-
- run: |
20-
docker build . -t sparrowprod.azurecr.io/sparrow-api:${{ github.run_number }} --build-arg GITHUB_TOKEN=${{ secrets.SPARROW_GITHUB_TOKEN }}
21-
docker push sparrowprod.azurecr.io/sparrow-api:${{ github.run_number }}
22-
deploy:
23-
needs: build
24-
runs-on: ubuntu-latest
25-
steps:
26-
- uses: actions/checkout@master
27-
- uses: richardrigutins/replace-in-files@v1
28-
with:
29-
files: "./deploymentManifests/deployment.yml"
30-
search-text: '_BUILD__ID_'
31-
replacement-text: '${{ github.run_number }}'
19+
- run: |
20+
docker build . -t sparrowprod.azurecr.io/sparrow-api:${{ github.run_number }} --build-arg GITHUB_TOKEN=${{ secrets.SPARROW_GITHUB_TOKEN }}
21+
docker push sparrowprod.azurecr.io/sparrow-api:${{ github.run_number }}
22+
deploy:
23+
needs: build
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@master
27+
- uses: richardrigutins/replace-in-files@v1
28+
with:
29+
files: "./deploymentManifests/deployment.yml"
30+
search-text: "_BUILD__ID_"
31+
replacement-text: "${{ github.run_number }}"
3232

33-
- uses: azure/[email protected]
33+
- uses: azure/[email protected]
3434

35-
- uses: Azure/k8s-set-context@v2
36-
with:
37-
kubeconfig: ${{ secrets.KUBE_CONFIG }}
35+
- uses: Azure/k8s-set-context@v2
36+
with:
37+
kubeconfig: ${{ secrets.KUBE_CONFIG }}
3838

39-
- uses: Azure/k8s-deploy@v4
40-
with:
41-
action: deploy
42-
namespace: sparrow-staging
43-
manifests: |
44-
./deploymentManifests/deployment.yml
39+
- uses: Azure/k8s-deploy@v4
40+
with:
41+
action: deploy
42+
namespace: sparrow-staging
43+
manifests: |
44+
./deploymentManifests/deployment.yml
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { Injectable, Inject, OnModuleInit } from "@nestjs/common";
2+
import { Db, ObjectId } from "mongodb";
3+
import { Collections } from "@src/modules/common/enum/database.collection.enum";
4+
import { LimitArea } from "@src/modules/common/models/plan.model";
5+
import { ConfigService } from "@nestjs/config";
6+
7+
@Injectable()
8+
export class AddCommunityPlanToTeamsMigration implements OnModuleInit {
9+
private hasRun = false;
10+
11+
constructor(
12+
@Inject("DATABASE_CONNECTION") private readonly db: Db,
13+
private readonly configService: ConfigService,
14+
) {}
15+
16+
async onModuleInit(): Promise<void> {
17+
if (this.hasRun) return;
18+
19+
try {
20+
console.log("Running AddCommunityPlanToTeamsMigration...");
21+
22+
const teamCollection = this.db.collection(Collections.TEAM);
23+
const planCollection = this.db.collection(Collections.PLAN);
24+
25+
// Get the default hub plan name from config
26+
const defaultHubPlan =
27+
this.configService.get<string>("app.defaultHubPlan");
28+
// Fetch the plan from plan collection
29+
const planDoc = await planCollection.findOne({ name: defaultHubPlan });
30+
if (!planDoc) {
31+
console.warn(
32+
`Plan '${defaultHubPlan}' not found in plan collection. Skipping team updates.`,
33+
);
34+
return;
35+
}
36+
const { _id, ...planData } = planDoc;
37+
38+
// Update teams that don't have a plan or where plan.id is missing
39+
const query = {
40+
$or: [
41+
{ plan: { $exists: false } },
42+
{ plan: null },
43+
{ "plan.id": { $exists: false } },
44+
],
45+
};
46+
47+
const update = {
48+
$set: {
49+
plan: {
50+
id: _id,
51+
...planData,
52+
},
53+
},
54+
};
55+
56+
const result = await teamCollection.updateMany(query, update);
57+
console.log(
58+
`Updated ${result.modifiedCount} team(s) with the Community plan.`,
59+
);
60+
61+
this.hasRun = true;
62+
} catch (error) {
63+
console.error("Error during AddCommunityPlanToTeamsMigration:", error);
64+
}
65+
}
66+
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "project-sparrow-api",
3-
"version": "2.34.0",
3+
"version": "2.35.0",
44
"description": "Backend APIs for Project Sparrow.",
55
"author": "techdome",
66
"license": "",
@@ -36,7 +36,8 @@
3636
"start:migration-superadmin": "ts-node -r tsconfig-paths/register src/migration-superadmin.ts",
3737
"start:migration-email": "ts-node -r tsconfig-paths/register src/migration-emailId.ts",
3838
"start:add-test-request": "ts-node -r tsconfig-paths/register src/add-tests-to-request.ts",
39-
"start:add-testflow-schedule": "ts-node -r tsconfig-paths/register src/update-plan-testflow-schedule.ts"
39+
"start:add-testflow-schedule": "ts-node -r tsconfig-paths/register src/update-plan-testflow-schedule.ts",
40+
"start:add-community-plan-to-teams": "ts-node -r tsconfig-paths/register src/add-community-plan-to-teams.ts"
4041
},
4142
"dependencies": {
4243
"@anthropic-ai/sdk": "^0.54.0",

src/add-community-plan-to-teams.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { NestFactory } from "@nestjs/core";
2+
import { Module, Provider } from "@nestjs/common";
3+
import { MongoClient, Db } from "mongodb";
4+
import { ConfigModule, ConfigService } from "@nestjs/config";
5+
import configuration from "./modules/common/config/configuration";
6+
import { AddCommunityPlanToTeamsMigration } from "migrations/add-community-plan-to-teams.migration";
7+
8+
const databaseProvider: Provider = {
9+
provide: "DATABASE_CONNECTION",
10+
useFactory: async (configService: ConfigService): Promise<Db> => {
11+
const dbUrl = configService.get<string>("db.url");
12+
const dbName = configService.get<string>("db.name");
13+
14+
if (!dbUrl) {
15+
throw new Error("Database URL is not defined in the configuration.");
16+
}
17+
18+
const client = new MongoClient(dbUrl);
19+
await client.connect();
20+
return client.db(dbName);
21+
},
22+
inject: [ConfigService],
23+
};
24+
25+
@Module({
26+
imports: [
27+
ConfigModule.forRoot({
28+
isGlobal: true,
29+
load: [configuration],
30+
}),
31+
],
32+
providers: [databaseProvider, AddCommunityPlanToTeamsMigration],
33+
})
34+
class MigrationModule {}
35+
36+
async function run() {
37+
const app = await NestFactory.createApplicationContext(MigrationModule);
38+
const migration = app.get(AddCommunityPlanToTeamsMigration);
39+
await migration.onModuleInit();
40+
await app.close();
41+
}
42+
43+
run();

src/modules/common/enum/testflow.enum.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,21 @@ export interface EmailData {
3737
scheduleRunPassedCount: number;
3838
scheduleRunFailedCount: number;
3939
scheduleRunTotalRequest: number;
40-
scheduleRunPassPercentage: string;
40+
scheduleRunPassPercentage: string;
4141
scheduleTotalTime: string | number;
4242
scheduleRunEnvName: string;
4343
isSuccess: boolean;
4444
isFailed: boolean;
4545
isPartial: boolean;
46+
testflowDataSummary?: DatasetSummaryItem[];
47+
}
48+
49+
export interface DatasetSummaryItem {
50+
datasetName: string;
51+
requestCount: number;
52+
passedCount: number;
53+
failedCount: number;
54+
duration: string;
4655
}
4756

4857
export interface OnceConfig {

0 commit comments

Comments
 (0)