mirror of
https://github.com/tpope/vim-rhubarb.git
synced 2025-12-07 12:44:27 +08:00
Support for GitHub enterprise
Completely untested.
This commit is contained in:
@@ -38,6 +38,11 @@ your netrc if you fetch it by hand:
|
|||||||
echo 'machine api.github.com login <token> password x-oauth-basic' \
|
echo 'machine api.github.com login <token> password x-oauth-basic' \
|
||||||
>> ~/.netrc
|
>> ~/.netrc
|
||||||
|
|
||||||
|
If you are using GitHub Enterprise, repeat those steps for each domain (omit
|
||||||
|
the `api.` portion). You'll also need to tell Rhubarb the root URLs:
|
||||||
|
|
||||||
|
let g:github_enterprise_urls = ['https://example.com']
|
||||||
|
|
||||||
## FAQ
|
## FAQ
|
||||||
|
|
||||||
> How do I turn off that preview window that shows the issue body?
|
> How do I turn off that preview window that shows the issue body?
|
||||||
|
|||||||
@@ -32,23 +32,32 @@ function! s:shellesc(arg) abort
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:homepage_for_url(url) abort
|
||||||
|
let domain_pattern = 'github\.com'
|
||||||
|
let domains = get(g:, 'github_enterprise_urls', get(g:, 'fugitive_github_domains', []))
|
||||||
|
call map(copy(domains), 'substitute(v:val, "/$", "", "")')
|
||||||
|
for domain in domains
|
||||||
|
let domain_pattern .= '\|' . escape(split(domain, '://')[-1], '.')
|
||||||
|
endfor
|
||||||
|
let repo = fugitive#buffer().repo()
|
||||||
|
let base = matchstr(a:url, '^\%(https\=://\|git://\|git@\)\=\zs\('.domain_pattern.'\)[/:].\{-\}\ze\%(\.git\)\=$')
|
||||||
|
if index(domains, 'http://' . matchstr(base, '^[^:/]*')) >= 0
|
||||||
|
return 'http://' . tr(base, ':', '/')
|
||||||
|
elseif !empty(base)
|
||||||
|
return 'https://' . tr(base, ':', '/')
|
||||||
|
endif
|
||||||
|
call s:throw('not a GitHub repository: '.a:url)
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:repo_homepage() abort
|
function! s:repo_homepage() abort
|
||||||
if !exists('b:rhubarb_homepage')
|
if !exists('b:rhubarb_homepage')
|
||||||
let repo = fugitive#buffer().repo()
|
let repo = fugitive#buffer().repo()
|
||||||
let url = repo.config('remote.origin.url')
|
let url = repo.config('remote.origin.url')
|
||||||
let name = matchstr(url, 'github\.com[:/]\zs[^/]*/[^/]\{-\}\ze\%(\.git\)\=$')
|
let b:rhubarb_homepage = s:homepage_for_url(url)
|
||||||
if empty(name)
|
|
||||||
call s:throw('origin is not a GitHub repository: '.url)
|
|
||||||
endif
|
|
||||||
let b:rhubarb_homepage = 'https://github.com/'.name
|
|
||||||
endif
|
endif
|
||||||
return b:rhubarb_homepage
|
return b:rhubarb_homepage
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:repo_name() abort
|
|
||||||
return matchstr(s:repo_homepage(), '://[^/]*/\zs.*')
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" }}}1
|
" }}}1
|
||||||
" HTTP {{{1
|
" HTTP {{{1
|
||||||
|
|
||||||
@@ -143,7 +152,13 @@ function! rhubarb#request(path, ...) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! rhubarb#repo_request(...) abort
|
function! rhubarb#repo_request(...) abort
|
||||||
return rhubarb#request('/repos/' . s:repo_name() . (a:0 && a:1 !=# '' ? '/' . a:1 : ''), a:0 > 1 ? a:2 : {})
|
let base = s:repo_homepage()
|
||||||
|
if base =~# '//github\.com/'
|
||||||
|
let base = substitute(base, '//github\.com/', '//api.github.com/repos/', '')
|
||||||
|
else
|
||||||
|
let base = substitute(base, '//[^/]\+/\zs', 'api/v3/repos/', '')
|
||||||
|
endif
|
||||||
|
return rhubarb#request(base . (a:0 && a:1 !=# '' ? '/' . a:1 : ''), a:0 > 1 ? a:2 : {})
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" }}}1
|
" }}}1
|
||||||
|
|||||||
Reference in New Issue
Block a user