Skip to content

Commit

Permalink
feat: remove dead code (#303)
Browse files Browse the repository at this point in the history
* feat: remove dead code

* fix: minor

* feat: webhook test

* fix: stuff

* test

* feat: little fixes

* feat: add bundling to Lambda

* feat: update readme

* feat: test

* feat: remove bundling from other package

* feat: src file for lambdalith

* feat: add gpt-4-preview

* feat: gpt4

* feat: gpt4

* feat: deploy gpt4

* feat: move webhook lambda to constructs folder

* feat: lock file

* chore: delete test
  • Loading branch information
mattzcarey committed Nov 14, 2023
1 parent a05c913 commit bf29301
Show file tree
Hide file tree
Showing 155 changed files with 7,549 additions and 39,257 deletions.
48 changes: 7 additions & 41 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,6 @@ defaults:
shell: bash

jobs:
build_and_test_web_app:
runs-on: ubuntu-latest
defaults:
run:
working-directory: services/web-app
shell: bash
env:
CI: true
AWS_REGION: eu-west-2

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Node.js
id: setup-node
uses: actions/setup-node@v3
with:
node-version: 18
cache: "npm"
cache-dependency-path: "**/package-lock.json"

# TODO: uncomment commented code- when we configure AWS credentials, we currently get the error 'Could not assume role with OIDC: Not authorized to perform sts:AssumeRoleWithWebIdentity'

# - name: Configure AWS Credentials
# uses: aws-actions/configure-aws-credentials@v3
# with:
# aws-region: ${{ env.AWS_REGION }}
# role-to-assume: ${{ secrets.AWS_ROLE_ARN_STAGING }}

# - name: 🚀 Deploy web-app
# run: npm i && npm run deploy-staging

build_and_test_core:
runs-on: ubuntu-latest
env:
Expand All @@ -78,11 +44,11 @@ jobs:
cache: "npm"
cache-dependency-path: "**/package-lock.json"

# - name: Configure AWS Credentials
# uses: aws-actions/configure-aws-credentials@v3
# with:
# aws-region: ${{ env.AWS_REGION }}
# role-to-assume: ${{ secrets.AWS_ROLE_ARN_STAGING }}
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ env.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_ROLE_ARN_STAGING }}

# - name: 🚀 Deploy core
# run: npm i && npm run deploy-staging
- name: 🚀 Deploy core
run: npm i && npm run deploy-staging
56 changes: 14 additions & 42 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ permissions:
actions: read

jobs:
build_and_test_code_review_gpt:
build_and_test_crgpt_package:
runs-on: ubuntu-latest
defaults:
run:
Expand Down Expand Up @@ -52,43 +52,14 @@ jobs:
- name: Run prompt tests
run: npm run test -- --ci=github --model=gpt-3.5-turbo

build_and_test_web_app:
runs-on: ubuntu-latest
defaults:
run:
working-directory: services/web-app
shell: bash
env:
CI: true
AWS_REGION: eu-west-2

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Node.js
id: setup-node
uses: actions/setup-node@v3
with:
node-version: 18

# TODO: uncomment commented code- when we configure AWS credentials, we currently get the error 'Could not assume role with OIDC: Not authorized to perform sts:AssumeRoleWithWebIdentity'

# - name: Configure AWS Credentials
# uses: aws-actions/configure-aws-credentials@v4
# with:
# aws-region: ${{ env.AWS_REGION }}
# role-to-assume: ${{ secrets.AWS_ROLE_ARN_STAGING }}
- name: 🚀 Deploy web-app
run: npm i && npm run lint-test
# run: npm i && npm run lint-test && npm run deploy-staging

build_and_test_core:
runs-on: ubuntu-latest
env:
CI: true
AWS_REGION: eu-west-2
APP_ID: ${{ secrets.APP_ID }}
WEBHOOK_SECRET: ${{ secrets.WEBHOOK_SECRET }}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}

defaults:
run:
Expand All @@ -106,13 +77,14 @@ jobs:
with:
node-version: 18

# - name: Configure AWS Credentials
# uses: aws-actions/configure-aws-credentials@v4
# with:
# aws-region: ${{ env.AWS_REGION }}
# role-to-assume: ${{ secrets.AWS_ROLE_ARN_STAGING }}
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ env.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_ROLE_ARN_STAGING }}

- name: Install pnpm
run: npm i -g pnpm

- name: 🚀 Deploy core
run:
npm i && npm run lint-test
# run: npm i && npm run lint-test && npm run deploy-staging
- name: 🚀 Deploy core to staging
run: pnpm i && pnpm deploy-staging
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ cdk.context.json
.cdk.staging
cdk.out/
cdk.context.json

# PEM
*.pem
28 changes: 1 addition & 27 deletions code-review-gpt/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
browser: true,
es2021: true,
},
ignorePatterns: ["**.js", "**.d.ts"],
ignorePatterns: ["**.js", "**.d.ts", "**.cjs", "**.mjs", "**.json"],
extends: [
"eslint:recommended",
"plugin:import/recommended",
Expand Down Expand Up @@ -37,32 +37,6 @@ module.exports = {
},
],
"prefer-const": "error",
"import/order": [
"error",
{
groups: [
["external", "builtin"],
"unknown",
"internal",
["parent", "sibling", "index"],
],
alphabetize: {
order: "asc",
caseInsensitive: false,
},
"newlines-between": "always",
pathGroupsExcludedImportTypes: ["builtin"],
},
],
"sort-imports": [
"error",
{
ignoreCase: true,
ignoreDeclarationSort: true,
ignoreMemberSort: false,
memberSyntaxSortOrder: ["none", "all", "multiple", "single"],
},
],
"padding-line-between-statements": [
"error",
{
Expand Down
29 changes: 0 additions & 29 deletions code-review-gpt/src/common/model/createMemoryStore.test.ts

This file was deleted.

10 changes: 10 additions & 0 deletions services/core/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# GitHub App

APP_ID=<app-id>
WEBHOOK_SECRET=<webhook-secret>
PRIVATE_KEY=<app-private-key>

# Optional

LOG_LEVEL=<log-level>
NODE_ENV=<node-env>
11 changes: 1 addition & 10 deletions services/core/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
browser: true,
es2021: true,
},
ignorePatterns: ["**.js", "**.d.ts"],
ignorePatterns: ["**.js", "**.d.ts", "**.cjs", "**.mjs", "**.json"],
extends: [
"eslint:recommended",
"plugin:import/recommended",
Expand Down Expand Up @@ -54,15 +54,6 @@ module.exports = {
pathGroupsExcludedImportTypes: ["builtin"],
},
],
"sort-imports": [
"error",
{
ignoreCase: true,
ignoreDeclarationSort: true,
ignoreMemberSort: false,
memberSyntaxSortOrder: ["none", "all", "multiple", "single"],
},
],
"padding-line-between-statements": [
"error",
{
Expand Down
40 changes: 37 additions & 3 deletions services/core/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
# How to name and deploy your stacks
# Core Backend Service

When developing be sure to use the `buildResourceName()` to define the names of your stacks and constructs.
Note this service uses pnpm as the package manager.

The `buildResourceName("<resource_name>")` uses command line arguments set when deploying to prepend additional info to the resource names.
```bash
npm install -g pnpm
```

## About the Service

This service allows you to deploy a GitHub app to AWS Lambda which will run code reviews on pull requests.

Set up your GitHub app in the GiHub UI and then set up your environment variables in this service by copying the `.env.example` file to `.env` and filling in the values.

You will not yest have a webhook url so set it to `https://example.com` for now.

## Getting Started

### Install dependencies

```bash
pnpm install
```

### Set up AWS credentials

Set them up in `~/.aws/credentials` or use the `aws configure` command.

Recommend to use a helpful GUI to manage your AWS credentials, such as [Leapp](https://github.com/Noovolari/leapp)

### Command line argument options

Expand All @@ -16,3 +40,13 @@ When you want to deploy you can set these cli options.
```bash
cdk deploy --context stage=<your_stage>
```

or ideally use the deploy script. This script includes packaging of the webhook lambda function.

```bash
pnpm deploy-staging
```

### Update the GitHub app webhook URL

Once you have deployed the service you will need to update the webhook URL in the GitHub app settings.
2 changes: 1 addition & 1 deletion services/core/cdk-helpers/certificates.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { StringParameter } from "aws-cdk-lib/aws-ssm";
import { Construct } from "constructs";

import { getStage, isDev } from "../helpers";
import { getStage, isDev } from "../env-helpers";

export const getCertificateArn = (
scope: Construct,
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions services/core/cdk-helpers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./certificates";
export * from "./domains";
export * from "./lambda";
4 changes: 2 additions & 2 deletions services/core/cdk-helpers/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Duration } from "aws-cdk-lib";
import { Architecture, Runtime, Tracing } from "aws-cdk-lib/aws-lambda";
import { NodejsFunctionProps } from "aws-cdk-lib/aws-lambda-nodejs";

import { getRegion, getStage } from "../helpers";
import { getRegion, getStage } from "../env-helpers";

export const commonLambdaEnvironment: Record<string, string> = {
STAGE: getStage(),
Expand All @@ -25,7 +25,7 @@ export const commonLambdaProps: Omit<NodejsFunctionProps, "code"> = {
memorySize: 512,
awsSdkConnectionReuse: true,
architecture: Architecture.ARM_64,
timeout: Duration.seconds(5),
timeout: Duration.seconds(600),
bundling: cdkEsbuildConfig,
tracing: Tracing.ACTIVE,
};
11 changes: 0 additions & 11 deletions services/core/constants.ts

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CfnResource, IAspect, RemovalPolicy } from "aws-cdk-lib";
import { IConstruct } from "constructs";

import { isProduction } from "../helpers";
import { isProduction } from "../../env-helpers";

export class RemovalPolicyAspect implements IAspect {
visit(node: IConstruct): void {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { AttributeType, BillingMode, Table } from "aws-cdk-lib/aws-dynamodb";
import { Construct } from "constructs";

import { TABLE_NAME } from "../../constants";
import { buildResourceName, isProduction } from "../../helpers";
import { buildResourceName, isProduction } from "../env-helpers";

export class CoreTable extends Table {
export class DDBTable extends Table {
constructor(scope: Construct, id: string) {
super(scope, id, {
tableName: buildResourceName(TABLE_NAME),
tableName: buildResourceName(id),
billingMode: BillingMode.PAY_PER_REQUEST,
partitionKey: {
name: "PK",
Expand Down

0 comments on commit bf29301

Please sign in to comment.