Change GitHub accounts decoupled from Git Config #163
Replies: 3 comments
-
Another approach would be to customizable variable that takes a function and ghub--token calls that function. This will allow the users to define custom functions, which would then make it easier to customize things. For example, instead of defining a completely new auth-source-backend as in this discussion the user can override the behavior of ghub--token with a different function. This way all the other packages that will use ghub--token like forge will be doing the same thing! |
Beta Was this translation helpful? Give feedback.
-
You should be able to do that using this basic idea: (cl-defmethod ghub--username :around (host &optional forge)
(or your-variable
(cl-call-next-method)))
If you do something like what I suggested above, then I ask you to make users aware that some ghub and forge documentation is superseded by that. The Git variables can be used to use different users in different repositories. If you override these repository-local settings with one global variable, there obviously is some loss of functionality. (Alternatively, why not just use the Git variable?)
That makes it sound like we call this internal function all over the place, but it is actually quite simple. But yes, you are not supposed to pass arguments to that function directly. It's a very internal function. Note however that
Ghub doesn't provide such a variable, but if one really wanted to bypass
That discussion demonstrates that it is actually fairly simple to define a new
The same happens if you configure this at the I would assume that a user who doesn't want to use any of the available You seem to conflate two distinct things:
You have concentrated on the former function but what is really matters for you are the latter two functions. I've written the above a while ago but then did not post it because it doesn't address the most important part: "can you make changes so my hacks are not necessary". Yes, and that would help with the code in Forge that allows viewing topics even if the respective repository hasn't been cloned and or been added to the local database. That works most of the time, but not always -- for the same simply ignoring that a repository might not exist locally doesn't work for you either. I will have to look into teaching |
Beta Was this translation helpful? Give feedback.
-
@tarsius Thanks for the detailed response and discussion. I think the last part of your answer captures the core of the discussion. In an Ideal world, forge can visit/edit any topic without any needs for local variables (this includes not just a local repo, but also the git user!). All it needs is to know who the user is and what secret to use to identify the user when editing topics (those can be provided in some interactive way if needed or passed to a function as variables rather than relying on a locally stored value). The current approach with using Now let me first make a general suggestion and then address some of the questions you had: 1- The user does not need to worry about adding the confusing "^forge" to their secret, etc. That happens automatically by forge itself, and it can be fixed for all credentials. Now, with that in mind, I can address some of the things you mentioned:
The assumption in my package is that you make calls from any directory (so no dependence on default-directory) and can explore any GitHub repo from within emacs. So essentially this is like opening the browser and looking at repos, issues, etc. but inside emacs buffers with emacs powers! Using git variables would not work because then the user has to call the commands in my package from the right directory and that does not make a lot of sense for the kind of workflow I am trying to support.
This is indeed something that looks interesting. If I find some time, I'll give it a try and see what I can do. But at the same time, think about whether it makes sense to do this by default in
Yes, if this was just something I was doing in my config, I could do it. But I am trying to provide a package to users and I don't want to break things with forge. I think the cl-defmethod you suggested above would be a much cleaner solution.
The issue is exactly this. Of course, we can make a call to GitHub API and specify those variables (with or without
I understand your point, but as I mentioned above, if you look at it from forge's perspectives, the two are not really different because there is no straightforward way to pass ghub--username and ghub--host directly to forge to switch between global accounts (again without local variables stored in repos, etc.) So as far as forge is concerned (and remember I am interested in forge for the nice interactive frontend to interact with topics, not just making calls to GitHub API), the two are not separate unless we hack the way forge does authentication. Thanks for taking the time to respond in details again. |
Beta Was this translation helpful? Give feedback.
-
Hi,
Is there a way to decouple the GitHub account from git config?
I am trying to support multiple accounts in my package, consult-gh, but since I added support for magit/forge, I would like to have switching accounts integrated with forge as well, but currently forge is using ghub and therefore git config to get the user info and retrieve tokens from auth-source-search. I would like to be able to customize that behavior and pass usernames decoupled from git config.
For example, if you can add a variable that keeps the current user info (host, username, etc.) that is used for authenticaiton. Then I can simply edit that variable and let forge and ghub do their normal things. Normal users should not see any difference because this variable can pick up its default value from git config anyway. Note that I cannot pass user and host to ghub--token because everything else in forge is calling ghub--token on its own.
Beta Was this translation helpful? Give feedback.
All reactions