mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-08-25 18:39:39 +00:00
Compare commits
12 Commits
test/ai-pr
...
212d0d1974
Author | SHA1 | Date | |
---|---|---|---|
212d0d1974 | |||
6d529ee0ae | |||
85687e7950 | |||
7e2c3136cf | |||
61348aa351 | |||
dea942f11e | |||
d62e620828 | |||
f0556813ac | |||
6d2252a403 | |||
8d265c9105 | |||
a4095c837b | |||
65d4a56135 |
42
.github/workflows/pr-description.yml
vendored
42
.github/workflows/pr-description.yml
vendored
@ -1,4 +1,4 @@
|
||||
name: 🤖 AI PR Description Generator (with Template)
|
||||
name: 🤖 AI PR Description Commenter (100% Safe with jq)
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
@ -12,8 +12,10 @@ jobs:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install GitHub CLI
|
||||
uses: cli/cli-action@v2
|
||||
- name: Install GitHub CLI and jq
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install gh jq -y
|
||||
|
||||
- name: Fetch PR Commits
|
||||
id: fetch_commits
|
||||
@ -23,23 +25,31 @@ jobs:
|
||||
echo "$COMMITS" >> $GITHUB_ENV
|
||||
echo "EOF" >> $GITHUB_ENV
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GH_TOKEN: ${{ secrets.GH_PERSONAL_TOKEN }}
|
||||
|
||||
- name: Generate PR Description with OpenAI
|
||||
id: generate_description
|
||||
- name: Generate PR Description with OpenAI (Safe JSON with jq)
|
||||
run: |
|
||||
REQUEST_BODY=$(jq -n \
|
||||
--arg model "gpt-4o" \
|
||||
--arg content "Given the following commit messages:\n\n${commits}\n\nGenerate a clear and professional pull request description." \
|
||||
'{
|
||||
model: $model,
|
||||
messages: [{ role: "user", content: $content }]
|
||||
}'
|
||||
)
|
||||
|
||||
RESPONSE=$(curl -s https://api.openai.com/v1/chat/completions \
|
||||
-H "Authorization: Bearer $OPENAI_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"model": "gpt-4o",
|
||||
"messages": [{
|
||||
"role": "user",
|
||||
"content": "Given the following commit messages:\n\n'"${commits}"'\n\nFill the following pull request template. Only fill the \"## Description\" section:\n\n<!--\n Thanks for contributing!\n\n Provide a description of your changes below and a general summary in the title.\n-->\n\n## Jira Ticket\n\n[SP-0000](https://syncrow.atlassian.net/browse/SP-0000)\n\n## Description\n\n<!--- Describe your changes in detail -->\n\n## How to Test\n\n<!--- Describe the created APIs / Logic -->"
|
||||
}]
|
||||
}')
|
||||
-d "$REQUEST_BODY")
|
||||
|
||||
DESCRIPTION=$(echo "$RESPONSE" | jq -r '.choices[0].message.content')
|
||||
|
||||
echo "---------- OpenAI Raw Response ----------"
|
||||
echo "$RESPONSE"
|
||||
echo "---------- Extracted Description ----------"
|
||||
echo "$DESCRIPTION"
|
||||
|
||||
echo "description<<EOF" >> $GITHUB_ENV
|
||||
echo "$DESCRIPTION" >> $GITHUB_ENV
|
||||
echo "EOF" >> $GITHUB_ENV
|
||||
@ -47,8 +57,8 @@ jobs:
|
||||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
||||
commits: ${{ env.commits }}
|
||||
|
||||
- name: Update PR Body with AI Description
|
||||
- name: Post AI Generated Description as Comment
|
||||
run: |
|
||||
gh pr edit ${{ github.event.pull_request.number }} --body "${{ env.description }}"
|
||||
gh pr comment ${{ github.event.pull_request.number }} --body "${{ env.description }}"
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GH_TOKEN: ${{ secrets.GH_PERSONAL_TOKEN }}
|
||||
|
@ -1,15 +1,13 @@
|
||||
import { DeviceStatusLogRepository } from '@app/common/modules/device-status-log/repositories';
|
||||
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
||||
import {
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { AddDeviceStatusDto } from '../dtos/add.devices-status.dto';
|
||||
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
||||
import { GetDeviceDetailsFunctionsStatusInterface } from 'src/device/interfaces/get.device.interface';
|
||||
import { TuyaContext } from '@tuya/tuya-connector-nodejs';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { firebaseDataBase } from '../../firebase.config';
|
||||
import { TuyaContext } from '@tuya/tuya-connector-nodejs';
|
||||
import {
|
||||
Database,
|
||||
DataSnapshot,
|
||||
@ -17,7 +15,9 @@ import {
|
||||
ref,
|
||||
runTransaction,
|
||||
} from 'firebase/database';
|
||||
import { DeviceStatusLogRepository } from '@app/common/modules/device-status-log/repositories';
|
||||
import { GetDeviceDetailsFunctionsStatusInterface } from 'src/device/interfaces/get.device.interface';
|
||||
import { firebaseDataBase } from '../../firebase.config';
|
||||
import { AddDeviceStatusDto } from '../dtos/add.devices-status.dto';
|
||||
@Injectable()
|
||||
export class DeviceStatusFirebaseService {
|
||||
private tuya: TuyaContext;
|
||||
@ -79,64 +79,77 @@ export class DeviceStatusFirebaseService {
|
||||
device: any;
|
||||
}[],
|
||||
): Promise<void> {
|
||||
const allLogs = [];
|
||||
|
||||
console.log(`🔁 Preparing logs from batch of ${batch.length} items...`);
|
||||
|
||||
const allLogs = [];
|
||||
|
||||
for (const item of batch) {
|
||||
const device = item.device;
|
||||
|
||||
if (!device?.uuid) {
|
||||
console.log(`⛔ Skipped unknown device: ${item.deviceTuyaUuid}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const logs = item.log.properties.map((property) =>
|
||||
// Determine properties based on environment
|
||||
const properties =
|
||||
this.isDevEnv && Array.isArray(item.log?.properties)
|
||||
? item.log.properties
|
||||
: Array.isArray(item.status)
|
||||
? item.status
|
||||
: null;
|
||||
|
||||
if (!properties) {
|
||||
console.log(
|
||||
`⛔ Skipped invalid status/properties for device: ${item.deviceTuyaUuid}`,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
const logs = properties.map((property) =>
|
||||
this.deviceStatusLogRepository.create({
|
||||
deviceId: device.uuid,
|
||||
deviceTuyaId: item.deviceTuyaUuid,
|
||||
productId: item.log.productId,
|
||||
productId: device.productDevice?.uuid,
|
||||
log: item.log,
|
||||
code: property.code,
|
||||
value: property.value,
|
||||
eventId: item.log.dataId,
|
||||
eventTime: new Date(property.time).toISOString(),
|
||||
eventId: item.log?.dataId,
|
||||
eventTime: new Date(
|
||||
this.isDevEnv ? property.time : property.t,
|
||||
).toISOString(),
|
||||
}),
|
||||
);
|
||||
|
||||
allLogs.push(...logs);
|
||||
}
|
||||
|
||||
console.log(`📝 Total logs to insert: ${allLogs.length}`);
|
||||
|
||||
const insertLogsPromise = (async () => {
|
||||
const chunkSize = 300;
|
||||
let insertedCount = 0;
|
||||
const chunkSize = 300;
|
||||
let insertedCount = 0;
|
||||
|
||||
for (let i = 0; i < allLogs.length; i += chunkSize) {
|
||||
const chunk = allLogs.slice(i, i + chunkSize);
|
||||
try {
|
||||
const result = await this.deviceStatusLogRepository
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into('device-status-log') // or use DeviceStatusLogEntity
|
||||
.values(chunk)
|
||||
.orIgnore() // skip duplicates
|
||||
.execute();
|
||||
for (let i = 0; i < allLogs.length; i += chunkSize) {
|
||||
const chunk = allLogs.slice(i, i + chunkSize);
|
||||
try {
|
||||
const result = await this.deviceStatusLogRepository
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into('device-status-log')
|
||||
.values(chunk)
|
||||
.orIgnore()
|
||||
.execute();
|
||||
|
||||
insertedCount += result.identifiers.length;
|
||||
console.log(
|
||||
`✅ Inserted ${result.identifiers.length} / ${chunk.length} logs (chunk)`,
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('❌ Insert error (skipped chunk):', error.message);
|
||||
}
|
||||
insertedCount += result.identifiers.length;
|
||||
console.log(
|
||||
`✅ Inserted ${result.identifiers.length} / ${chunk.length} logs (chunk)`,
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('❌ Insert error (skipped chunk):', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(
|
||||
`✅ Total logs inserted: ${insertedCount} / ${allLogs.length}`,
|
||||
);
|
||||
})();
|
||||
|
||||
await insertLogsPromise;
|
||||
console.log(`✅ Total logs inserted: ${insertedCount} / ${allLogs.length}`);
|
||||
}
|
||||
|
||||
async addDeviceStatusToFirebase(
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { Injectable, OnModuleInit } from '@nestjs/common';
|
||||
import TuyaWebsocket from '../../config/tuya-web-socket-config';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { DeviceStatusFirebaseService } from '@app/common/firebase/devices-status/services/devices-status.service';
|
||||
import { SosHandlerService } from './sos.handler.service';
|
||||
import { Injectable, OnModuleInit } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import * as NodeCache from 'node-cache';
|
||||
import TuyaWebsocket from '../../config/tuya-web-socket-config';
|
||||
import { SosHandlerService } from './sos.handler.service';
|
||||
|
||||
@Injectable()
|
||||
export class TuyaWebSocketService implements OnModuleInit {
|
||||
@ -74,7 +74,12 @@ export class TuyaWebSocketService implements OnModuleInit {
|
||||
this.client.message(async (ws: WebSocket, message: any) => {
|
||||
try {
|
||||
const { devId, status, logData } = this.extractMessageData(message);
|
||||
if (!Array.isArray(logData?.properties)) {
|
||||
// console.log(
|
||||
// `📬 Received message for device: ${devId}, status:`,
|
||||
// status,
|
||||
// logData,
|
||||
// );
|
||||
if (!Array.isArray(status)) {
|
||||
this.client.ackMessage(message.messageId);
|
||||
return;
|
||||
}
|
||||
@ -162,6 +167,8 @@ export class TuyaWebSocketService implements OnModuleInit {
|
||||
status: any;
|
||||
logData: any;
|
||||
} {
|
||||
// console.log('Received message:', message);
|
||||
|
||||
const payloadData = message.payload.data;
|
||||
|
||||
if (this.isDevEnv) {
|
||||
|
@ -3,12 +3,12 @@ import { IsNotEmpty, IsOptional, IsUUID, Matches } from 'class-validator';
|
||||
|
||||
export class BookingRequestDto {
|
||||
@ApiProperty({
|
||||
description: 'Month in MM/YYYY format',
|
||||
example: '07/2025',
|
||||
description: 'Month in MM-YYYY format',
|
||||
example: '07-2025',
|
||||
})
|
||||
@IsNotEmpty()
|
||||
@Matches(/^(0[1-9]|1[0-2])\/\d{4}$/, {
|
||||
message: 'Date must be in MM/YYYY format',
|
||||
message: 'Date must be in MM-YYYY format',
|
||||
})
|
||||
month: string;
|
||||
|
||||
|
@ -51,7 +51,7 @@ export class BookingService {
|
||||
}
|
||||
|
||||
async findAll({ month, space }: BookingRequestDto, project: string) {
|
||||
const [monthNumber, year] = month.split('/').map(Number);
|
||||
const [monthNumber, year] = month.split('-').map(Number);
|
||||
const fromDate = new Date(year, monthNumber - 1, 1);
|
||||
const toDate = new Date(year, monthNumber, 0, 23, 59, 59);
|
||||
return this.bookingEntityRepository.find({
|
||||
|
Reference in New Issue
Block a user