This guide covers how to generate Github PRs with Codegen.

To follow along, you can use any codemod. This guide will use the following boilerplate codemod as an example:

# grab codebase content
file = codebase.files[0] # or .get_file("test.py")
function = codebase.functions[0] # or .get_symbol("my_func")

# make edits
file.edit('🌈' + file.content) # edit contents
function.rename('new_name') # rename
function.set_docstring('new docstring') # set docstring

Previewing Changes

Before creating a PR, you can use the preview diff tab to preview the changes a codemod will make.

The preview diff tab prioritizes speed over completeness - returning results in 1-5s. It does not return all the changes that a codemod will make.

Once you are happy with the preview, and want to view the full diff, you can navigate to the Generate PRs tab.

Generating PRs

On the generate PRs tab you are able to control:

  • The base branch of the PR.
  • The head branch of the PR + whether to force push to the head branch.
  • The grouping of the PRs. See Splitting PRs for more details.
  • The maximum number of PRs to generate.
  • A subdirectory or path to limit the changes to.

After you hit the Generate PRs button, this will start a process that you can view the progress + output of in the bottom panel.

The Generate PRs button only creates new branches with the changes from the codemod. It does not automatically open PRs for these branches because this could overload the repo’s CI pipeline if there is ex: 1 PR for every CODEOWNER.

To open the PRs you can click the Create PR button in the output panel.

Now you can navigate to this PR in your Github repo, get any required approvals, and then merge πŸš€!