Skip to content

Commit 71ed5f7

Browse files
committed
Check using another API endpoint. ex: github enterprise edition. related issue mattn#154
1 parent ac335e1 commit 71ed5f7

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

autoload/gist.vim

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
let s:save_cpo = &cpo
1010
set cpo&vim
1111

12+
if exists('g:gist_disabled') && g:gist_disabled == 1
13+
function gist#Gist(...)
14+
endfunction
15+
finish
16+
endif
17+
1218
if !exists('g:github_user') && !executable('git')
1319
echohl ErrorMsg | echomsg "Gist: require 'git' command" | echohl None
1420
finish
@@ -39,6 +45,20 @@ if !exists('g:gist_api_url')
3945
if strlen(g:gist_api_url) == 0
4046
let g:gist_api_url = 'https://api.github.com/'
4147
end
48+
if exists('g:github_api_url') && !exists('g:gist_shutup_issue154')
49+
if matchstr(g:gist_api_url, 'https\?://\zs[^/]\+\ze') != matchstr(g:github_api_url, 'https\?://\zs[^/]\+\ze')
50+
echohl WarningMsg
51+
echo "--- Warning ---"
52+
echo "It seems that you set different URIs for github_api_url/gist_api_url."
53+
echo "If you want to remove this message: let g:gist_shutup_issue154 = 1"
54+
echohl None
55+
if confirm("Continue?", "&Yes\n&No") != 1
56+
let g:gist_disabled = 1
57+
finish
58+
endif
59+
redraw!
60+
endif
61+
endif
4262
endif
4363

4464
if !exists('g:gist_update_on_write')
@@ -115,7 +135,7 @@ endfunction
115135

116136
" Note: A colon in the file name has side effects on Windows due to NTFS Alternate Data Streams; avoid it.
117137
let s:bufprefix = 'gist' . (has('unix') ? ':' : '_')
118-
function! s:GistList(gistls, page)
138+
function! s:GistList(gistls, page) abort
119139
if a:gistls == '-all'
120140
let url = g:gist_api_url.'gists/public'
121141
elseif get(g:, 'gist_show_privates', 0) && a:gistls == 'starred'
@@ -216,7 +236,7 @@ function! gist#list(user, ...)
216236
return webapi#json#decode(res.content)
217237
endfunction
218238

219-
function! s:GistGetFileName(gistid)
239+
function! s:GistGetFileName(gistid) abort
220240
let auth = s:GistGetAuthHeader()
221241
if len(auth) == 0
222242
return ''
@@ -229,7 +249,7 @@ function! s:GistGetFileName(gistid)
229249
return ''
230250
endfunction
231251

232-
function! s:GistDetectFiletype(gistid)
252+
function! s:GistDetectFiletype(gistid) abort
233253
let auth = s:GistGetAuthHeader()
234254
if len(auth) == 0
235255
return ''
@@ -246,7 +266,7 @@ function! s:GistDetectFiletype(gistid)
246266
silent! exec "setlocal ft=".tolower(type)
247267
endfunction
248268

249-
function! s:GistWrite(fname)
269+
function! s:GistWrite(fname) abort
250270
if substitute(a:fname, '\\', '/', 'g') == expand("%:p:gs@\\@/@")
251271
if g:gist_update_on_write != 2 || v:cmdbang
252272
Gist -e
@@ -260,7 +280,7 @@ function! s:GistWrite(fname)
260280
endif
261281
endfunction
262282

263-
function! s:GistGet(gistid, clipboard)
283+
function! s:GistGet(gistid, clipboard) abort
264284
redraw | echon 'Getting gist... '
265285
let res = webapi#http#get(g:gist_api_url.'gists/'.a:gistid, '', { "Authorization": s:GistGetAuthHeader() })
266286
if res.status =~ '^2'
@@ -351,7 +371,7 @@ function! s:GistGet(gistid, clipboard)
351371
endif
352372
endfunction
353373

354-
function! s:GistListAction(shift)
374+
function! s:GistListAction(shift) abort
355375
let line = getline('.')
356376
let mx = '^gist:\s*\zs\(\w\+\)\ze.*'
357377
if line =~# mx
@@ -369,7 +389,7 @@ function! s:GistListAction(shift)
369389
endif
370390
endfunction
371391

372-
function! s:GistUpdate(content, gistid, gistnm, desc)
392+
function! s:GistUpdate(content, gistid, gistnm, desc) abort
373393
let gist = { "id": a:gistid, "files" : {}, "description": "","public": function('webapi#json#true') }
374394
if exists('b:gist')
375395
if has_key(b:gist, 'private') && b:gist.private | let gist["public"] = function('webapi#json#false') | endif
@@ -421,7 +441,7 @@ function! s:GistUpdate(content, gistid, gistnm, desc)
421441
return loc
422442
endfunction
423443

424-
function! s:GistDelete(gistid)
444+
function! s:GistDelete(gistid) abort
425445
let auth = s:GistGetAuthHeader()
426446
if len(auth) == 0
427447
redraw
@@ -483,7 +503,7 @@ endfunction
483503
"
484504
" GistID: 123123
485505
"
486-
function! s:GistPost(content, private, desc, anonymous)
506+
function! s:GistPost(content, private, desc, anonymous) abort
487507
let gist = { "files" : {}, "description": "","public": function('webapi#json#true') }
488508
if a:desc != ' ' | let gist["description"] = a:desc | endif
489509
if a:private | let gist["public"] = function('webapi#json#false') | endif
@@ -523,7 +543,7 @@ function! s:GistPost(content, private, desc, anonymous)
523543
return loc
524544
endfunction
525545

526-
function! s:GistPostBuffers(private, desc, anonymous)
546+
function! s:GistPostBuffers(private, desc, anonymous) abort
527547
let bufnrs = range(1, bufnr("$"))
528548
let bn = bufnr('%')
529549
let query = []
@@ -579,7 +599,7 @@ function! s:GistPostBuffers(private, desc, anonymous)
579599
return loc
580600
endfunction
581601

582-
function! gist#Gist(count, line1, line2, ...)
602+
function! gist#Gist(count, line1, line2, ...) abort
583603
redraw
584604
if strlen(g:github_user) == 0
585605
echohl ErrorMsg | echomsg "You don't have github account. read ':help gist-vim-setup'." | echohl None
@@ -780,7 +800,7 @@ function! gist#Gist(count, line1, line2, ...)
780800
return 1
781801
endfunction
782802

783-
function! s:GistGetAuthHeader()
803+
function! s:GistGetAuthHeader() abort
784804
if get(g:, 'gist_use_password_in_gitconfig', 0) != 0
785805
let password = substitute(system('git config --get github.password'), "\n", '', '')
786806
if password =~ '^!' | let password = system(password[1:]) | endif

0 commit comments

Comments
 (0)