Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce switching to github user before running commands #743

Open
uwla opened this issue Dec 27, 2024 · 2 comments
Open

Enforce switching to github user before running commands #743

uwla opened this issue Dec 27, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@uwla
Copy link

uwla commented Dec 27, 2024

GH allows switching between user profiles with gh auto switch.

Is there a way I can configure octo.nvim to always switch to <user>
before running any command?

For example, suppose my default github user is user1 but I have a
project called project2 which I use user2 and would like to use
user2 for this project. If I have configured octo.nvim to use user2,
then it would switch to this user before running any octo command.

The manual solution is to run gh auth switch and pick user2 every
time I open project2 in neovim.

Another option would be to configure octo.nvim such that it always
switch to the configured user before calling gh behind the scenes.

This would enable us to have a default user1 and to modify this value
on a per-project basis using other nvim plugins which load project
configuration from files .vim, .vim/, init.lua, etc. That way,
project2 can modify the default user1 to user2 like so:

-- this is a local file to project2, which modifies default settings
require('octo.nvim').setup({
    default_user = 'user2'
})
@wd60622
Copy link
Collaborator

wd60622 commented Dec 28, 2024

Yeah, I think that it'd be a good idea to at least not blindly do commands without knowing which username it is from.

It might be good to expose the current user somehow so other plugins can use it. For instance, displaying it in the statusline.

Exposing gh auth switch would be a good idea too.

What are your thoughts? Would like you like to open a PR for this?

@wd60622 wd60622 added the enhancement New feature or request label Dec 28, 2024
@uwla
Copy link
Author

uwla commented Dec 29, 2024

I have made a workaround:

-- OCTO wrapper command
vim.api.nvim_create_user_command('GH', function(args)
    local gh_user = vim.g.gh_auth_user
    if gh_user ~= nil then
        vim.fn.system("gh auth switch --user " .. gh_user)
    end
    require('octo')
    vim.cmd('Octo ' .. table.concat(args.fargs, ' '))
end, { nargs = '*' })

Instead of calling Octo, I call the GH command which switches the user
behind the scenes. That way, I can set vim.g.gh_auth_user on a per-project
basis and have a default one.

The main problem is that I do not get completion in the cmdline.

What are your thoughts? Would like you like to open a PR for this?

I could go for that even though I am not familiar with Lua (I only use it for neovim)

I'll take a look at the codebase this week or next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants