gitbutlerapp / gitbutler

The GitButler version control client, backed by Git, powered by Tauri/Rust/Svelte
https://gitbutler.com
Other
12.25k stars 476 forks source link

Can't open a PR #4378

Open dr-wahrheit opened 1 month ago

dr-wahrheit commented 1 month ago

Version

0.12.9

Operating System

Mac OS X

Distribution Method

dmg (Apple Silicon)

Describe the issue

I reported a problem that is now solved thanks to the support of the community (Discord).

While I can pull and push changes without any issues, I am unable to create a pull request. The error I receive is: Cannot create PR without GitHub credentials.

image

I have configured multiple Git accounts on my machine using SSH. I use this configuration in ~/.ssh/config:

#git account-1
Host github-account-1
 HostName github.com
 User git
 IdentityFile ~/.ssh/id_ed25519_github_account-1

#git account-2
Host github-account-2
 HostName github.com
 User git
 IdentityFile ~/.ssh/id_ed25519_github_account-2

This is the output of git remote -v:

origin  git@github-account-1:my-repo.git (fetch)
origin  git@github-account-1:my-repo.git (push)

As you notice, no github.com is present in the URL and, as @Byron pointed out, this doesn't seem to agree with this check: https://github.com/Byron/gitbutler/blob/c8e7368df5c7532469d84da2956d2ff9fa9332d8/app/src/lib/github/service.ts#L77-L79

To fix this issue, I had to change my remote configuration to include "github.com".

I'm not sure if this is a bug or not, but for sure it would be better to document somewhere that "github.com" is mandatory in the remote URL.

A note: after changing the URL, it didn't work immediately. There seems to be some kind of cache that I couldn't clear. I had to remove the project and then re-add it.

How to reproduce

Try configuring a project using a remote without "github.com" in the URL:

  1. Add the following to ~/.ssh/config:

    Host github-account-1
     HostName github.com
     User git
     IdentityFile ~/.ssh/id_ed25519_github_account-1
  2. Add the SSH key to your account.

  3. Set git@github-account-1:my-repo.git as the remote URL for your Git repository.

  4. Open the project with GitButler and verify that the configuration is correct. image

  5. Make a change to the project.

  6. Try to create a pull request (PR).

This setup aims to use a custom SSH configuration (~/.ssh/config) to define an alias (github-account-1) for GitHub, ensuring that the correct SSH key and hostname are used without explicitly including "github.com" in the remote URL.

Expected behavior

That it does what the Create PR button normally does and that it doesn't show the error message Cannot create PR without GitHub credentials.

Relevant log output

No logs are present in console. Just the "Cannot create PR without GitHub credentials." message
Byron commented 1 month ago

Thanks a lot for the detailed report!

I think there are multiple parts to this which could see an improvement.

The first mentioned issue should be quite straightforward to fix by unifying the logic that decides if something is eligible for GitHub API usage or not.

dr-wahrheit commented 1 month ago

An update after upgrade to 0.12.12.

The problem seems getting worse. Now even with github.com in the ssh configuration the "Create PR" is grayed out (the previous version worked).

image

My GitHub integration is (I did it again a couple of times just to be safe):

image
Byron commented 1 month ago

Thanks for the feedback, it's too bad this issue unintentionally went off into the wrong direction.

Could you share the (possibly anonymised, but structurally similar) URL that is used now?

With that, it should be possible to reproduce the issue, and assure it won't regress again. Thank you

dr-wahrheit commented 1 month ago

Of course!

I use this configuration in ~/.ssh/config:

#git account-1
Host account1-github.com
 HostName github.com
 User git
 IdentityFile ~/.ssh/id_ed25519_github_account-1

#git account-2
Host github-account-2
 HostName github.com
 User git
 IdentityFile ~/.ssh/id_ed25519_github_account-2

This way I can use git+ssh and the configured host to manage access with different accounts on the same machine.

This is the output of git remote -v:

origin  git@account1-github.com:my-repo.git (fetch)
origin  git@account1-github.com:my-repo.git (push)

I hope this helps. I remain at your disposal for any clarification.

Byron commented 1 month ago

Thanks a lot, very helpful!

I think the problem here is that it's still an unconventional GitHub URL, and until there is a way in the UI to override it, it must parseable with the git-url-parse package, which also has some examples of valid URLs.

The key here is that the username and the repo-name must be available from the URL.

If there is no way to make a custom setup like this parseable, I think the only way to make this work is to provide overrides for the required values, username and repository name, in the interface.