Skip to content

Commit

Permalink
Move db access to tangential-core
Browse files Browse the repository at this point in the history
  • Loading branch information
akfreas committed Nov 5, 2023
1 parent 2ebd482 commit 7ad6994
Show file tree
Hide file tree
Showing 12 changed files with 197 additions and 88 deletions.
6 changes: 2 additions & 4 deletions tangential/.env.dev
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
LOCAL_HTTP_PROXY=http://localhost:8081
NODE_TLS_REJECT_UNAUTHORIZED=0
MONGODB_URL="mongodb+srv://db:CsdfRb74SZldOODz@tangential-test.jgagw73.mongodb.net/?retryWrites=true&w=majority"
MONGODB_URI="mongodb+srv://db:CsdfRb74SZldOODz@tangential-test.jgagw73.mongodb.net/?retryWrites=true&w=majority"
MONGODB_DATABASE=tangential-dev
awsRegion=us-east-1
awsRegion=us-east-1
2 changes: 1 addition & 1 deletion tangential/.env.live
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
MONGODB_URL="mongodb+srv://db:CsdfRb74SZldOODz@tangential-test.jgagw73.mongodb.net/?retryWrites=true&w=majority"
MONGODB_URI="mongodb+srv://db:CsdfRb74SZldOODz@tangential-test.jgagw73.mongodb.net/?retryWrites=true&w=majority"
MONGODB_DATABASE=tangential-live
awsRegion=us-east-1
2 changes: 1 addition & 1 deletion tangential/.env.offline
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
LOCAL_HTTP_PROXY=http://localhost:8081
NODE_TLS_REJECT_UNAUTHORIZED=0
MONGODB_URL="mongodb+srv://db:CsdfRb74SZldOODz@tangential-test.jgagw73.mongodb.net/?retryWrites=true&w=majority"
MONGODB_URI="mongodb+srv://db:CsdfRb74SZldOODz@tangential-test.jgagw73.mongodb.net/?retryWrites=true&w=majority"
MONGODB_DATABASE=tangential-offline
awsRegion=us-east-1
recordJiraRequests=true
5 changes: 5 additions & 0 deletions tangential/iam-role.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- Effect: Allow
Action:
- sqs:SendMessage
Resource:
- !GetAtt ProjectAnalysisQueue.Arn
8 changes: 5 additions & 3 deletions tangential/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"main": "index.js",
"license": "MIT",
"dependencies": {
"@akfreas/tangential-core": "^1.0.1",
"@akfreas/tangential-core": "^1.0.2",
"@aws-sdk/client-comprehend": "^3.438.0",
"@aws-sdk/client-s3": "^3.438.0",
"@aws-sdk/client-secrets-manager": "^3.438.0",
Expand All @@ -16,11 +16,12 @@
"aws-xray-sdk-core": "^3.5.3",
"axios": "^1.5.1",
"luxon": "^3.4.3",
"mongodb": "6.2"
"mongodb": "6.2",
"openai": "^4.15.0",
"qs": "^6.11.2"
},
"devDependencies": {
"@akfreas/serverless-offline-sqs": "^7.3.2",
"serverless-domain-manager": "^7.1.2",
"@types/jest": "^29.5.7",
"@types/luxon": "^3.3.3",
"@types/node": "^20.8.10",
Expand All @@ -30,6 +31,7 @@
"jest": "^29.7.0",
"proxy-agent": "^6.3.1",
"serverless": "^3.35.2",
"serverless-domain-manager": "^7.1.2",
"serverless-dotenv-plugin": "^6.0.0",
"serverless-offline": "^13.2.0",
"serverless-plugin-typescript": "^2.1.5",
Expand Down
18 changes: 12 additions & 6 deletions tangential/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ provider:
timeout: 60
stage: ${opt:stage, 'offline'}
region: us-east-1
profile: tangential
iam:
role:
statements: ${file(./iam-role.yml)}

environment:
projectAnalysisQueueUrl: ${self:custom.projectAnalysisQueueUrl.${self:provider.stage}, self:custom.projectAnalysisQueueUrl.remote}
httpApi:
Expand All @@ -39,12 +44,13 @@ custom:
debug: true

customDomain:
domainName: api.tangential.app
stage: ${self:provider.stage}
basePath: ${self:provider.stage}
certificateArn: arn:aws:acm:us-east-1:556167323904:certificate/680b6cce-755d-403f-b116-4a1d3d88295a
createRoute53Record: true
endpointType: edge
domainName: ${self:provider.stage}.api.tangential.app
stage: $default
certificateArn: arn:aws:acm:us-east-1:556167323904:certificate/ba19fbb2-0c34-4cd6-984a-0c5562fd6e9d
endpointType: regional
hostedZoneId: Z091731134YSQCRRMM86I
autoDomain: true
apiType: http

functions:
startWorkspaceAnalysis:
Expand Down
6 changes: 2 additions & 4 deletions tangential/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { Agent as HttpAgent } from 'http';
import * as https from 'https';
import * as http from 'http';

let HTTPSProxyAgent: typeof import('https-proxy-agent');
let HTTPProxyAgent: typeof import('http-proxy-agent');


let agent: https.Agent;
Expand Down Expand Up @@ -33,8 +31,8 @@ let httpInstance = new HttpAgent();
let elasticSearchHttpInstance = httpsInstance;

if (process.env.LOCAL_HTTP_PROXY) {
HTTPSProxyAgent = require('https-proxy-agent');
HTTPProxyAgent = require('http-proxy-agent');
const HTTPSProxyAgent = require('https-proxy-agent');
const HTTPProxyAgent = require('http-proxy-agent');
httpsInstance = new HTTPSProxyAgent.HttpsProxyAgent(process.env.LOCAL_HTTP_PROXY);
httpInstance = new HTTPProxyAgent.HttpProxyAgent(process.env.LOCAL_HTTP_PROXY);

Expand Down
7 changes: 3 additions & 4 deletions tangential/src/utils/analysisStorage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import MongoDBWrapper from "./databaseWrapper";
import { doError, doLog, jsonLog } from "./logging";
import { ProjectReport } from "@akfreas/tangential-core"

import { ProjectReport, MongoDBWrapper } from "@akfreas/tangential-core"

export async function storeProjectReport(report: ProjectReport): Promise<void> {
try {
Expand All @@ -10,7 +9,7 @@ export async function storeProjectReport(report: ProjectReport): Promise<void> {
return;
}

const dbWrapper = await MongoDBWrapper.getInstance();
const dbWrapper = await MongoDBWrapper.getInstance(process.env.MONGODB_URI, process.env.MONGODB_DATABASE)

const reportsCollection = dbWrapper.getCollection<ProjectReport>('reports');
// Storing the report in the database
Expand Down
63 changes: 0 additions & 63 deletions tangential/src/utils/databaseWrapper.ts

This file was deleted.

17 changes: 16 additions & 1 deletion tangential/src/utils/jira.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,14 @@ async function calculateVelocity(
return await sumStoryPoints(combinedJql, pointsFields, auth);
}

async function sumRemainingStoryPointsForEpic(epicId: string, pointsFields: PointsField[], auth: JiraRequestAuth): Promise<number> {
// Formulate JQL for issues within an epic, excluding completed issues
const jql = `"Epic Link" = ${epicId} AND status != "Done"`;

// Use the sumStoryPoints function to get the total of remaining points
return await sumStoryPoints(jql, pointsFields, auth);
}


interface IssueCommentsTimeline {
beforeDate: IssueComment[];
Expand Down Expand Up @@ -455,6 +463,9 @@ export async function analyzeEpic(
const velocity = await calculateVelocity(jql, 30, pointsFields, auth); // Assuming 30 days
result.velocity = velocity;

const remainingPoints = await sumRemainingStoryPointsForEpic(epicKey, pointsFields, auth);
result.remainingPoints = remainingPoints;

// Fetch the changelog for that epic
const changelogs = await fetchIssueChangelog(epicKey, auth);
result.epic_changelog = changelogs.length ? changelogs[0] : null;
Expand All @@ -466,7 +477,11 @@ export async function analyzeEpic(
// Pull changelog and comments and filter out everything before last checked date
const longRunningIssues: LongRunningIssue[] = [];

result.comments = await getCommentsTimeline(epicKey, auth, windowStartDate.toISO()!);
const comments = await getCommentsTimeline(epicKey, auth, windowStartDate.toISO()!);

if (comments) {
result.comments = comments;
}

for (const child of childIssues.issues) {
const childData: any = {
Expand Down
33 changes: 33 additions & 0 deletions tangential/src/utils/openAiWrapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import OpenAI from 'openai';
import { Agent } from 'https';
import { httpsAgent } from '../config/config';
import { doError, doLog } from './logging';

interface ChatCompletionParams {
messages: any[];
model: string;
temperature?: number;
maxTokens?: number;
}

export async function createChatCompletion({
messages,
model,
temperature,
maxTokens,
}: ChatCompletionParams): Promise<any> {
const apiKey = process.env.OPENAI_API_KEY;
if (!apiKey) {
throw new Error('No OpenAI API key found');
}
const openai = new OpenAI({
apiKey,
});

const completion = await openai.chat.completions.create({
messages,
model,
}, { httpAgent: httpsAgent });

return completion;
}
Loading

0 comments on commit 7ad6994

Please sign in to comment.