Automating Forge Repository Setup in Emacs

When setting up a new machine, I needed to add multiple GitHub repositories to Forge (the Git forge integration for Emacs) without manually clicking through transient menus for each one. The default interactive workflow requires selecting options for issue/PR syncing through a transient menu for each repository.

Here’s the solution to automate this:

(defun gabe-setup-forge-repos ()
  (forge-add-repository (forge-get-repository "https://github.com/g-simmons/persona-research-internship" nil :insert!))
  ;; Add more repos as needed
)

Key points:

  • forge-get-repository with :insert! creates a repository object that bypasses the interactive menu

  • Wrapping multiple repos in a function makes setup a one-command process

  • This pulls all issues/PRs for each repository automatically

Now setting up Forge on a new machine is as simple as calling (gabe-setup-forge-repos).

Issues

Cannot use ‘vertico-exit’ in "/Users/gabe/" yet.
Use `M-x forge-add-repository' before trying again.Invalid face reference: quote

Implementation notes

  • Claude sonnet (20241022 version) was able to suggest this solution from the following prompt along with the source code for forge-add-repository:

    When I call (forge-add-repository “https://github.com/g-simmons/persona-research-internship”), it pops open a transient menu (not sure if this is the right name) with options for which issues (topics) should get pulled for the newly added repo. I would like to do this non-interactively, for example when setting up a new laptop.

    Is there a way for me to pass in the “a” argument, for pulling all issues without interacting with the transient?

    The implementation of forge-add-repository is attached

  • Claude missed the nil :insert! arguments, but probably could have gotten it if I had included the docs for forge-get-repository.