Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/235 typesafety changes #238

Merged
merged 14 commits into from
Sep 1, 2023
Merged

Conversation

April-Bates-Dev
Copy link
Contributor

No description provided.

"lint-fix": "eslint . --ext=js,ts --fix",
"lint-test": "eslint . --ext=js,ts",
"lint-fix": "eslint . --ext=js,ts,tsx --fix",
"lint-test": "eslint . --ext=js,ts,tsx",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Note] We now have tsx files

@@ -8,7 +8,7 @@ import { buildResourceName } from "../../helpers";
import { commonLambdaEnvironment } from "../helpers/commonLambdaEnvironment";
import { commonLambdaProps } from "../helpers/commonLambdaProps";

interface UpdateUserLambdaProps {
type UpdateUserLambdaProps = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Note] I changed a lot of interfaces to types for consistency across the repo

const getCdkContext = (): Record<string, unknown> | undefined => {
const cdkContextEnv = process.env.CDK_CONTEXT_JSON;
const getCliCdkContext = (cliArg: string): string | undefined => {
const cdkContextEnv = process.env.CDK_CONTEXT_JSON ?? "";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Note] We need a long term fix for getting the environment variables in a nice way, as there a number of fixes like this across the code base and we could do something consistent

const parsedCdKContext: unknown = JSON.parse(cdkContextEnv);

if (isRecord(parsedCdKContext) && cliArg in parsedCdKContext) {
const cdkCli = parsedCdKContext[cliArg];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Note] I had to do this type check in two stages as otherwise typescript was getting confused 😮‍💨

@github-actions
Copy link
Contributor

github-actions bot commented Sep 1, 2023

Risk Level 3 - /home/runner/work/code-review-gpt/code-review-gpt/src/common/git/getFilesWithChanges.ts

The code changes in this file have a moderate risk to the code base. There are a few potential issues and areas for improvement:

  1. The getFilesWithChanges function uses the exit function from the process module. This can cause the entire process to exit abruptly, which may not be desired. Consider throwing an error instead and handling it at a higher level.

  2. The getFilesWithChanges function throws an error if there is a failure in getting the files with changes. It would be better to provide a more informative error message to the user.

Here are some example code snippets for the suggested changes:

  1. Throwing an error instead of using exit:
export const getFilesWithChanges = async (
  isCi: string | undefined
): Promise<ReviewFile[]> => {
  const fileNames = await getChangedFilesNames(isCi);

  if (fileNames.length === 0) {
    throw new Error(\"No files with changes found. Please stage your changes and try again.\");
  }

  const files = await Promise.all(
    fileNames.map(async (fileName) => {
      const fileContent = await readFile(fileName, \"utf8\");
      const changedLines = await getChangedFileLines(isCi, fileName);

      return { fileName, fileContent, changedLines };
    })
  );

  return files;
};
  1. Providing a more informative error message:
export const getFilesWithChanges = async (
  isCi: string | undefined
): Promise<ReviewFile[]> => {
  try {
    const fileNames = await getChangedFilesNames(isCi);

    if (fileNames.length === 0) {
      throw new Error(\"No files with changes found. Please stage your changes and try again.\");
    }

    const files = await Promise.all(
      fileNames.map(async (fileName) => {
        const fileContent = await readFile(fileName, \"utf8\");
        const changedLines = await getChangedFileLines(isCi, fileName);

        return { fileName, fileContent, changedLines };
      })
    );

    return files;
  } catch (error) {
    throw new Error(`Failed to get files with changes: ${error.message}`);
  }
};



---

**Risk Level 3 - /home/runner/work/code-review-gpt/code-review-gpt/services/web-app/src/components/home/Features.tsx**

The code changes in this file have a moderate risk to the code base. The changes involve adding a new import statement and updating the component to use a new Card component. The code is clean and readable. However, there is a typo in the import statement \"use client\" which should be removed.


---

**Risk Level 4 - /home/runner/work/code-review-gpt/code-review-gpt/services/web-app/src/components/home/Hero.tsx**

The code changes in this file have a high risk to the code base. The changes involve adding a new function component and using multiple framer-motion hooks and transformations. The code is complex and may introduce bugs or performance issues. It is recommended to thoroughly test the changes before merging them into the code base.



---
🔍🔧🚨



---

#### Powered by [Code Review GPT](https://github.com/mattzcarey/code-review-gpt)

import { Theme } from "@radix-ui/themes";
import { NavBar } from "@/components/navbar";
import Footer from "../components/footer/footer";
import { NavBar } from "../components/navbar";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Note] I changed all imports to relative imports so we had consistency across the code base. In the future it would be nice to use absolute paths everywhere

@github-actions
Copy link
Contributor

github-actions bot commented Sep 1, 2023

Test results summary:

✅ [PASS] - Test case: Bad variable name
❌ [FAIL] - Test case: Exposed secret
✅ [PASS] - Test case: Too many nested loops
⚠️ [WARN] - Test case: Unawaited Promise

SUMMARY: ✅ PASS: 2 - ⚠️ WARN: 1 - ❌ FAIL: 1


Tests Powered by Code Review GPT

} finally {
setLoading(false);
}
};
fetchData();
void fetchData();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Note] I had to use void here as useEffects don't like async functions.

@@ -1,5 +1,4 @@
import React from "react";
import { Button } from "@radix-ui/themes";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Note] I'm slightly worried that we are using both tailwind and radix- I think we should choose just one as otherwise I think we are going to run into problems in future (with them fighting each other etc)

@@ -2,9 +2,10 @@ import { Button, Link } from "@radix-ui/themes";
import { motion, useScroll, useSpring, useTransform } from "framer-motion";
import React, { useRef } from "react";
import { MdNorthEast } from "react-icons/md";

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Note] These changes had been made as linting hadn't been run on the code Aiden added

axiosInstance.interceptors.request.use((config) => {
//TODO: investigate this as the Session type returned from does not seem to contain 'token'
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
config.headers.Authorization = session.token;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Note] I didn't have time to investigate this :(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add this to my current bug ticket :)

userId: string,
apiKey: string,
name: string,
pictureUrl?: string,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Note] This is a bug- by setting "" values here you actually setting constants rather than default values- so if you tried to do

const user: User;
user.name = 'Adam' 

You would see an error as user.name can only be set to "".

gitlabSha: process.env.CI_COMMIT_SHA ?? '',
gitlabToken: process.env.GITLAB_TOKEN ?? '',
projectId: process.env.CI_PROJECT_ID ?? '',
mergeRequestIIdString: process.env.CI_MERGE_REQUEST_IID ?? '',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Note] This is again gross but I want to fix the process.env types properly and in the mean time at least our fix is consistent (this is the fix in another file)

Copy link
Contributor

@SEBRATHEZEBRA SEBRATHEZEBRA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! The consistency of everything looks so much better :)

@April-Bates-Dev April-Bates-Dev merged commit b4e257e into main Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants