pwntester / octo.nvim

Edit and review GitHub issues and pull requests from the comfort of your favorite editor
MIT License
2.28k stars 125 forks source link

add ability to set computed env vars for gh cli #346

Closed mrjones2014 closed 1 year ago

mrjones2014 commented 1 year ago

Describe what this PR does / why we need it

Adds a hook to get computed environment variables when running the GitHub CLI. It is needed, for example, to allow you to set GITHUB_TOKEN from the 1Password CLI.

Does this pull request fix one issue?

Fixes #345

Describe how you did it

Added a config option that allows user to pass a function that returns a table to merge with env_vars

Describe how to verify it

require('octo').setup({
  get_env = function() return { GITHUB_TOKEN = 'your token here' } end,
})

This config should authenticate the GitHub CLI via octo.nvim

Special notes for reviews

Here's how I've configured mine, integrating with the op.nvim plugin, using its API:

require('octo').setup({
  get_env = function()
    local github_token = require('op.api').item.get({ '[item uuid here]', '--fields', 'token' })[1]
    if not github_token or not vim.startswith(github_token, 'ghp_') then
      error('Failed to get GitHub token.')
    end

    return { GITHUB_TOKEN = github_token }
  end,
})
pwntester commented 1 year ago

Thanks for the PR!

Although in your specific use case it makes sense for get_env to be a function, I would expect most users would suffice to use a table. Can you make the following changes?

mrjones2014 commented 1 year ago

Done!

pwntester commented 1 year ago

Awesome, thanks!