octo.nvim

repository·master·Indexed 25 days ago

https://github.com/pwntester/octo.nvim

A Neovim plugin for editing and reviewing GitHub issues, pull requests, and discussions directly within the editor. It leverages the GitHub CLI to sync changes and provides a dedicated review mode for PRs, including diff navigation and commenting. Supports integration with pickers like telescope.nvim, fzf-lua, and snacks.nvim, and offers omnifunc completion for issues, PRs, and users.

Tokens
4K
Snippets
9
Records
17
Agent score
36%

What's inside octo.nvim

  1. Octo.nvim Features Overview

    master

    Octo.nvim provides the following capabilities:

    • Edit GitHub issues, PRs, and discussions.
    • Add, modify, or delete comments.
    • Manage labels, reactions, assignees, project cards, and reviewers.
    • Perform PR reviews.
    • Interact with the GitHub CLI via the octo.gh Lua module.
  2. Requirements for Octo.nvim

    master

    Before using Octo.nvim, ensure your environment meets the following requirements:

    • Neovim: version >=0.10.0.
    • GitHub CLI: Must be installed.
      • To use Projects v2, run gh auth refresh -s read:project to add the necessary scope.
      • To modify projects, add the project scope instead.
    • plenary.nvim: Required dependency.
    • Pickers (one of the following):
      • telescope.nvim
      • fzf-lua
      • snacks.nvim
      • (If none are installed, it defaults to vim.ui.select)
    • nvim-web-devicons: Recommended for file panel icons.

    After installation, run :checkhealth octo to verify your setup.

  3. Install Octo.nvim using lazy.nvim

    master

    To install Octo.nvim, use the following configuration with lazy.nvim. This setup includes telescope as the picker and defines several keybindings for common tasks like listing issues, pull requests, discussions, and notifications. It also includes the required plenary.nvim dependency.

    {
      "pwntester/octo.nvim",
      cmd = "Octo",
      opts = {
        -- or "fzf-lua" or "snacks" or "default"
        picker = "telescope",
        -- bare Octo command opens picker of commands
        enable_builtin = true,
      },
      keys = {
        {
          "<leader>oi",
          "<CMD>Octo issue list<CR>",
          desc = "List GitHub Issues",
        },
        {
          "<leader>op",
          "<CMD>Octo pr list<CR>",
          desc = "List GitHub PullRequests",
        },
        {
          "<leader>od",
          "<CMD>Octo discussion list<CR>",
          desc = "List GitHub Discussions",
        },
        {
          "<leader>on",
          "<CMD>Octo notification list<CR>",
          desc = "List GitHub Notifications",
        },
        {
          "<leader>os",
          function()
            require("octo.utils").create_base_search_command { include_current_repo = true }
          end,
          desc = "Search GitHub",
        },
      },
      dependencies = {
        "nvim-lua/plenary.nvim",
        "nvim-telescope/telescope.nvim",
        -- OR "ibhagwan/fzf-lua",
        -- OR "folke/snacks.nvim",
        "nvim-tree/nvim-web-devicons", -- optional if file_panel.icons is a function
      },
    }
  4. Perform PR reviews with Octo.nvim

    master

    Octo.nvim provides a dedicated review mode for GitHub Pull Requests.

    Entering Review Mode

    • Run Octo review to enter review mode for the current branch.
    • Alternatively, open a PR buffer (using Octo <PR url>, Octo pr list, or Octo pr edit <PR number>) and run Octo review within that buffer.

    Review Workflow

    1. Navigation: A new tab opens with a file panel and two diff windows. Use ]q and [q to change panel entries.
    2. Commenting:
      • Add comments or suggestions on visual-selected lines using <localleader>ca (comment) or <localleader>sa (suggestion).
      • A new buffer appears in the alternate diff window. Save this buffer to commit your changes to GitHub.
    3. Reviewing Specific Commits: Use Octo review commit to select a specific commit. The file panel will filter to show only files changed by that commit.
    4. Managing Comments: Hold the cursor on a line with a comment to show a thread buffer. You can modify, delete, react, or reply to comments within the thread buffer.
    5. Pending Comments: Use Octo review comments to see pending comments. Press <CR> to jump to a selected comment.
    6. Submitting: Run Octo review submit. A float window will appear for the top-level review comment.
      • Press <C-m> to submit a comment.
      • Press <C-a> to approve.
      • Press <C-r> to request changes.
  5. Configure autocompletion for issues, PRs, and users

    master

    Octo.nvim includes built-in omnifunc completion for issues, PRs, and users, triggerable via <C-x><C-o>.

    Manual Mapping for Markdown

    To enable autocompletion when typing # (issues/PRs) or @ (users) in markdown files, add these mappings to your configuration:

    -- Add these mappings for octo file type
    vim.keymap.set("i", "@", "@<C-x><C-o>", { silent = true, buffer = true })
    vim.keymap.set("i", "#", "#<C-x><C-o>", { silent = true, buffer = true })

    Using Completion Engines

    If you use nvim-cmp or blink.cmp, you can use the following sources for better integration:

    • nvim-cmp: Use cmp-git.
    • blink.cmp: Use blink-cmp-git.
    • Emoji: Use cmp-emoji or blink-emoji.nvim for markdown emoji completion.
  6. Use Treesitter for Octo markdown buffers

    master

    To enable Treesitter markdown parsing for Octo buffers, register the octo filetype to use the markdown language in your Treesitter configuration:

    vim.treesitter.language.register('markdown', 'octo')
  7. Use Octo commands and URLs to manage GitHub content

    master

    Octo.nvim allows you to interact with GitHub issues, PRs, and discussions using the :Octo command or special octo:// URLs.

    Using the :Octo command

    You can pass GitHub URLs directly to the command to open specific items:

    " GitHub.com URLs
    Octo https://github.com/pwntester/octo.nvim/issues/12
    Octo https://github.com/pwntester/octo.nvim/pull/123
    
    " GitHub Enterprise URLs (hostname is automatically detected)
    Octo https://ghe.example.com/owner/repo/issues/456
    Octo https://ghe.example.com/owner/repo/pull/789

    Using octo:// URLs

    You can open issues and PRs directly using the octo:// protocol in any buffer (e.g., via :e). This is useful for working across multiple GitHub instances without changing global settings.

    " Open from the default GitHub instance
    :e octo://owner/repo/issue/123
    :e octo://owner/repo/pull/456
    
    " Open from a specific GitHub Enterprise instance
    :e octo://ghe.example.com/owner/repo/issue/123
    :e octo://ghe.example.com/owner/repo/pull/456

    Common Octo Command Examples

    Octo https://github.com/pwntester/octo.nvim/issues/12
    Octo issue create
    Octo issue create pwntester/octo.nvim
    Octo comment add
    Octo reaction add hooray
    Octo issue edit pwntester/octo.nvim 1
    Octo issue edit 1
    Octo issue list createdBy=pwntester
    Octo issue list neovim/neovim labels=bug,help\ wanted states=OPEN
    Octo search assignee:pwntester is:pr
    Octo search is:discussion repo:pwntester/octo.nvim category:"Show and Tell"
  8. Configure Octo.nvim setup options

    master

    Use the require('octo').setup() function to customize plugin behavior.

    Common Configuration Keys

    • ssh_aliases: A table mapping SSH aliases to github.com. Use this if your .git/config uses an SSH alias for GitHub.
    • suppress_missing_scope: A table to suppress warnings for missing GitHub scopes (e.g., projects_v2 = true).
    • search.completion_overrides: Used to override completion for specific :Octo search qualifiers (e.g., to disable remote calls).
    • mappings_disable_default: Set to true to disable all default key mappings.
    require('octo').setup({
      ssh_aliases = {
        ["<THE ALIAS YOU HAVE LISTED IN ~/.ssh/config>"] = "github.com"
      },
      suppress_missing_scope = {
        projects_v2 = true,
      }
    })
  9. Configure file panel icons

    master

    Customize the icons displayed in the file panel using the file_panel.icons option. You can enable nvim-web-devicons by setting it to true, disable them with false, or provide a custom function that accepts (name, ext) and returns an icon, hl pair.

    require("octo").setup({
      file_panel = {
        icons = function(name, _ext)
          return require("mini.icons").get("file", name)
        end,
      },
    })
  10. Configure octo.nvim

    master

    Use require"octo".setup { ... } to configure the plugin. The configuration covers pickers, remote defaults, UI elements, icon sets, and specialized mappings for discussions, issues, pull requests, and reviews.

    Key configuration sections include:

    • picker: Select the picker engine (telescope, fzf-lua, snacks, or default).
    • picker_config: Configure picker-specific settings like mappings and snacks custom actions.
    • mappings: Define custom keybindings for different contexts (e.g., discussion, issue, pull_request, review_diff).
    • ui: Control buffer appearance, including conceallevel and status column usage.
    • pull_requests / issues / discussions: Set default sorting via order_by (fields: COMMENTS, CREATED_AT, UPDATED_AT; directions: DESC, ASC).
    • gh_cmd: Specify the GitHub CLI command to use (defaults to gh).
    require"octo".setup {
      picker = "telescope", -- or "fzf-lua" or "snacks" or "default"
      picker_config = {
        use_emojis = false,
        search_static = true,
        mappings = {
          open_in_browser = { lhs = "<C-b>", desc = "open issue in browser" },
          copy_url = { lhs = "<C-y>", desc = "copy url to system clipboard" },
          copy_sha = { lhs = "<C-e>", desc = "copy commit SHA to system clipboard" },
          checkout_pr = { lhs = "<C-o>", desc = "checkout pull request" },
          merge_pr = { lhs = "<C-r>", desc = "merge pull request" },
        },
        snacks = {
          actions = {
            issues = {},
            pull_requests = {},
            notifications = {},
            issue_templates = {},
            search = {},
            changed_files = {},
            commits = {},
            review_commits = {},
          },
        },
      },
      default_remote = { "upstream", "origin" },
      default_merge_method = "merge",
      default_delete_branch = false,
      ssh_aliases = {["github.com-work"] = "github.com"},
      gh_cmd = "gh",
      -- ... other options
    }
  11. Troubleshoot GitHub authentication errors

    master

    Octo.nvim relies on the gh CLI tool for authentication.

    Missing Scope Warning

    If you see Cannot request projects v2, missing scope 'read:project', you must refresh your GitHub token with the required scope:

    gh auth refresh -s read:project

    Alternatively, suppress the warning in your Octo config using suppress_missing_scope = { projects_v2 = true }.

    General Authentication Errors

    If you encounter authentication errors:

    1. Ensure gh is logged in: If you are using a GITHUB_TOKEN, run GITHUB_TOKEN= gh auth login and follow the prompts. gh must be able to store credentials in a way accessible to subshells.
    2. SSH Aliases: If your repository uses an SSH alias for GitHub, you must register it in the Octo configuration:
      require('octo').setup({
        ssh_aliases = {
          ["<YOUR_ALIAS>"] = "github.com"
        }
      })
    GITHUB_TOKEN= gh auth login
  12. Use Octo commands for GitHub management

    master

    Octo uses a unified command structure: Octo <object> <action> [arguments]. If no command is passed, Octo treats the argument as a URL to extract an issue or PR repository and number.

    Common objects and actions include:

    • issue: close, reopen, create [repo], develop, edit <number> [repo], list [repo] [key=value], search, reload, browser, url, subscription, pin, unpin.
    • pr: list [repo] [key=value], search, edit <number> [repo], reopen, create, close, checkout, commits, changes, diff, merge [merge|rebase|squash] [delete|nodelete], ready, draft, checks, reload, browser, url, subscription, sha, runs.
    • repo: list, fork, browser, url, subscription, view.
    • comment: add, suggest, delete, url, reply.
    • label: add [label], remove [label], create [label], delete [label], edit [label].
    • milestone: add [milestone], remove, create [milestone], list [repo].
    • assignee/reviewer: add [login], remove [login].
    • discussion: list [repo], edit <number> [repo], browser, create [repo], reload, close, mark, unmark, reopen, search, subscription, category.