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

Struggling to get a custom router using ssh remote with port #248

Closed
ErickKramer opened this issue Sep 23, 2024 · 5 comments
Closed

Struggling to get a custom router using ssh remote with port #248

ErickKramer opened this issue Sep 23, 2024 · 5 comments

Comments

@ErickKramer
Copy link

Thank you for maintaining this plugin! I was on the way to develop something similar when I found this.

I was going through your README.md and tried to get a custom router working for my enterprise Gitlab, but I am doing something wrong and I cannot identify what.

My current config looks as follows

return {
	"linrongbin16/gitlinker.nvim",
	cmd = "GitLink",
	config = function(opts)
		opts = opts or {}
		opts.router = {
			my_gitlab = {
				["^gitlab.myhost.com%"] = "https://gitlab.myhost.com/"
					.. "{_A.ORG}/"
					.. "{_A.REPO}/blobs/"
					.. "{_A.CURRENT_BRANCH}/"
					.. "{_A.FILE}"
					.. "#L{_A.LSTART}"
					.. "{(_A.LEND > _A.LSTART and ('-L' .. _A.LEND) or '')}",
			},
		}
		opts.debug = true
		opts.file_log = true
		require("gitlinker").setup(opts)
	end,
}

The remotes that we used are with the following form

ssh://[email protected]:9898/some_group/some_repo.git

While running the GitLink my_gitlab I get the following error

Error executing vim.schedule lua callback: ...nvim/lazy/gitlinker.nvim/lua/gitlinker/commons/async.lua:80:
 The coroutine failed with this message:                                                                  
...im/lazy/gitlinker.nvim/lua/gitlinker/commons/logging.lua:455: fatal: failed to generate permanent url f
rom remote ("ssh://[email protected]:9898/er_dev/er_rosinstall.git"): "...im/lazy/gitlin
ker.nvim/lua/gitlinker/commons/logging.lua:455: \"gitlab.myhost.com\" not support, please bi
nd it in 'router'!"                                                                                       
stack traceback:                                                                                          
        [C]: in function 'assert'                                                                         
        ...im/lazy/gitlinker.nvim/lua/gitlinker/commons/logging.lua:455: in function 'ensure'             
        .../.local/share/nvim/lazy/gitlinker.nvim/lua/gitlinker.lua:232: in function <.../.local/share/nvi
m/lazy/gitlinker.nvim/lua/gitlinker.lua:204>                                                              
stack traceback:                                                                                          
        [C]: in function 'error'                                                                          
        ...nvim/lazy/gitlinker.nvim/lua/gitlinker/commons/async.lua:80: in function 'cb'                  
        ...nvim/lazy/gitlinker.nvim/lua/gitlinker/commons/async.lua:120: in function <...nvim/lazy/gitlink
er.nvim/lua/gitlinker/commons/async.lua:119>

Do you have some idea how I can configure my custom router for this particular case?

@linrongbin16
Copy link
Owner

linrongbin16 commented Sep 23, 2024

hi @ErickKramer,

You need to build the opts configs like this:

opts.router = {
  browse = {
    ["^gitlab.myhost.com%"] = "https://gitlab.myhost.com/"
      .. "{_A.ORG}/"
      .. "{_A.REPO}/blobs/"
      .. "{_A.CURRENT_BRANCH}/"
      .. "{_A.FILE}"
      .. "#L{_A.LSTART}"
      .. "{(_A.LEND > _A.LSTART and ('-L' .. _A.LEND) or '')}",
  }
}

The browse is just for GitLink browse. If you want blame, implement the blame (same level with browse).

@linrongbin16
Copy link
Owner

linrongbin16 commented Sep 23, 2024

Also see here:

router = {
browse = {
-- example: https://github.com/linrongbin16/gitlinker.nvim/blob/9679445c7a24783d27063cd65f525f02def5f128/lua/gitlinker.lua#L3-L4
["^github%.com"] = "https://github.com/"
.. "{_A.ORG}/"
.. "{_A.REPO}/blob/"
.. "{_A.REV}/"
.. "{_A.FILE}?plain=1" -- '?plain=1'
.. "#L{_A.LSTART}"
.. "{(_A.LEND > _A.LSTART and ('-L' .. _A.LEND) or '')}",

@ErickKramer
Copy link
Author

Thank you for the quick response.

I checked your suggestion with the way to define the router and it is defined correctly now.

However, it still fails to parse the enterprise gitlab I am using at the moment. I was expecting the parsing of the remote host to fail due to the custom ssh port, but it seems that the issue is actually caused when having a "complex" enterprise domain.

With "complex" I mean a gitlab remote like

ssh://[email protected]:9898/some_group/some_repo.git

I haven't managed to find the router that can match such domain.

The following router works well, if I remove the mysecond-host from the remote url.

		router = {
			browse = {
				["^gitlab.myhost.com"] = "https://gitlab.myhost.mysecond-host.com/"
					.. "{_A.ORG}/"
					.. "{_A.REPO}/blobs/"
					.. "{_A.CURRENT_BRANCH}/"
					.. "{_A.FILE}"
					.. "#L{_A.LSTART}"
					.. "{(_A.LEND > _A.LSTART and ('-L' .. _A.LEND) or '')}",
			},
		},

I tried using % as shown in the README.md ^github%.your%.host, but it did not work.

I also tried using ** as someone else showed in one of the issues I checked.

@linrongbin16
Copy link
Owner

linrongbin16 commented Sep 23, 2024

hi @ErickKramer,

mysecond-host need to be mysecond%-host.

Because the key ^gitlab%.myhost%.mysecond%-host%.com is evaluated as a lua pattern (a special regex syntax in lua), the % is the escape char.

@linrongbin16 linrongbin16 pinned this issue Sep 24, 2024
@ErickKramer
Copy link
Author

hi @ErickKramer,

mysecond-host need to be mysecond%-host.

Because the key ^gitlab%.myhost%.mysecond%-host%.com is evaluated as a lua pattern (a special regex syntax in lua), the % is the escape char.

Thanks a lot! that was definitely what I was missing :)

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

No branches or pull requests

2 participants