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

✨ Updated addProject action to handle repository creation and mapping #903

Merged
merged 2 commits into from
Mar 14, 2025

Conversation

junkisai
Copy link
Member

@junkisai junkisai commented Mar 14, 2025

Issue

  • resolve:

Why is this change needed?

At the same time as adding a Project, a record is also added to the ProjectRepositoryMapping.
Additionally, if there is no corresponding record in the Repository table, a record is added to the Repository table as well.

Furthermore, the display section for the migration list that had been commented out as a temporary measure in #901 (comment) has also been fixed.

What would you like reviewers to focus on?

Testing Verification

What was done

🤖 Generated by PR Agent at 4fcb19b

  • Enhanced addProject action to handle repository creation and mapping.
  • Updated ProjectDetailPage to display migration details.
  • Improved InstallationSelector to include repository and installation details.

Detailed Changes

Relevant files
Enhancement
addProject.ts
Add transaction for project and repository creation           

frontend/apps/app/features/projects/actions/addProject.ts

  • Added a transaction to handle project and repository creation.
  • Ensured repository mapping is created if it doesn't exist.
  • Redirects updated to use the created project's ID.
  • +37/-6   
    ProjectDetailPage.tsx
    Display migration details in ProjectDetailPage                     

    frontend/apps/app/features/projects/pages/ProjectDetailPage/ProjectDetailPage.tsx

  • Updated getProject to include migration details from pull requests.
  • Added logic to filter and map migrations for display.
  • Re-enabled migration list rendering in the UI.
  • +45/-4   
    InstallationSelector.tsx
    Enhance InstallationSelector with repository details         

    frontend/apps/app/features/projects/pages/ProjectNewPage/InstallationSelector/InstallationSelector.tsx

  • Updated handleClick to include repository and installation details.
  • Added form data fields for repository and installation information.
  • Improved error handling during project addition.
  • +24/-14 

    Additional Notes


    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Copy link

    changeset-bot bot commented Mar 14, 2025

    ⚠️ No Changeset found

    Latest commit: 4fcb19b

    Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

    This PR includes no changesets

    When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

    Click here to learn what changesets are, and how to add one.

    Click here if you're a maintainer who wants to add a changeset to this PR

    Copy link

    vercel bot commented Mar 14, 2025

    The latest updates on your projects. Learn more about Vercel for Git ↗︎

    Name Status Preview Comments Updated (UTC)
    liam-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 14, 2025 9:54am
    liam-erd-sample ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 14, 2025 9:54am
    3 Skipped Deployments
    Name Status Preview Comments Updated (UTC)
    test-liam-docs ⬜️ Ignored (Inspect) Mar 14, 2025 9:54am
    test-liam-erd-sample ⬜️ Ignored (Inspect) Mar 14, 2025 9:54am
    test-liam-erd-web ⬜️ Ignored (Inspect) Mar 14, 2025 9:54am

    Copy link

    supabase bot commented Mar 14, 2025

    Updates to Preview Branch (feat/add-record-project-repository-mapping) ↗︎

    Deployments Status Updated
    Database Fri, 14 Mar 2025 09:50:27 UTC
    Services Fri, 14 Mar 2025 09:50:27 UTC
    APIs Fri, 14 Mar 2025 09:50:27 UTC

    Tasks are run on every commit but only new migration files are pushed.
    Close and reopen this PR if you want to apply changes from existing seed or migration files.

    Tasks Status Updated
    Configurations Fri, 14 Mar 2025 09:50:33 UTC
    Migrations Fri, 14 Mar 2025 09:50:33 UTC
    Seeding Fri, 14 Mar 2025 09:50:34 UTC
    Edge Functions Fri, 14 Mar 2025 09:50:34 UTC

    View logs for this Workflow Run ↗︎.
    Learn more about Supabase for Git ↗︎.

    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Error Handling

    The transaction doesn't include any error handling. If repository creation fails or any other part of the transaction fails, there's no specific error handling or user feedback.

    const result = await prisma.$transaction(async (tx) => {
      const project = await tx.project.create({
        data: {
          name: projectName,
        },
      })
    
      let repository = await tx.repository.findUnique({
        where: {
          id: Number(repositoryId),
        },
      })
    
      if (!repository) {
        repository = await tx.repository.create({
          data: {
            name: repositoryName,
            owner: repositoryOwner,
            installationId: BigInt(installationId),
          },
        })
      }
    
      await tx.projectRepositoryMapping.create({
        data: {
          projectId: project.id,
          repositoryId: repository.id,
        },
      })
    
      return project
    })

    Dependency Array
    The handleClick useCallback dependency array only includes selectedInstallation but the function also depends on setIsAddingProject and addProject. These dependencies should be included in the dependency array.

    Type Safety

    The code uses type assertion for pr.migration without proper null checking, which could lead to runtime errors if migration is null despite the filter.

    const { id, title } = pr.migration as { id: number; title: string }
    

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Validate required form data

    Validate that required form data values are not empty or null before proceeding
    with database operations. Missing values could cause runtime errors when
    creating the repository.

    frontend/apps/app/features/projects/actions/addProject.ts [8-11]

     const repositoryId = formData.get('repositoryId') as string
     const repositoryName = formData.get('repositoryName') as string
     const repositoryOwner = formData.get('repositoryOwner') as string
     const installationId = formData.get('installationId') as string
     
    +if (!projectName || !repositoryName || !repositoryOwner || !installationId) {
    +  throw new Error('Missing required project or repository information');
    +}
    +
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    __

    Why: This suggestion addresses a critical validation issue that could lead to runtime errors. Without validation, null or empty values could be passed to database operations, potentially causing application crashes or data integrity issues.

    Medium
    Prevent empty installation ID

    Check if selectedInstallation exists before attempting to use it. The current
    code allows an empty string for installationId which will cause errors in the
    server action when converting to BigInt.

    frontend/apps/app/features/projects/pages/ProjectNewPage/InstallationSelector/InstallationSelector.tsx [75-78]

    +if (!selectedInstallation) {
    +  throw new Error('No installation selected');
    +}
    +
     formData.set(
       'installationId',
    -  selectedInstallation?.id.toString() || '',
    +  selectedInstallation.id.toString(),
     )
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    __

    Why: This suggestion prevents a critical error by checking for a selected installation before using it. The current code allows empty strings which would cause BigInt conversion errors in the server action, leading to application failures.

    Medium
    Handle BigInt conversion errors

    Wrap the BigInt(installationId) conversion in a try-catch block to handle
    potential invalid input that could cause runtime errors when converting
    non-numeric strings to BigInt.

    frontend/apps/app/features/projects/actions/addProject.ts [27-33]

    -repository = await tx.repository.create({
    -  data: {
    -    name: repositoryName,
    -    owner: repositoryOwner,
    -    installationId: BigInt(installationId),
    -  },
    -})
    +try {
    +  repository = await tx.repository.create({
    +    data: {
    +      name: repositoryName,
    +      owner: repositoryOwner,
    +      installationId: BigInt(installationId),
    +    },
    +  })
    +} catch (error) {
    +  throw new Error(`Invalid installation ID format: ${error.message}`);
    +}
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    __

    Why: The suggestion adds important error handling for BigInt conversion which could fail with non-numeric input. This prevents potential runtime errors and provides a more informative error message to help with debugging.

    Medium
    • More

    Copy link
    Member

    @NoritakaIkeda NoritakaIkeda left a comment

    Choose a reason for hiding this comment

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

    Confirmed that repository information is added when creating a project!

    Copy link
    Member

    @sasamuku sasamuku left a comment

    Choose a reason for hiding this comment

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

    LGTM👍

    const repositoryOwner = formData.get('repositoryOwner') as string
    const installationId = formData.get('installationId') as string

    const result = await prisma.$transaction(async (tx) => {
    Copy link
    Member

    Choose a reason for hiding this comment

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

    I see, Prisma's transaction 👀

    @sasamuku sasamuku added this pull request to the merge queue Mar 14, 2025
    Merged via the queue into main with commit d9aee9b Mar 14, 2025
    21 checks passed
    @sasamuku sasamuku deleted the feat/add-record-project-repository-mapping branch March 14, 2025 10:15
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    3 participants