Skip to content

gitignore .apphosting/ #377

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

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft

gitignore .apphosting/ #377

wants to merge 11 commits into from

Conversation

annajowang
Copy link
Collaborator

  • Add common function to update .gitignore.
  • Address bot comments
  • Update packages/@apphosting/common/src/index.ts
  • Update packages/@apphosting/common/src/index.ts
  • Apply suggestions from code review
  • fix stupid mess made by stupid bot
  • lint bot's bad code
  • lint
  • Update common package version
  • gitignore .apphosting/

annajowang and others added 11 commits August 1, 2025 21:56
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @annajowang, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

I've implemented changes to automatically manage the .gitignore file within projects, specifically ensuring that the .apphosting/ directory, which contains build artifacts, is always ignored by Git. This prevents unnecessary files from being committed to version control and streamlines the development workflow. This was achieved by introducing a new common utility function and integrating it into the Next.js adapter's build process.

Highlights

  • New .gitignore Utility Function: I've introduced a new utility function updateOrCreateGitignore in the @apphosting/common package. This function can programmatically add specified entries to a .gitignore file, creating the file if it doesn't already exist.
  • Automatic .apphosting/ Gitignore: I've integrated the new updateOrCreateGitignore function into the @apphosting/adapter-nextjs build process. Now, after the bundle.yaml is generated, the .apphosting/ directory will automatically be added to the project's .gitignore file, ensuring build outputs are not committed.
  • Enhanced Test Coverage: I've added comprehensive unit tests for the new .gitignore functionality in both the @apphosting/common library and the @apphosting/adapter-nextjs to ensure robustness across various scenarios, including monorepos and projects with or without existing .gitignore files.
  • Package Version Update: The version of the @apphosting/common package has been bumped to 0.0.6 to reflect the addition of the new updateOrCreateGitignore utility.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new utility function to add entries to a .gitignore file, and uses it to ensure the .apphosting directory is ignored. The changes are well-tested. I've provided feedback on improving the implementation of the new utility for better performance and correctness, and on refactoring the new tests to reduce code duplication.

Comment on lines +216 to +272
it(".apphosting gitignored without existing .gitignore file", async () => {
const { generateBuildOutput, validateOutputDirectory } = await importUtils;
const files = {
// .next/standalone/.next/ must be created beforehand otherwise
// generateBuildOutput will attempt to copy
// .next/ into .next/standalone/.next
".next/standalone/.next/package.json": "",
".next/static/staticfile": "",
};
generateTestFiles(tmpDir, files);
await generateBuildOutput(
tmpDir,
tmpDir,
outputBundleOptions,
path.join(tmpDir, ".next"),
defaultNextVersion,
{
adapterPackageName: "@apphosting/adapter-nextjs",
adapterVersion: "14.0.1",
},
);
await validateOutputDirectory(outputBundleOptions, path.join(tmpDir, ".next"));

const expectedFiles = {
".gitignore": "/.apphosting/",
};
validateTestFiles(tmpDir, expectedFiles);
});
it(".apphosting gitignored in existing .gitignore file", async () => {
const { generateBuildOutput, validateOutputDirectory } = await importUtils;
const files = {
// .next/standalone/.next/ must be created beforehand otherwise
// generateBuildOutput will attempt to copy
// .next/ into .next/standalone/.next
".next/standalone/.next/package.json": "",
".next/static/staticfile": "",
".gitignore": "/.next/",
};
generateTestFiles(tmpDir, files);
await generateBuildOutput(
tmpDir,
tmpDir,
outputBundleOptions,
path.join(tmpDir, ".next"),
defaultNextVersion,
{
adapterPackageName: "@apphosting/adapter-nextjs",
adapterVersion: "14.0.1",
},
);
await validateOutputDirectory(outputBundleOptions, path.join(tmpDir, ".next"));

const expectedFiles = {
".gitignore": "/.next/\n/.apphosting/",
};
validateTestFiles(tmpDir, expectedFiles);
});

Choose a reason for hiding this comment

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

medium

These two tests (.apphosting gitignored without existing .gitignore file and .apphosting gitignored in existing .gitignore file) contain a lot of duplicated setup and execution logic. To improve maintainability and reduce redundancy, consider refactoring them into a single parameterized test. You can create an array of test cases and iterate over it, which will make the test suite cleaner and easier to extend in the future.

  [
    {
      description: "without existing .gitignore file",
      initialFiles: {
        ".next/standalone/.next/package.json": "",
        ".next/static/staticfile": "",
      },
      expectedGitignore: "/.apphosting/",
    },
    {
      description: "in existing .gitignore file",
      initialFiles: {
        ".next/standalone/.next/package.json": "",
        ".next/static/staticfile": "",
        ".gitignore": "/.next/",
      },
      expectedGitignore: "/.next/\n/.apphosting/",
    },
  ].forEach(({ description, initialFiles, expectedGitignore }) => {
    it(`.apphosting gitignored ${description}`, async () => {
      const { generateBuildOutput, validateOutputDirectory } = await importUtils;
      generateTestFiles(tmpDir, initialFiles);
      await generateBuildOutput(
        tmpDir,
        tmpDir,
        outputBundleOptions,
        path.join(tmpDir, ".next"),
        defaultNextVersion,
        {
          adapterPackageName: "@apphosting/adapter-nextjs",
          adapterVersion: "14.0.1",
        },
      );
      await validateOutputDirectory(outputBundleOptions, path.join(tmpDir, ".next"));

      const expectedFiles = {
        ".gitignore": expectedGitignore,
      };
      validateTestFiles(tmpDir, expectedFiles);
    });
  });

Comment on lines +157 to +165
let content = fs.readFileSync(gitignorePath, "utf-8");
for (const entry of entries) {
if (!content.split("\n").includes(entry)) {
console.log(`adding ${entry} to ${gitignorePath}`);
content += `\n${entry}`;
}
}

fs.writeFileSync(gitignorePath, content);

Choose a reason for hiding this comment

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

medium

This implementation re-splits the file content on every iteration of the loop, which can be inefficient. Also, the way new entries are appended with \n${entry} can lead to an initial newline if the file is empty.

A more robust and performant approach would be to read the existing entries into a Set once, filter out the entries that already exist, and then append the new entries with proper newline handling.

  let content = fs.readFileSync(gitignorePath, "utf-8");
  const existingEntries = new Set(content.split("\n"));

  const entriesToAdd = entries.filter(entry => !existingEntries.has(entry));

  if (entriesToAdd.length > 0) {
    entriesToAdd.forEach(entry => console.log(`adding ${entry} to ${gitignorePath}`));

    if (content.length > 0 && !content.endsWith("\n")) {
      content += "\n";
    }

    content += entriesToAdd.join("\n");
    fs.writeFileSync(gitignorePath, content);
  }

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.

1 participant