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

[FEATURE REQUEST]: Get `GITHUB_TOKEN` from a function #345

Closed mrjones2014 closed 1 year ago

mrjones2014 commented 1 year ago

I see that in https://github.com/pwntester/octo.nvim/blob/master/lua/octo/gh/init.lua

you grab GITHUB_TOKEN from vim.env. I would like to use the 1Password CLI to populate the GITHUB_TOKEN.

Currently I have it set up like so (using the op.nvim 1Password Neovim plugin):

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
vim.env.GITHUB_TOKEN = github_token
require('octo').setup()

However, this means I am prompted for auth immediately, instead of only when octo.nvim actually goes to run the gh CLI.

Would it be possible to have an option in setup like so:

require('octo').setup({
  get_gh_token = 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
  end,
})
mrjones2014 commented 1 year ago

Or it could more generally be get_env which gets merged with your env_vars table.

mrjones2014 commented 1 year ago

I've opened a PR for this.

pwntester commented 1 year ago

Thanks for PR, added few comments there